void debug_newptr(long size,void *ptr) { long i; if (current_level < 0) return; if (!ptr) McoErrorAlert(MCO_INVALID_PTR); if (!dbg_ptr_ptrs) return; if (!dbg_ptr_sizes) return; if (!dbg_ptr_counts) return; if (!dbg_ptr_levels) return; for (i=0; i<max_ptrs; i++) if (!dbg_ptr_ptrs[i]) { dbg_ptr_ptrs[i] = ptr; dbg_ptr_sizes[i] = size; dbg_ptr_counts[i] = num_ptrs; dbg_ptr_levels[i] = current_level; if ((num_ptrs == 3587) || (num_ptrs == 3588)) { i = 0; } num_ptrs++; break; } if (i == max_news) McoErrorAlert(MCO_MAX_MEMORY); fill_mem(size,ptr,PTR_FILL_I); }
void debug_newhand(long size,void *ptr) { long i; Handle h; if (current_level < 0) return; if (!ptr) McoErrorAlert(MCO_INVALID_PTR); if (!dbg_hand_ptrs) return; if (!dbg_hand_sizes) return; if (!dbg_hand_counts) return; if (!dbg_hand_levels) return; for (i=0; i<max_ptrs; i++) if (!dbg_hand_ptrs[i]) { dbg_hand_ptrs[i] = ptr; dbg_hand_sizes[i] = size; dbg_hand_counts[i] = num_hand; dbg_hand_levels[i] = current_level; if ((num_hand == 24) || (num_hand == 25)) { i = 0; } num_hand++; break; } if (i == max_hand) McoErrorAlert(MCO_MAX_MEMORY); h = (Handle)ptr; HLock((Handle)h); fill_mem(size,*h,HAND_FILL_I); HUnlock((Handle)h); }
void debug_new(size_t size,void *ptr) { long i; if (current_level < 0) return; if (!ptr) McoErrorAlert(MCO_INVALID_PTR); if (!dbg_new_ptrs) return; if (!dbg_new_sizes) return; if (!dbg_new_counts) return; if (!dbg_new_levels) return; for (i=0; i<max_news; i++) if (!dbg_new_ptrs[i]) { dbg_new_ptrs[i] = ptr; dbg_new_sizes[i] = size; dbg_new_counts[i] = num_new; dbg_new_levels[i] = current_level; if ((size == 340) || (num_new == 57) || (num_new == 57) || (num_new == 57)) { i = 0; } num_new++; break; } if (i == max_news) McoErrorAlert(MCO_MAX_MEMORY); fill_mem(size,ptr,NEW_FILL_I); }
int main() { BDISP = 0; BDRAW = 0; fill_mem(0x0000); fill_mem(0xffff); BDISP = 0; BDRAW = 1; hud_init(); while(1) { hud_rc_plane_single_frame(); // demo(); } return 0; }
/* * new uglymem * * alloc & init a new entry of ugly mem */ static UGLYMEM *new_uglymem(size_t memsize, STRPTR memfile, ULONG memline) { UGLYMEM *newmem = (UGLYMEM *) malloc(sizeof(UGLYMEM)); if (newmem) { newmem->lower = (STRPTR) ugly_malloc_notracking(memsize + 2 * UMEM_WALLSIZE); if (newmem->lower) { /* compute location of main mem/upper wall */ newmem->ptr = (void *) (newmem->lower + UMEM_WALLSIZE); newmem->upper = (newmem->lower + UMEM_WALLSIZE + memsize); /* link to list */ newmem->next = first; first = newmem; /* init data */ newmem->size = memsize; newmem->file = memfile; newmem->line = memline; newmem->fillchar = ugly_fillchar; /* fill new mem area with $DEADF00D */ fill_mem4(newmem->ptr, memsize, deadfood); /* fill lower/upper wall */ fill_mem(newmem->lower, UMEM_WALLSIZE, ugly_fillchar); fill_mem(newmem->upper, UMEM_WALLSIZE, ugly_fillchar); /* update fillchar */ if (ugly_fillchar == 0xff) ugly_fillchar = 0x81; else ugly_fillchar++; } else free(newmem); } return (newmem); }
int init_buffs(char *pbufs[]) { int i; for (i = 0; pbufs[i] != NULL; i++) { switch (i) { case 0: /*FALLTHROUGH*/ case 1: fill_mem(pbufs[i], 0, 1); break; case 2: fill_mem(pbufs[i], 1, 0); break; default: tst_brkm(TBROK, cleanup, "Error in init_buffs()"); } } return 0; }
void init_buffs(char *pbufs[]) { int i; for (i = 0; pbufs[i] != NULL; i++) { switch (i) { case 0: case 1: fill_mem(pbufs[i], 0, 1); break; case 2: fill_mem(pbufs[i], 1, 0); break; default: tst_brkm(TBROK, cleanup, "error detected: init_buffs"); } } }
int init_buffs(char *pbufs[]) { int i; for (i = 0; pbufs[i] != (char *)NULL; i++) { switch (i) { case 0: case 1: fill_mem(pbufs[i], 0, 1); break; case 2: fill_mem(pbufs[i], 1, 0); break; default: tst_resm(TFAIL, "Error detected: init_buffs()"); cleanup(); /*NOTREACHED*/ } } return 0; }
int worker(int num) { char *local, *remote; //int id; int k; fprintf(stderr, "\tbind process %d to cpu %ld\n", num, cpu_num - num - 1); if (bind_to_cpu(cpu_num - num - 1) < 0) { //(*total_e)++; kill(0, SIGUSR1); exit(-1); } local = (char *)create_shm(key[num], shm_size); if (local == NULL) { kill(0, SIGUSR1); exit(-1); } k = (num % 2 == 0 ? num + 1 : num - 1); remote = (char *)wait_remote_shm(key[k], shm_size); if (remote == NULL) { kill(0, SIGUSR1); exit(-1); } while (1) { sem_wait(sem[num]); fill_mem(local, data, shm_size); sem_wait(write_lock); (*total_w)++; sem_post(write_lock); sem_post(sem[num]); sem_wait(sem[k]); if (read_mem(remote, data, shm_size) < 0) { sem_post(sem[k]); (*total_e)++; kill(0, SIGUSR1); exit(-1); } sem_wait(read_lock); (*total_r)++; sem_post(read_lock); sem_post(sem[k]); } }
void debug_freeptr(void *ptr) { long i; if (current_level < 0) return; if (!ptr) McoErrorAlert(MCO_INVALID_PTR); if (!dbg_ptr_ptrs) return; for (i=0; i<max_ptrs; i++) if (dbg_ptr_ptrs[i] == ptr) { fill_mem(dbg_ptr_sizes[i],ptr,PTR_FILL_D); dbg_ptr_ptrs[i] = 0L; dbg_ptr_sizes[i] = 0; dbg_ptr_counts[i] = 0; dbg_ptr_levels[i] = 0; break; } if (i == max_ptrs) McoErrorAlert(MCO_INVALID_PTR); }
void debug_delete(void *ptr) { long i; if (current_level < 0) return; if (!ptr) McoErrorAlert(MCO_INVALID_PTR); if (!dbg_new_ptrs) return; for (i=0; i<max_news; i++) if (dbg_new_ptrs[i] == ptr) { fill_mem(dbg_new_sizes[i],ptr,NEW_FILL_D); dbg_new_ptrs[i] = 0L; dbg_new_sizes[i] = 0; dbg_new_counts[i] = 0; dbg_new_levels[i] = 0; break; } if (i == max_news) McoErrorAlert(MCO_INVALID_PTR); }
void debug_freehand(void *ptr) { long i; Handle h; if (current_level < 0) return; if (!ptr) McoErrorAlert(MCO_INVALID_PTR); if (!dbg_hand_ptrs) return; for (i=0; i<max_hand; i++) if (dbg_hand_ptrs[i] == ptr) { h = (Handle)ptr; HLock((Handle)h); fill_mem(dbg_hand_sizes[i],*h,HAND_FILL_D); HUnlock((Handle)h); dbg_hand_ptrs[i] = 0L; dbg_hand_sizes[i] = 0; dbg_hand_counts[i] = 0; dbg_hand_levels[i] = 0; break; } if (i == max_hand) McoErrorAlert(MCO_INVALID_PTR); }
page_table() { #if (EDITFLAG*TEMFLAG) register int i,j; register long n,ctrlptr; register long *longptr; register EBDTLINK *ptabptr; long currpageptr,maxntable,dummlong; int type,nvals,ebdtindex,ebdt_i; CTRLHEADER ctrlheader; VAL_INFO *val[MAXNVALS]; /* build page address offset table */ if (!change_mem(addrmem,4L*curr_nctrl)) return 1; longptr= (long*)(heap[addrmem].start); ctrlptr= heap[curr_mem].start; for (i=0; i<curr_nctrl; i++,longptr++) { *longptr = i ? longptr[-1]+j : 0L ; j= ((CTRLHEADER*)(ctrlptr))->length; ctrlptr += j; } /* build linked list of ebdt/valinfo -- */ /* -- allocate largest possible table */ fill_mem(ptabmem); ptabptr= (EBDTLINK*)(heap[ptabmem].start); maxntable= heap[ptabmem].nbytes / sizeof(*ptabptr) ; /* -- first part of table is for the ebdt itself */ n= n_of_ebdt(&dummlong); if (n>maxntable) n= maxntable= 0; /* loops skipped, returns error */ for (i=0; i<n; i++) { ptabptr[i].next= i; ptabptr[i].ctrl_i= -1; /* means ebdt */ } /* -- rest of table is for ctrl valinfo's */ longptr= (long*)(heap[addrmem].start); currpageptr= heap[curr_mem].start; for (i=0; (i<curr_nctrl)&&(n<maxntable); i++) { ctrlptr= currpageptr + longptr[i] ; type= ((CTRLHEADER*)(ctrlptr))->type; if (type>=0) /* visible */ { nvals= find_vals(type,ctrlptr+sizeof(ctrlheader),val); for (j=0; (j<nvals)&&(n<maxntable); j++) { find_e_m(i,val[j],&ebdt_i,&dummy); if (ebdt_i>=0) { ctrlptr= currpageptr + longptr[ebdt_i]; ebdtindex= ( (CTRL_EBDT*)(ctrlptr+sizeof(ctrlheader)) )->index; ptabptr[n].ctrl_i= i; ptabptr[n].val_i= j; ptabptr[n].next= ptabptr[ebdtindex].next; ptabptr[ebdtindex].next= n; n++; } } } } if (n==maxntable) { form_alert(1,BADMEM2); n=0; } change_mem(ptabmem,n*sizeof(*ptabptr)); return (n==maxntable)||(!maxntable); #endif } /* end page_table() */
int main(int argc, char *argv[]) { int ret, status; pid_t child, ctl; void *malloced; struct sigaction sa_ori, sa_child; struct test_struct mystruct = { 1, 2, 3, (void *)4 }; size_t page_size = sysconf(_SC_PAGESIZE); malloced = malloc(page_size); if (malloced == NULL) { perror("malloc() failed"); return PTS_UNRESOLVED; } fill_mem(malloced, page_size); /* Initialize an environment variable */ ret = setenv("OPTS_FORK_TC", "2-1.c", 1); if (ret != 0) { perror("setenv() failed"); return PTS_UNRESOLVED; } /* Initialize the signal handler */ sa_ori.sa_handler = handler; ret = sigemptyset(&sa_ori.sa_mask); if (ret != 0) { perror("sigemptyset() failed"); return PTS_UNRESOLVED; } ret = sigaddset(&sa_ori.sa_mask, SIGUSR2); if (ret != 0) { perror("sigaddset() failed"); return PTS_UNRESOLVED; } sa_ori.sa_flags = SA_NOCLDSTOP; ret = sigaction(SIGUSR1, &sa_ori, NULL); if (ret != 0) { perror("sigaction() failed"); return PTS_UNRESOLVED; } /* Create the child */ child = fork(); if (child == -1) { perror("fork() failed"); return PTS_UNRESOLVED; } /* child */ if (child == 0) { /* Check the struct was copied */ if ((mystruct.one != 1) || (mystruct.two != 2) || (mystruct.three != 3) || (mystruct.four != (void *)4)) { printf("On-the-stack structure not copied correctly\n"); return PTS_FAIL; } /* Check the malloc'ed memory is copied */ if (check_mem(malloced, page_size)) { printf("Allocated page not copied correctly\n"); return PTS_FAIL; } /* Free the memory -- this should suceed */ free(malloced); /* Check the env variable */ if (strncmp("2-1.c", getenv("OPTS_FORK_TC"), 6) != 0) { printf("Enviroment variable not copied correctly\n"); return PTS_FAIL; } /* Check the signal handler stuff */ ret = sigaction(SIGUSR1, NULL, &sa_child); if (ret != 0) { perror("sigaction() failed in child"); return PTS_UNRESOLVED; } if (sa_child.sa_handler != handler) { printf("Signal handler function is different\n"); return PTS_FAIL; } ret = sigismember(&sa_child.sa_mask, SIGUSR2); if (ret == 0) { printf("Signal handler mask is different\n"); return PTS_FAIL; } if (ret != 1) { printf("Unexpected return code from sigismember\n"); return PTS_UNRESOLVED; } if (((sa_child.sa_flags & SA_NOCLDSTOP) != SA_NOCLDSTOP) #ifndef WITHOUT_XOPEN || ((sa_child.sa_flags & SA_ONSTACK) != 0) || ((sa_child.sa_flags & SA_RESETHAND) != 0) || ((sa_child.sa_flags & SA_RESTART) != 0) || ((sa_child.sa_flags & SA_SIGINFO) != 0) || ((sa_child.sa_flags & SA_NOCLDWAIT) != 0) || ((sa_child.sa_flags & SA_NODEFER) != 0) #endif ) { printf("The sigaction flags are different\n"); return PTS_FAIL; } return PTS_PASS; } /* Parent joins the child */ ctl = waitpid(child, &status, 0); if (ctl != child) { printf("Waitpid returned wrong PID\n"); return PTS_UNRESOLVED; } if (!WIFEXITED(status)) { printf("Child exited abnormally\n"); return PTS_UNRESOLVED; } if (WEXITSTATUS(status) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } return WEXITSTATUS(status); }