Beispiel #1
0
static int set_local_region(struct PupHeap *heap, struct PupHeapRegion *region)
{
	ABORT_ON(!region, "set_local_region() given null region");
	get_thread_info(heap)->local_region = region;
	// TODO: error handling?
	return 0;
}
Beispiel #2
0
int pup_heap_init(struct PupHeap *heap)
{
	fprintf(stderr, "pup_heap_init() pid=%d\n", getpid());
	int res;
	res = pthread_key_create(&heap->this_thread_info, NULL /* no dtor */);
	if (res) return res;

	heap->region_list = NULL;
	heap->thread_list = 0;

	// initialisation for the main thread,
	res = pup_heap_thread_init(heap);
	if (res) {
		// ignore return value, since we're cleaning up anyway,
		pthread_key_delete(heap->this_thread_info);
		return res;
	}
	res = setup_signal_handling(heap);
	if (res) {
		pthread_key_delete(heap->this_thread_info);
		return res;
	}
	res = heap_thread_start(heap);
	if (res) {
		pup_heap_thread_destroy(heap);
		pthread_key_delete(heap->this_thread_info);
		return res;
	}
	res = pthread_barrier_init(&heap->safepoint_barrier, NULL, 2);
	// FIXME: proper error handling,
	ABORTF_ON(res, "pthread_barrier_init() failed: %s",
	               strerror(errno));
	ANNOTATE_BARRIER_INIT(&heap->safepoint_barrier, 2, false);
	struct PupGCState *gc_state = pup_gc_state_create();
	// FIXME: proper error handling,
	ABORT_ON(!gc_state, "pup_gc_state_create() failed");
	set_gc_state(heap, gc_state);
	return 0;
}
Beispiel #3
0
void free_page(void *p) {
	unsigned int addr, i, offset;
	mem_zone_t *zone;

	offset = 0;
	addr = (unsigned int)p;
	zone = (mem_zone_t*)&endkernel + sizeof(mem_zone_t);

	for (i = 0; i < zone_nr; i++, zone = zone + sizeof(mem_zone_t)) {
		if (addr >= zone->start_addr && addr < zone->end_addr)
			goto found_zone;
	}

	printf("Invalid memory operation at: 0x%x\n", addr);
	abort();

found_zone:
	offset = (addr - zone->start_addr)/PAGE_SIZE;
	zone->zone_bitmap[offset] = 0;
	zone->free_pages++;
	ABORT_ON(zone->free_pages > zone->nr_pages);
}
Beispiel #4
0
static int set_thread_info(struct PupHeap *heap, struct PupThreadInfo *info)
{
	ABORT_ON(!info, "set_thread_info() given null info");
	return pthread_setspecific(heap->this_thread_info, info);
}
Beispiel #5
0
static struct PupThreadInfo *get_thread_info(struct PupHeap *heap)
{
	void *res = pthread_getspecific(heap->this_thread_info);
	ABORT_ON(!res, "pthread_getspecific() produced null");
	return (struct PupThreadInfo *)res;
}