Exemple #1
0
int main(int argc, char** argv)
{
    HANDLE lib;
    HANDLE event;
    int i;
    ULONG_PTR hThread;
    int sum = 0;

    USE_USER32();

    event = CreateEvent(NULL, TRUE, FALSE, NULL);
    hThread = _beginthreadex(NULL, 0, run_func, event, 0, &i);

    for (i=0; i<ITERS; i++) {
        lib = LoadLibrary("win32.reload.dll.dll");
        if (lib == NULL) {
            print("error loading library\n");
            break;
        } else {
            /* don't ask to compute fact or fib too high */
            BOOL (WINAPI *proc)(DWORD);
            proc = (BOOL (WINAPI *)(DWORD))
                GetProcAddress(lib, (LPCSTR)"import_me");
            sum += (*proc)(i % MAX_FACT_FIB);
            FreeLibrary(lib);
        }
    }

    SetEvent(event);
    WaitForSingleObject((HANDLE)hThread, INFINITE);

    print("sum=%d\n", sum);
    check_mem_usage();
    return 0;
}
Exemple #2
0
int
main(int argc, char **argv)
{
    HANDLE lib;
    HANDLE event;
    ULONG_PTR hThread;
    int reloaded = 0;

    USE_USER32();

#ifdef UNIX
    /* though win32/ */
    intercept_signal(SIGSEGV, signal_handler);
#else
    /* note that can't normally if we have a debugger attached this
     * will not get this executed */
    SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)our_top_handler);
#endif

    event = CreateEvent(NULL, TRUE, FALSE, NULL);
    hThread = _beginthreadex(NULL, 0, run_func, event, 0, NULL);

    /* need to run as long as necessary to hit the required faults */
    while (transitions < NUM_TRANSITIONS) {
        lib = LoadLibrary("win32.reload-race.dll.dll");
        if (lib == NULL) {
            print("error loading library\n");
            break;
        } else {
            reloaded++;
#if VERBOSE
            print("reloaded %d times %d\n", reloaded);
#endif
            import1 = (funptr)GetProcAddress(lib, (LPCSTR) "import_me1");
            import2 = (funptr)GetProcAddress(lib, (LPCSTR) "import_me2");
            /* may want to explicitly sleep here but that may be slower */
            if (reloaded % 2 == 0)
                YIELD();
            FreeLibrary(lib);
            if (reloaded % 3 == 0)
                YIELD();
        }
    }

    SetEvent(event);
    WaitForSingleObject((HANDLE)hThread, INFINITE);
    print("main loop done\n");
    check_mem_usage();
#if VERBOSE
    print("reloaded %d times %d\n", reloaded);
#endif

    return 0;
}
Exemple #3
0
int main(int argc, char *argv[])
{
 
  int optn;
  /* use of getopt to determine whether to create random numbers
     for the disks or use the number specified and read disk values
     from a predeteremined file */
  
  /*NOTE: options not implemented, functions exists just need to modify
    this main file if they are desired */
  while((optn = getopt(argc,argv,"hfr")) != -1){
    switch(optn){
    case 'r':
      /* given an r option, set flag to true */
      rand_flag = true;
      break;
    case 'f':
      /* given an f option, set file flag to true */
      file_flag = true;
      break;
    case 'h':
    case '?':
    default:
      /* given an h, unknown, or default case, produce usage message */
      usage();
      return 1;
    }
  }
  
  /* initialize curr_mem */
  curr_mem = 0;

  /**** set size_of_array from input, or else
	produce usage message and exit ****/
  if(argv[1] != NULL){
    size_of_array = atoi(argv[1]);
  }
  else{
    usage();
    return 1;
  }
  
  /* disk array used to represent disk board layout */
  disk disks[size_of_array];
  
  /* chceck memory usage */
  curr_mem += sizeof(disks);  
  check_mem_usage();

  /* initialize disk array and set up the board layout */
  memset(disks,0,(size_of_array * sizeof(disk)));
  disk_setup(size_of_array, disks);


  /* print large disk and small disk layout, as well as the initial state */
  printf(" --- Large Disks --- \n");
  int x;
  for(x = 0; x < size_of_array; x++){
    printf("%d ",disks[x].lrg_val);
  }
  printf("\n\n");

  printf(" --- Small Disks --- \n");
  for(int x = 0; x < size_of_array; x++){
    printf("%d ",disks[x].sml_val);
  }
  printf("\n \n \n");

  printf("\n\n --- Initial State --- \n");
  for(x= 0; x < size_of_array; x++){
    printf("%d ",disks[x].sml_val);
  }
  printf("\n\n");

  /* call function to emunlate simple memory-bounded A* algorithm 
     on the disk board */
  mem_bound_A(disks);
  
  /* clear memory in fringe before exit */
  clear_fringe();
  /* clear memory in clsoed list before exit */
  clear_closed();
  return 0;
}