int
usdt_dof_file_load(usdt_dof_file_t *file, const char *module)
{
        dof_helper_t dh;
        dof_hdr_t *dof;
        int fd;

        dof = (dof_hdr_t *) file->dof;

        dh.dofhp_dof  = (uintptr_t)dof;
        dh.dofhp_addr = (uintptr_t)dof;
        (void) strncpy(dh.dofhp_mod, module, sizeof (dh.dofhp_mod));

        if ((fd = open(helper, O_RDWR)) < 0)
                return (-1);

        file->gen = load_dof(fd, &dh);

        if ((close(fd)) < 0)
                return (-1);

        if (file->gen < 0)
                return (-1);

        return (0);
}
Example #2
0
static VALUE load_ustack_helper(VALUE klass, VALUE path) {
  dtrace_hdl_t *dtp;
  dtrace_prog_t *helper;

  int err;
  void *dof;
  int argc = 1;
  char *argv[1] = { "ruby" };

  printf("c land: I am trying to load %s", RSTRING_PTR(path));
  puts("");

  FILE *fp = fopen(RSTRING_PTR(path), "r");
  if (fp == NULL) {
		rb_raise(rb_eFatal, "failed to open '%s', errno %d: %s", path, errno, strerror(errno));
  }

  dtp = dtrace_open(DTRACE_VERSION, DTRACE_O_NODEV, &err);
  if (dtp == NULL) {
    dtrace_close(dtp);
    rb_raise(rb_eFatal, "dtrace_open failed: %s", dtrace_errmsg(dtp, err));
  }

  (void) dtrace_setopt(dtp, "linkmode", "dynamic");
  (void) dtrace_setopt(dtp, "unodefs", NULL);

  if ((helper = dtrace_program_fcompile(dtp, fp,
          DTRACE_C_ZDEFS,
          argc, argv)) == NULL) {
    dtrace_close(dtp);
    rb_raise(rb_eFatal, "compile failed: errno %d: %s", dtrace_errno(dtp), dtrace_errmsg(dtp, dtrace_errno(dtp)));
  }

  (void) fclose(fp);

  if ((dof = dtrace_dof_create(dtp, helper, 0)) == NULL) {
    dtrace_close(dtp);
    rb_raise(rb_eFatal, "DOF create failed: %s", dtrace_errmsg(dtp, dtrace_errno(dtp)));
  }

  if (load_dof(dof) != 0) {
    dtrace_close(dtp);
    rb_raise(rb_eFatal, "DOF load failed: %s", strerror(err));
  }

  dtrace_close(dtp);

  return Qnil;
}