void flx_collector_t::scan_object(void *p, int reclimit) { Word_t reachable = (parity & 1UL) ^ 1UL; again: if(debug) fprintf(stderr,"Scan object %p, reachable bit value = %d\n",p,(int)reachable); Word_t cand = (Word_t)p; Word_t head=cand; Word_t *ppshape = (Word_t*)JudyLLast(j_shape,&head,&je); if(ppshape==(Word_t*)PPJERR)judyerror("scan_object"); if(ppshape == NULL) return; // no lower object /* if(debug) { fprintf(stderr,"Found candidate object %p, &shape=%p, shape(1) %p\n",(void*)fp,(void*)w,(void*)(*w)); fprintf(stderr," .. type=%s!\n",((gc_shape_t*)(*w & ~1UL))->cname); } */ if( (*ppshape & 1UL) == reachable) return; // already handled gc_shape_t *pshape = (gc_shape_t*)(*ppshape & ~1UL); unsigned long n = get_count((void*)head) * pshape->count * pshape->amt; if(cand >= (Word_t)(void*)((unsigned char*)(void*)head+n)) return; // not interior if(debug) fprintf(stderr,"MARKING object %p, shape %p, type=%s\n",(void*)head,pshape,pshape->cname); *ppshape = (*ppshape & ~1uL) | reachable; if(pshape->flags & gc_flags_conservative) { unsigned long n_used = get_used((void*)head) * pshape->count; // end of object, rounded down to size of a void* void **end = (void**)( (unsigned char*)(void*)head + n_used * n / sizeof(void*) * sizeof(void*) ); for ( void **i = (void**)head; i != end; i = i+1) { //if(debug) // fprintf(stderr, "Check if *%p=%p is a pointer\n",i,*(void**)i); if(reclimit==0) Judy1Set(&j_tmp,(Word_t)*i,&je); else scan_object(*i,reclimit -1); } } else { unsigned long dyncount = get_used((void*)head); if(pshape->scanner) { void *r = pshape->scanner(this, pshape, (void*)head,dyncount,reclimit); if (r) { p = r; goto again; } } } }
::flx::gc::generic::pointer_data_t flx_collector_t::get_pointer_data (void *p) { ::flx::gc::generic::pointer_data_t pdat; pdat.head = NULL; pdat.max_elements = 0ul; pdat.used_elements = 0ul; pdat.shape = NULL; pdat.pointer = p; Word_t cand = (Word_t)p; Word_t head = cand; Word_t *ppshape = (Word_t*)JudyLLast(j_shape,&head, &je); if(ppshape==(Word_t*)PPJERR)judyerror("get_pointer_data"); if(ppshape == NULL) return pdat; // no lower object gc_shape_t *pshape = (gc_shape_t*)(*ppshape & ~1UL); unsigned long max_slots = get_count((void*)head); unsigned long used_slots = get_used((void*)head); unsigned long n = max_slots * pshape->count * pshape->amt; if(cand >= (Word_t)(void*)((unsigned char*)(void*)head+n)) return pdat; // not interior pdat.head = (void*)head; pdat.max_elements = max_slots; pdat.used_elements = used_slots; pdat.shape = pshape; return pdat; }
uint16_t AsebaGetBuffer(AsebaVMState *vm, uint8_t * data, uint16_t maxLength, uint16_t* source) { int flags; uint16_t ret = 0; size_t u; // Touching the FIFO, mask the interrupt ... USBMaskInterrupts(flags); u = get_used(&AsebaUsb.rx); /* Minium packet size == len + src + msg_type == 6 bytes */ if(u >= 6) { int len; fifo_peek((unsigned char *) &len, &AsebaUsb.rx, 2); if (u >= len + 6) { memcpy_out_fifo((unsigned char *) &len, &AsebaUsb.rx, 2); memcpy_out_fifo((unsigned char *) source, &AsebaUsb.rx, 2); // msg_type is not in the len but is always present len = len + 2; /* Yay ! We have a complete packet ! */ if(len > maxLength) len = maxLength; memcpy_out_fifo(data, &AsebaUsb.rx, len); ret = len; } } if(usb_uart_serial_port_open()) USBCDCKickRx(); else fifo_reset(&AsebaUsb.rx); USBUnmaskInterrupts(flags); return ret; }
// pos: next position of word to search for. // (i, j): current position. bool search(string &word, int pos, vector<int> &used, vector<vector<char> > &board, int i, int j) { if (pos == word.length()) return true; int rows = board.size(); int cols = board[0].size(); set_used(used, cols, i, j, 1); // left if (j > 0) { // not on left edge if (word[pos] == board[i][j-1] && ! get_used(used, cols, i, j-1) ) if (search(word, pos + 1, used, board, i, j-1)) return true; } // right if (j < cols - 1) { // not on right edge if (word[pos] == board[i][j+1] && ! get_used(used, cols, i, j+1) ) if (search(word, pos + 1, used, board, i, j+1)) return true; } // up if (i > 0) { // not top row. if (word[pos] == board[i-1][j] && ! get_used(used, cols, i-1, j) ) if (search(word, pos + 1, used, board, i-1, j)) return true; } // down if (i < rows - 1) { if (word[pos] == board[i+1][j] && ! get_used(used, cols, i+1, j) ) if (search(word, pos + 1, used, board, i+1, j)) return true; } set_used(used, cols, i, j, 0); return false; }
int AsebaUsbRecvBufferEmpty(void) { // We are called with interrupt disabled ! Check if rx contain something meaningfull int u; u = get_used(&AsebaUsb.rx); if(u > 6) { int len; fifo_peek((unsigned char *) &len, &AsebaUsb.rx, 2); if (u >= len + 6) return 0; } return 1; }
size_t dump_data(struct ring_buff *rb, size_t size) { size_t dist = get_used(rb); if (size > dist) size = dist; dist = get_end_dist(rb, rb->tail); if (size < dist) { rb->tail += size; } else { rb->tail = rb->buf + size - dist; } return size; }
unsigned char AsebaTxReady(unsigned char *data) { size_t size = get_used(&AsebaUsb.tx); if(size == 0) { tx_busy = 0; debug = 0; return 0; } if(size > ASEBA_USB_MTU) size = ASEBA_USB_MTU; memcpy_out_fifo(data, &AsebaUsb.tx, size); debug ++; return size; }
void flx_collector_t::incr_used(void *memory, unsigned long n) { assert(memory); assert(n>=0); //fprintf(stderr,"Incr used of %p by %ld\n",memory,n); assert(get_used(memory) + n <= get_count(memory)); Word_t *p = (Word_t*)(void*)JudyLGet(j_nused,(Word_t)memory,&je); if(p==(Word_t*)PPJERR)judyerror("incr_used"); if(p==NULL) { //fprintf(stderr,"incr_used: No recorded usage! Creating store for data\n"); p = (Word_t*)(void*)JudyLIns(&j_nused,(Word_t)memory,&je); if(p==(Word_t*)PPJERR)judyerror("incr_used: new slot"); *p = n; } else *p+=n; }
size_t get_data(struct ring_buff *rb, void *data, size_t size) { size_t dist = get_used(rb); if (size > dist) size = dist; dist = get_end_dist(rb, rb->tail); if (size < dist) { memcpy(data, rb->tail, size); rb->tail += size; } else { size_t wrap_size = size - dist; memcpy(data, rb->tail, dist); memcpy((char *)data + dist, rb->buf, wrap_size); rb->tail = rb->buf + wrap_size; } return size; }
int main(void) { unsigned long long before; struct sigevent sevt; pthread_mutex_t mutex; pthread_cond_t cond; int fd, failed = 0; pthread_t thread; sem_t sem, *psem; timer_t tm; __maybe_unused pid_t child; mlockall(MCL_CURRENT|MCL_FUTURE); fprintf(stderr, "Checking for leaks in posix skin objects\n"); before = get_used(); check_pthread(pthread_create(&thread, NULL, empty, NULL)); check_pthread(pthread_join(thread, NULL)); sleep(1); /* Leave some time for xnheap * deferred free */ check_used("thread", before, failed); before = get_used(); check_pthread(pthread_mutex_init(&mutex, NULL)); check_pthread(pthread_mutex_destroy(&mutex)); check_used("mutex", before, failed); before = get_used(); check_pthread(pthread_cond_init(&cond, NULL)); check_pthread(pthread_cond_destroy(&cond)); check_used("cond", before, failed); before = get_used(); check_unix(sem_init(&sem, 0, 0)); check_unix(sem_destroy(&sem)); check_used("sem", before, failed); before = get_used(); check_unix(-!(psem = sem_open(SEM_NAME, O_CREAT, 0644, 1))); check_unix(sem_close(psem)); check_unix(sem_unlink(SEM_NAME)); check_used("named sem", before, failed); before = get_used(); sevt.sigev_notify = SIGEV_THREAD_ID; sevt.sigev_signo = SIGALRM; sevt.sigev_notify_thread_id = syscall(__NR_gettid); check_unix(timer_create(CLOCK_MONOTONIC, &sevt, &tm)); check_unix(timer_delete(tm)); check_used("timer", before, failed); before = get_used(); check_unix(fd = mq_open(MQ_NAME, O_RDWR | O_CREAT, 0644, NULL)); check_unix(mq_close(fd)); check_unix(mq_unlink(MQ_NAME)); check_used("mq", before, failed); #ifdef HAVE_FORK before = get_used(); check_unix(child = fork()); if (!child) { subprocess_leak(); return EXIT_SUCCESS; } while (waitpid(child, NULL, 0) == -1 && errno == EINTR); sleep(1); /* Leave some time for xnheap * deferred free */ check_unix(sem_unlink(SEM_NAME)); check_unix(mq_unlink(MQ_NAME)); check_used("fork", before, failed); #endif return failed ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(void) { unsigned long long before; RT_ALARM nalrm; RT_BUFFER nbuf; RT_COND ncond; RT_EVENT nevt; RT_HEAP nheap; RT_MUTEX nmtx; RT_PIPE npipe; RT_QUEUE nq; RT_SEM nsem; RT_TASK ntsk; int failed = 0; mlockall(MCL_CURRENT|MCL_FUTURE); rt_print_auto_init(1); rt_fprintf(stderr, "Checking for leaks in native skin services\n"); before = get_used(); check_native(rt_alarm_create(&nalrm, NULL)); check_native(rt_alarm_delete(&nalrm)); check_used("alarm", before, failed); before = get_used(); check_native(rt_buffer_create(&nbuf, NULL, 16384, B_PRIO)); check_native(rt_buffer_delete(&nbuf)); check_used("buffer", before, failed); before = get_used(); check_native(rt_cond_create(&ncond, NULL)); check_native(rt_cond_delete(&ncond)); check_used("cond", before, failed); before = get_used(); check_native(rt_event_create(&nevt, NULL, 0, EV_PRIO)); check_native(rt_event_delete(&nevt)); check_used("event", before, failed); before = get_used(); check_native(rt_heap_create(&nheap, "heap", 16384, H_PRIO | H_SHARED)); check_native(rt_heap_delete(&nheap)); check_used("heap", before, failed); before = get_used(); check_native(rt_mutex_create(&nmtx, NULL)); check_native(rt_mutex_delete(&nmtx)); check_used("mutex", before, failed); before = get_used(); check_native(rt_pipe_create(&npipe, NULL, P_MINOR_AUTO, 0)); check_native(rt_pipe_delete(&npipe)); check_used("pipe", before, failed); before = get_used(); check_native(rt_queue_create(&nq, "queue", 16384, Q_UNLIMITED, Q_PRIO)); check_native(rt_queue_delete(&nq)); check_used("queue", before, failed); before = get_used(); check_native(rt_sem_create(&nsem, NULL, 0, S_PRIO)); check_native(rt_sem_delete(&nsem)); check_used("sem", before, failed); before = get_used(); check_native(rt_task_spawn(&ntsk, NULL, 0, 1, T_JOINABLE, empty, NULL)); check_native(rt_task_join(&ntsk)); sleep(1); /* Leave some time for xnheap * deferred free */ check_used("task", before, failed); return failed ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(void) { unsigned long long before; struct sigevent sevt; pthread_mutex_t mutex; pthread_cond_t cond; int fd, failed = 0; pthread_t thread; sem_t sem, *psem; timer_t tm; void *shm; mlockall(MCL_CURRENT|MCL_FUTURE); fprintf(stderr, "Checking for leaks in posix skin objects\n"); before = get_used(); check_pthread(pthread_create(&thread, NULL, empty, NULL)); check_pthread(pthread_join(thread, NULL)); sleep(1); /* Leave some time for xnheap * deferred free */ check_used("thread", before, failed); before = get_used(); check_pthread(pthread_mutex_init(&mutex, NULL)); check_pthread(pthread_mutex_destroy(&mutex)); check_used("mutex", before, failed); before = get_used(); check_pthread(pthread_cond_init(&cond, NULL)); check_pthread(pthread_cond_destroy(&cond)); check_used("cond", before, failed); before = get_used(); check_unix(sem_init(&sem, 0, 0)); check_unix(sem_destroy(&sem)); check_used("sem", before, failed); before = get_used(); check_unix(-!(psem = sem_open(SEM_NAME, O_CREAT, 0644, 1))); check_unix(sem_close(psem)); check_unix(sem_unlink(SEM_NAME)); check_used("named sem", before, failed); before = get_used(); sevt.sigev_notify = SIGEV_SIGNAL; sevt.sigev_signo = SIGALRM; check_unix(timer_create(CLOCK_MONOTONIC, &sevt, &tm)); check_unix(timer_delete(tm)); check_used("timer", before, failed); before = get_used(); check_unix(fd = shm_open(SHM_NAME, O_CREAT | O_RDWR, 0644)); check_unix(ftruncate(fd, SHM_SZ)); shm = mmap(NULL, SHM_SZ, PROT_READ, MAP_SHARED, fd, 0); check_unix(shm == MAP_FAILED ? -1 : 0); check_unix(munmap(shm, SHM_SZ)); check_unix(close(fd)); check_unix(shm_unlink(SHM_NAME)); check_used("shm", before, failed); before = get_used(); check_unix(fd = mq_open(MQ_NAME, O_RDWR | O_CREAT, 0644, NULL)); check_unix(mq_close(fd)); check_unix(mq_unlink(MQ_NAME)); check_used("mq", before, failed); return failed ? EXIT_FAILURE : EXIT_SUCCESS; }
static inline size_t get_free(struct fifo * f) { return f->size - get_used(f); }