예제 #1
0
파일: intercept.c 프로젝트: CPFL/xen
int hvm_mmio_intercept(ioreq_t *p)
{
    struct vcpu *v = current;
    int i;

    for ( i = 0; i < HVM_MMIO_HANDLER_NR; i++ )
    {
        hvm_mmio_check_t check_handler =
            hvm_mmio_handlers[i]->check_handler;

        if ( check_handler(v, p->addr) )
        {
            if ( unlikely(p->count > 1) &&
                 !check_handler(v, unlikely(p->df)
                                   ? p->addr - (p->count - 1L) * p->size
                                   : p->addr + (p->count - 1L) * p->size) )
                p->count = 1;

            return hvm_mmio_access(
                v, p,
                hvm_mmio_handlers[i]->read_handler,
                hvm_mmio_handlers[i]->write_handler);
        }
    }

    return X86EMUL_UNHANDLEABLE;
}
예제 #2
0
파일: bbrun.c 프로젝트: 1and1get2/Bumblebee
/**
 * Forks and runs the given application, waits for a maximum of timeout seconds for process to finish.
 *
 * @param argv The arguments values, the first one is the application path or name
 */
void bb_run_fork_wait(char** argv, int timeout) {
  check_handler();
  // Fork and attempt to run given application
  pid_t ret = fork();
  if (ret == 0) {
    // Fork went ok, child process replace
    bb_run_exec(argv);
  } else {
    if (ret > 0) {
      // Fork went ok, parent process continues
      bb_log(LOG_DEBUG, "Process %s started, PID %i.\n", argv[0], ret);
      pidlist_add(ret);
      //sleep until process finishes or timeout reached
      int i = 0;
      while (bb_is_running(ret) && ((i < timeout) || (timeout == 0)) && dowait) {
        usleep(1000000);
        i++;
      }
      //make a single attempt to kill the process if timed out, without waiting
      if (bb_is_running(ret)) {
        bb_stop(ret);
      }
    } else {
      // Fork failed
      bb_log(LOG_ERR, "Process %s could not be started. fork() failed.\n", argv[0]);
      return;
    }
  }
  return;
}
void instruction_count::start() {
    m_count = 0;
#ifdef _WINDOWS
    check_handler();
    QTCP_proc(GetCurrentThread(), &m_count);
#endif
}
예제 #4
0
파일: main.c 프로젝트: 17twenty/go
int main(void) {
	int32_t res;

	int r1 = install_handler();
	if (r1!=0) {
		return r1;
	}

	if (!DidInitRun()) {
		fprintf(stderr, "ERROR: buildmode=c-archive init should run\n");
		return 2;
	}

	if (DidMainRun()) {
		fprintf(stderr, "ERROR: buildmode=c-archive should not run main\n");
		return 2;
	}

	int r2 = check_handler();
	if (r2!=0) {
		return r2;
	}

	res = FromPkg();
	if (res != 1024) {
		fprintf(stderr, "ERROR: FromPkg()=%d, want 1024\n", res);
		return 2;
	}

	CheckArgs();

	fprintf(stderr, "PASS\n");
	return 0;
}
double instruction_count::get_num_instructions() {
    unsigned long long current = 0;
#ifdef _WINDOWS
    check_handler();
    QTCP_proc(GetCurrentThread(), &current);
#endif
    return static_cast<double>(current - m_count);
}
예제 #6
0
int find_partition_2d(cloud_2d* data, specs_2d* specs, handler_2d* callback) {

    int return_code = code_success;

    if ( return_code = check_specs(specs) )
        goto exit;

    if ( return_code = check_handler(callback) )
        goto exit;

    double x_min, x_max, y_min, y_max;
    double* min_max[4] = {&x_min, &x_max, &y_min, &y_max};

    if ( return_code = check_data(data, min_max) )
        goto exit;

    treegrid_2d* grid;

    if ( return_code = treegrid_2d_new(&grid, NULL) ) // TODO: define necessary args
        goto exit;

    int num_cells_total = insert_all_points(grid, data);
    if ( num_cells_total < 0) {
        return_code = num_cells_total;
        goto clean_grid;
    }

    double *x_reduc = NULL, *y_reduc = NULL;

    if ( return_code = alloc_output_buffer(&x_reduc, &y_reduc, num_cells_total) )
        goto clean_array;

    add_to_output_buffer(data, grid, x_reduc, y_reduc);

    void* context = callback->use_data_context;
    return_code = callback->use_data(context, x_reduc, y_reduc, num_cells_total);

clean_array:
    if (x_reduc) free(x_reduc);
    if (y_reduc) free(y_reduc);

clean_grid:
    return_code = treegrid_2d_clean(grid);

exit:
    return return_code;

}
예제 #7
0
파일: bbrun.c 프로젝트: 1and1get2/Bumblebee
/**
 * Forks and runs the given application, using an optional LD_LIBRARY_PATH. The
 * function then returns immediately.
 * stderr and stdout of the ran application is redirected to the parameter redirect.
 * stdin is redirected to /dev/null always.
 *
 * @param argv The arguments values, the first one is the program
 * @param ldpath The library path to be used if any (may be NULL)
 * @param redirect The file descriptor to redirect stdout/stderr to. Must be valid and open.
 * @return The childs process ID
 */
