static void provide(char *conf_name, char *mvm_id_str) { struct CONF *conf; unsigned long sz; int fd, mvm_id; void *mem; char x; conf = config_parse(conf_name); sz = config_get_int(conf, "size"); sz *= 1024 * 1024; assert(sz); mvm_id = atoi(mvm_id_str); assert(mvm_id); mem = valloc(sz); assert(mem); fd = init_mvm(sz, mem, conf, mvm_id); printf("Providing, press [enter] to finish.\n"); fscanf(stdin, "%c", &x); heca_close(fd); config_clean(conf); free(mem); }
static void handler(int unused) { unlink(path); if(pidfile)unlink(pidfile); config_clean(); exit(1); }
static void compute(int svm_id, char *conf_name) { struct CONF *conf = NULL; int fd, i, num; void *mem, *svm_mem; unsigned long sz, svm_sz; char x; assert(conf_name); conf = config_parse(conf_name); assert(conf); num = config_count_ints(conf); assert(num); sz = config_get_int(conf, "size"); assert(sz); sz *= 1024 * 1024; /* allocate mem and init */ mem = valloc(sz); assert(mem); svm_sz = sz/num; svm_mem = mem + (svm_id-1)*(svm_sz); for (i = 0; i < svm_sz/sizeof(int); i++) *((int *) (svm_mem + i*sizeof(int))) = svm_id; /* initialize */ if (svm_id == 1) { struct hecaioc_mr mr_array[num]; for (i = 0; i < num; i++) { mr_array[i].mr_id = i+1; mr_array[i].dsm_id = 1; mr_array[i].svm_ids[0] = i+1; mr_array[i].svm_ids[1] = 0; mr_array[i].sz = svm_sz; mr_array[i].addr = mem + svm_sz*i; mr_array[i].flags = UD_AUTO_UNMAP | UD_SHARED; } fd = init_cvm(0, conf, mr_array, num, 0); } else { fd = init_mvm(sz, mem, conf, svm_id); } /* payload */ imdb(mem, sz, num); printf("Benchmark finished.\n"); fscanf(stdin, "%c", &x); /* cleanup */ heca_close(fd); config_clean(conf); free(mem); }
static void compute(char *conf_name) { int fd = -1, i; struct CONF *conf; conf = config_parse(conf_name); assert(conf); for_each_mr (i) { mr_array[i].addr = valloc(PAGE_SIZE*NUM_PAGES); mr_array[i].flags |= UD_SHARED; } notify("[0] initialize cvm:\n"); fd = init_cvm(0, conf, mr_array, mr_count, 1); if (fd < 0) { fprintf(stderr, "can't open /dev/heca\n"); goto out; } notify("[1] pull all pages: (read mode, should show '2')"); print_pages(NUM_PAGES); notify("[2] push back pages: (should just be discarded)"); push_pages(fd, NUM_PUSHBACK); notify("[4] re-pull pages: (read mode, should show 'e')"); print_pages(NUM_PUSHBACK); notify("[5] dirty and print pages: (acquiring write, writing '1', printing)"); dirty_pages(NUM_PUSHBACK, '1'); print_pages(NUM_PUSHBACK); notify("[8] print pages: (getting read from mvm, should show '2')"); print_pages(NUM_PUSHBACK); notify("[9] dirty and print pages: (acquiring write, writing '1', printing)"); dirty_pages(NUM_PUSHBACK, '1'); print_pages(NUM_PUSHBACK); notify("[11] dirty and print pages: (acquiring write, writing '1', printing)"); dirty_pages(NUM_PUSHBACK, '1'); print_pages(NUM_PUSHBACK); notify("[.] disconnect:\n"); heca_close(fd); out: config_clean(conf); for_each_mr (i) { free(mr_array[i].addr); mr_array[i].addr = 0; } }
static void compute(unsigned long sz, char *conf_name) { struct CONF *conf = NULL; int fd; void *mem; char x; if (conf_name) { conf = config_parse(conf_name); sz = config_get_int(conf, "size"); } /* allocate mem and init */ assert(sz); sz *= 1024 * 1024; mem = valloc(sz); assert(mem); if (conf) { struct hecaioc_mr mr_array = {.mr_id=1,.dsm_id=1,.sz=sz,.addr=mem,.flags=UD_AUTO_UNMAP|UD_SHARED}; fd = init_cvm(0, conf, &mr_array, 1, 1); } /* payload: configurable in the future */ payload = quicksort; payload(mem, sz); printf("Benchmark finished.\n"); fscanf(stdin, "%c", &x); /* cleanup */ if (conf) { heca_close(fd); config_clean(conf); } free(mem); } static void print_usage(void) { printf("usage:\n" "{compute:} ./poc [config file name]\n" "{provide:} ./poc [config file name] [id]\n" "{compute locally:} ./poc [memory size]\n"); }
static void compute(char *conf_name) { int fd = -1, i, lockfd = -1, rc; struct CONF *conf = NULL; pid_t child; const char *lockfn = "/tmp/tst.lock"; fprintf(stderr, "Parent (%d): started\n", getpid()); for_each_mr (i) { mr_array[i].addr = valloc(PAGE_SIZE*NUM_PAGES); #if 0 mr_array[i].flags |= UD_COPY_ON_ACCESS; #endif } if ((child = fork()) == -1) { perror("fork error"); goto failure; } else if (!child) { if ((lockfd = open(lockfn, O_RDWR|O_CREAT|O_APPEND, 0666)) < 0) { perror("open"); goto failure; } fprintf(stderr, "Child (%d): started\n", getpid()); sleep(2); if (flock(lockfd, LOCK_EX) < 0) { perror("flock"); goto failure; } notify("[1] pull all pages: "); print_pages(NUM_PAGES); if (flock(lockfd, LOCK_UN) < 0) { perror("flock"); goto failure; } sleep(1); if (flock(lockfd, LOCK_EX) < 0) { perror("flock"); goto failure; } notify("[4] re-pull pages:"); print_pages(NUM_PUSHBACK); notify("[5] dirty and print pages (1):"); dirty_pages(NUM_PUSHBACK, '1'); print_pages(NUM_PUSHBACK); notify("[7] dirty and print pages (3):"); dirty_pages(NUM_PUSHBACK, '3'); print_pages(NUM_PUSHBACK); if (flock(lockfd, LOCK_UN) < 0) { perror("flock"); goto failure; } sleep(1); if (flock(lockfd, LOCK_EX) < 0) { perror("flock"); goto failure; } notify("[.] disconnect:\n"); fprintf(stderr, "Child (%d): ended\n", getpid()); if (flock(lockfd, LOCK_UN) < 0) { perror("flock"); goto failure; } goto done; } sleep(1); if ((lockfd = open(lockfn, O_RDWR|O_CREAT|O_APPEND, 0666)) < 0) { perror("open"); goto failure; } if (flock(lockfd, LOCK_EX) < 0) { perror("flock"); goto failure; } fprintf(stderr, "[0] initialize:\n"); conf = config_parse(conf_name); assert(conf); fd = init_cvm(child, conf, mr_array, mr_count, 1); if (fd < 0) { fprintf(stderr, "can't open /dev/heca\n"); goto failure; } fprintf(stderr, "Parent: completed HECA setup...\n"); if (flock(lockfd, LOCK_UN) < 0) { perror("flock"); goto failure; } sleep(1); if (flock(lockfd, LOCK_EX) < 0) { perror("flock"); goto failure; } notify("[2] push back pages:"); push_pages(child, fd, NUM_PUSHBACK); if (flock(lockfd, LOCK_UN) < 0) { perror("flock"); goto failure; } /* parent */ while (1) { int status; pid_t end; end = waitpid(child, &status, WNOHANG|WUNTRACED); if (end == -1) { perror("waitpid error"); goto failure; } else if (!end) { /* child still running */ sleep(1); } else if (end == child) { if (WIFEXITED(status)) printf("Child ended normally\n"); else if (WIFSIGNALED(status)) printf("Child ended because of an uncaught signal\n"); else if (WIFSTOPPED(status)) printf("Child process has stopped\n"); break; } } fprintf(stderr, "Parent (%d): is back\n", getpid()); notify("[X] parent will now close /dev/heca"); heca_close(fd); fd = -1; fprintf(stderr, "Parent (%d): ended\n", getpid()); rc = 0; goto done; /* child/parent cleanup */ failure: rc = 1; done: if (conf) config_clean(conf); for_each_mr (i) { free(mr_array[i].addr); mr_array[i].addr = 0; } if (lockfd != -1) close(lockfd); exit(rc); }
PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh,int flags,int argc, const char **argv) { int i; int r; int try_first_pass=0; int use_first_pass=0; int alwaysok=0; int mode=0; int digits=6; int window=0; int valid=1800; time_t t; const char *user=NULL; const char *pass=NULL; const char *config=config_default; const char *device=NULL; const char *lock=NULL; const char *replaydb=NULL; const char *cachedb=NULL; const char *cmp=NULL; const char *rcmp=NULL; char name[256]; for(i=0;i<argc;i++)if(!strcmp(argv[i],"try_first_pass")) try_first_pass=1; else if(!strcmp(argv[i],"use_first_pass"))use_first_pass=1; else if(!strcmp(argv[i],"alwaysok"))alwaysok=1; else if(!strcmp(argv[i],"retrigger"))mode=1; else if(!strncmp(argv[i],"digits=",7))digits=atoi(&argv[i][7]); else if(!strncmp(argv[i],"window=",7))window=atoi(&argv[i][7]); else if(!strncmp(argv[i],"valid=",6))valid=atoi(&argv[i][6]); else if(!strncmp(argv[i],"config=",7))config=&argv[i][7]; else if(!strncmp(argv[i],"device=",7))device=&argv[i][7]; else if(!strncmp(argv[i],"lock=",5))lock=&argv[i][5]; else if(!strncmp(argv[i],"replaydb=",9))replaydb=&argv[i][9]; else if(!strncmp(argv[i],"cachedb=",8))cachedb=&argv[i][8]; else if(!strncmp(argv[i],"cachehosts=",11))cmp=&argv[i][11]; else if(!strncmp(argv[i],"replayok=",9))rcmp=&argv[i][9]; if(config_parse((char *)config,0)||!device||!lock|| digits<6||digits>8||window<0||window>5) { r=PAM_SERVICE_ERR; goto out; } if(cachedb&&(r=cachecheck(pamh,cachedb,cmp,valid,mode))==PAM_SUCCESS) goto out; if((r=preprocess(pamh,&user,&pass,name,sizeof(name),try_first_pass, use_first_pass,digits))!=PAM_SUCCESS)goto out; t=time(NULL); if(rmtclient(device,lock,t,name,atoi(pass),digits,window,&r,netkey)) { r=PAM_AUTHINFO_UNAVAIL; goto out; } else if(r==PAM_SUCCESS&&replaydb) r=replaycheck(pamh,replaydb,rcmp,name,atoi(pass),t); if(r==PAM_SUCCESS&&cachedb)cacheadd(pamh,cachedb,cmp); out: config_clean(); if(alwaysok)return PAM_SUCCESS; return r; }