pid_t bb_run_fork_ld_redirect(char **argv, char *ldpath, int redirect) {
  check_handler();
  // Fork and attempt to run given application
  pid_t ret = fork();
  if (ret == 0) {
    if (ldpath && *ldpath) {
      char *current_path = getenv("LD_LIBRARY_PATH");
      /* Fork went ok, set environment if necessary */
      if (current_path) {
        char *ldpath_new = malloc(strlen(ldpath) + 1 + strlen(current_path) + 1);
        if (ldpath_new) {
          strcpy(ldpath_new, ldpath);
          strcat(ldpath_new, ":");
          strcat(ldpath_new, current_path);
          setenv("LD_LIBRARY_PATH", ldpath_new, 1);
          free(ldpath_new);
        } else {
          bb_log(LOG_WARNING, "Could not allocate memory for LD_LIBRARY_PATH\n");
        }
      } else {
        setenv("LD_LIBRARY_PATH", ldpath, 1);
      }
    }
    //open /dev/null for stdin redirect
    int devnull = open("/dev/null", O_RDWR);
    //fail silently on error, nothing we can do about it anyway...
    if (devnull >= 0){dup2(devnull, STDIN_FILENO);}
    //redirect stdout and stderr to the given filenum.
    dup2(redirect, STDOUT_FILENO);
    dup2(redirect, STDERR_FILENO);
    close(devnull);
    //ok, all ready, now actually execute
    bb_run_exec(argv);
  } else {
    if (ret > 0) {
      // Fork went ok, parent process continues
      bb_log(LOG_DEBUG, "Process %s started, PID %i.\n", argv[0], ret);
      pidlist_add(ret);
    } else {
      // Fork failed
      bb_log(LOG_ERR, "Process %s could not be started. fork() failed.\n", argv[0]);
      return 0;
    }
  }
  return ret;
}
예제 #8
0
파일: bbrun.c 프로젝트: 1and1get2/Bumblebee
/**
 * Forks and runs the given application and waits for the process to finish
 *
 * @param argv The arguments values, the first one is the program
 * @param detached non-zero if the std in/output must be redirected to /dev/null, zero otherwise
 * @return Exit code of the program (between 0 and 255) or -1 on failure
 */
int bb_run_fork(char **argv, int detached) {
  int exitcode = -1;

  check_handler();
  /* Fork and attempt to run given application */
  pid_t pid = fork();
  if (pid == 0) {
    /* child process after fork */
    if (detached) {
      bb_run_exec_detached(argv);
    } else {
      bb_run_exec(argv);
    }
  } else if (pid > 0) {
    /* parent process after fork */
    int status = 0;

    bb_log(LOG_DEBUG, "Process %s started, PID %i.\n", argv[0], pid);
    pidlist_add(pid);

    if (waitpid(pid, &status, 0) != -1) {
      if (WIFEXITED(status)) {
        /* program exited normally, return status */
        exitcode = WEXITSTATUS(status);
      } else if (WIFSIGNALED(status)) {
        /* program was terminated by a signal */
        exitcode = 128 + WTERMSIG(status);
      }
    } else {
      bb_log(LOG_ERR, "waitpid(%i) faild with %s\n", pid, strerror(errno));
    }
    pidlist_remove(pid);
  } else {
    /* Fork failed */
    bb_log(LOG_ERR, "Process %s could not be started. fork() failed.\n", argv[0]);
  }

  /* could not determine return value */
  return exitcode;
}
예제 #9
0
파일: bbrun.c 프로젝트: Samsagax/bumblebeed
/**
 * Forks and runs the given application, using an optional LD_LIBRARY_PATH. The
 * function then returns immediately
 *
 * @param argv The arguments values, the first one is the program
 * @param ldpath The library path to be used if any (may be NULL)
 * @return The childs process ID
 */
pid_t bb_run_fork_ld(char **argv, char *ldpath) {
  check_handler();
  // Fork and attempt to run given application
  pid_t ret = fork();
  if (ret == 0) {
    if (ldpath && *ldpath) {
      char *current_path = getenv("LD_LIBRARY_PATH");
      /* Fork went ok, set environment if necessary */
      if (current_path) {
        char *ldpath_new = malloc(strlen(ldpath) + 1 + strlen(current_path) + 1);
        if (ldpath_new) {
          strcpy(ldpath_new, ldpath);
          strcat(ldpath_new, ":");
          strcat(ldpath_new, current_path);
          setenv("LD_LIBRARY_PATH", ldpath_new, 1);
          free(ldpath_new);
        } else {
          bb_log(LOG_WARNING, "Could not allocate memory for LD_LIBRARY_PATH\n");
        }
      } else {
        setenv("LD_LIBRARY_PATH", ldpath, 1);
      }
    }
    bb_run_exec(argv);
  } else {
    if (ret > 0) {
      // Fork went ok, parent process continues
      bb_log(LOG_INFO, "Process %s started, PID %i.\n", argv[0], ret);
      pidlist_add(ret);
    } else {
      // Fork failed
      bb_log(LOG_ERR, "Process %s could not be started. fork() failed.\n", argv[0]);
      return 0;
    }
  }
  return ret;
}
예제 #10
0
/**
 * @brief load all handlers found in the ::HANDLERS_DIR
 * @returns 0 on success, -1 on error.
 */
int load_handlers() {
    DIR *d;
    struct dirent *de;
    handler *h;
    char *path, *cwd;
    void *handle;
    size_t len;

    len = 50;
    cwd = malloc(len);

    while(cwd && len < PATH_MAX) {
        if(getcwd(cwd, len)) break;
        if(errno != ERANGE) {
            print( ERROR, "getcwd: %s", strerror(errno));
            free(cwd);
            return -1;
        }
        len += 50;
        cwd = realloc(cwd, len);
    }

    if(!cwd) {
        print( ERROR, "malloc(%d): %s", len, strerror(errno));
        return -1;
    }

    d = opendir(HANDLERS_DIR);

    if(!d) {
        print( ERROR, "opendir: %s", strerror(errno) );
        free(cwd);
        return -1;
    }

    while((de=readdir(d))) {
        if(!strncmp(de->d_name, ".", 2) || !strncmp(de->d_name, "..", 3)) {
            continue;
        }

        len = strlen(de->d_name);

        if(strncmp(de->d_name + (len - 3), ".so", 3))
            continue;

        if(asprintf(&path, "%s/" HANDLERS_DIR "/%s", cwd, de->d_name) == -1) {
            print( ERROR, "asprintf: %s", strerror(errno) );
            continue;
        }

        if(!(handle = dlopen(path, RTLD_NOW))) {
            print( ERROR, "dlopen: %s", dlerror() );
            free(path);
            continue;
        }

        if(!(h = (handler *)dlsym(handle, "handler_info"))) {
            print( ERROR, "\"%s\": undefined reference to 'handler_info'", path );
            goto close;
        }

        if(check_handler(h)) {
            goto close;
        }

        h->dl_handle = handle;

        list_add(&(handlers), (node *) h);

        free(path);
        continue;

close:

        if(dlclose(handle))
            print( ERROR, "dlclose(\"%s\"): %s", path, dlerror() );

        free(path);
    }

    closedir(d);

    free(cwd);

    if(!handlers.head) {
        print( ERROR, "no handlers found" );
        return -1;
    }

    return 0;
}