void init_kheap(){ end = (unsigned int) &end; placement_address = end; kheap = (heap_header_t*) fmalloc(KHEAP_SIZE); init_heap(kheap, KHEAP_SIZE); //Make user heap, then map to its uheap = (heap_header_t*) kmalloc_a(UHEAP_SIZE); init_heap(uheap, UHEAP_SIZE); vpage_map_user(root_vpage_dir, (uint) &uheap, (uint) &uheap); }
void exhaustion_test2 () { container ptrs; init_heap (); std::cout << "Growing exhaustion tests" << std::endl; // Delete in allocation order ptrs = alloc_series ( 32, 1.5 ); std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... } byte chunks" << std::endl; print_free_list (); for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter ) fallback_free ( *iter ); print_free_list (); std::cout << "----" << std::endl; // Delete in reverse order print_free_list (); ptrs = alloc_series ( 32, 1.5 ); std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... } byte chunks" << std::endl; for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter ) fallback_free ( *iter ); print_free_list (); std::cout << "----" << std::endl; // Alternate deletions ptrs = alloc_series ( 32, 1.5 ); std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... } byte chunks" << std::endl; while ( ptrs.size () > 0 ) fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 )); print_free_list (); }
void exhaustion_test3 () { const size_t allocs [] = { 124, 60, 252, 60, 4 }; container ptrs; init_heap (); std::cout << "Complete exhaustion tests" << std::endl; // Delete in allocation order ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] )); std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl; print_free_list (); for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter ) fallback_free ( *iter ); print_free_list (); std::cout << "----" << std::endl; // Delete in reverse order print_free_list (); ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] )); std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl; for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter ) fallback_free ( *iter ); print_free_list (); std::cout << "----" << std::endl; // Alternate deletions ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] )); std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl; while ( ptrs.size () > 0 ) fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 )); print_free_list (); }
void __F_NAME(__NTMain,__wNTMain)( void ) /***************************************/ { init_heap(); __process_fini = &__FiniRtns; __InitRtns( 255 ); __CommonInit(); __initPOSIXHandles(); __appcwdlen = strrchr(_LpPgmName, '/') - _LpPgmName + 1; __appcwdlen = __appcwdlen > 512 ? 512 : __appcwdlen; __appcwd= (char*)malloc(__appcwdlen); strncpy(__appcwd, _LpPgmName, __appcwdlen); __appcwd[__appcwdlen] = 0; ___Argv[0] = _LpPgmName; if( *_LpCmdLine != 0) { ___Argc = 2; ___Argv[1] = _LpCmdLine; } else ___Argc = 1; #ifdef __WIDECHAR__ exit( wmain( ___wArgc, ___wArgv ) ); #else exit( main( ___Argc, ___Argv ) ); #endif }
static void simple_heap_test() { printf("Simple Heap\n"); heap hp; heap_node mem[64]; init_heap(&hp, mem, 64); char a = 'a', b = 'b', c = 'c', d = 'd'; heap_insert(&hp, 1, &b); heap_insert(&hp, 100, &d); heap_insert(&hp, 0, &a); heap_insert(&hp, 5, &c); char ret = *(char*) heap_min_value(&hp); assert_equals(ret, 'a', "Simple Heap Min 1"); ret = *(char*) heap_delete_min(&hp); assert_equals(ret, 'a', "Simple Heap Delete 1"); ret = *(char*) heap_min_value(&hp); assert_equals(ret, 'b', "Simple Heap Min 2"); ret = *(char*) heap_delete_min(&hp); assert_equals(ret, 'b', "Simple Heap Delete 2"); ret = *(char*) heap_delete_min(&hp); assert_equals(ret, 'c', "Simple Heap Delete 3"); ret = *(char*) heap_delete_min(&hp); assert_equals(ret, 'd', "Simple Heap Delete 4"); }
int Merge (int arrays[][4], int k, int n, int result[]) { int i=0, j=0, r=0; HeapNode *node = NULL, *minnode = NULL; Heap *h = NULL; init_heap (&h, k); for (i=0; i<k; i++) { node = newnode(); node->data = arrays[i][0]; node->array = i; node->index = 1; HeapAdd (h, node, i); } MinHeap (h); r = 0; for (i=0; i<n*k; i++) { minnode = getMin (h); result[r++] = minnode->data; if (minnode->index < n) { minnode->data = arrays[minnode->array][minnode->index]; minnode->index++; } else { minnode->data = MAX; } MinHeapify (h, 0); } return 0; }
/* \brief Handles archetecture-specific initialization for i586. * * This function initializes various tables, paging, and the initial heap, * various timers, then passes the locations of modules and elf info (if any) * to \ref kmain. * * @param mboot The multiboot header passed by a compliant bootloader. * @param blarg At the moment, the initial stack placement. This parameter * is unused and will be removed soon. * @param magic The multiboot header checksum. */ void arch_init( multiboot_header_t *mboot, int blarg, int magic ){ void *modules = 0; void *elfinfo = 0; init_serial( ); // Take care of multiboot stuff... if ( magic != 0x2badb002 ) panic( "Need multiboot-compliant bootloader to boot Helix kernel.\n" ); if ( mboot->flags & MULTIBOOT_FLAG_ELF ) elfinfo = &mboot->elf_headers; if ( mboot->flags & MULTIBOOT_FLAG_MODS && mboot->mods_count ){ modules = *(int **)mboot->mods_addr; early_placement = *(int *)(mboot->mods_addr + 4); } // Set up memory utils init_tables( ); init_paging( mboot->mem_lower + mboot->mem_upper ); kheap = kmalloc_early( sizeof( mheap_t ), 0 ); init_heap( kheap, kernel_dir, 0xd0000000, PAGE_SIZE * 32 ); init_timer( ); kmain( 0, modules, elfinfo ); while( 1 ) asm volatile( "hlt" ); }
void * _mesa_exec_malloc(GLuint size) { struct mem_block *block = NULL; void *addr = NULL; _glthread_LOCK_MUTEX(exec_mutex); if (!init_heap()) goto bail; if (exec_heap) { size = (size + 31) & ~31; block = mmAllocMem( exec_heap, size, 32, 0 ); } if (block) addr = exec_mem + block->ofs; else printf("_mesa_exec_malloc failed\n"); bail: _glthread_UNLOCK_MUTEX(exec_mutex); return addr; }
int radeon_mem_init_heap( DRM_IOCTL_ARGS ) { DRM_DEVICE; drm_radeon_private_t *dev_priv = dev->dev_private; drm_radeon_mem_init_heap_t initheap; struct mem_block **heap; if ( !dev_priv ) { DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ ); return DRM_ERR(EINVAL); } DRM_COPY_FROM_USER_IOCTL( initheap, (drm_radeon_mem_init_heap_t *)data, sizeof(initheap) ); heap = get_heap( dev_priv, initheap.region ); if (!heap) return DRM_ERR(EFAULT); if (*heap) { DRM_ERROR("heap already initialized?"); return DRM_ERR(EFAULT); } return init_heap( heap, initheap.start, initheap.size ); }
int main() { struct match *info1, *info2, *info3; init_heap(); info1 = get_match(20151018, "Baseball", "Cubs", "Mets", 1, 4); print_info(info1); dump_heap(); del_match(info1); info1 = get_match(20151018, "Football", "Ravens", "49ers", 20, 25); info2 = get_match(20151019, "Baseball", "Royals", "Blue Jays", 8, 1); info3 = get_match(20151019, "Football", "Giants", "Eagles", 7, 27); dump_heap(); del_match(info2); dump_heap(); return 0; }
void dij() { int i, j, t, k; init_heap(); heap[++heap[0]] = 1; d[1] = 0; pos[1] = heap[0]; for(i = 2;i <= n; i++) { d[i] = oo; heap[++heap[0]] = i; pos[i] = heap[0]; } for(k = 1;k <= n; k++) { i = pop(); t = first[i]; while(t != -1) { j = e[t].v; if(d[j] > d[i] + e[t].w) { d[j] = d[i] + e[t].w; heap_up(pos[j]); } t = e[t].next; } } printf("%d\n", d[n]); }
int kernelStart(struct multiboot_info *mboot_ptr){ kprintf("\n\n\n\n\n\n HW init ...\n"); init_descriptor_tables(); kprintf("\t\t IDT/GDT initialised...\n"); init_sysClock(100); kprintf("\t\t CMOS timer initialised to 100hz...\n"); u32int memsize = (mboot_ptr->mem_lower + mboot_ptr->mem_upper) * 1024; init_heap(end_address + 0x1000, memsize - end_address - 0x1000); //kprintf("\t\t end_address: %d \n", end_address); kprintf("\t\t Heap initialised...\n"); init_keyboard(); kprintf("\t\t PS/2 keyboard initialised...\n"); init_system_timer(); kprintf("\t\t timer initialised...\n"); init_application(); kprintf("\t\t application initialised...\n"); enableInterrupt(); while(1){} return 0; }
void init() { t0.data.number=0; init_heap(); // reverse_variable_name_lookup[0] = "Anonymous"; // reverse_variable_name_lookup[1] = "arg1"; // reverse_variable_name_lookup[2] = "arg2"; // reverse_variable_name_lookup[3] = "arg3"; // reverse_variable_name_lookup[4] = "arg4"; // reverse_variable_name_lookup[5] = "arg5"; // reverse_variable_name_lookup[6] = "arg6"; // reverse_variable_name_lookup[7] = "arg7"; // reverse_variable_name_lookup[8] = "arg8"; // reverse_variable_name_lookup[9] = "arg9"; // reverse_variable_name_lookup[10] = "arg10"; //3641448411 // std::cout << "hash : " << get_string_hash("\\") << std::endl; // get_string_hash("1"); // get_string_hash("2"); // get_string_hash("3"); // get_string_hash("4"); // get_string_hash("5"); // get_string_hash("6"); // get_string_hash("7"); // get_string_hash("8"); // get_string_hash("9"); // get_string_hash("10"); }
void *sram_malloc(size_t sz) { if (!_info.initialized) { init_heap(); } return _info.algo->malloc(sz); }
int main(int argc, const char **argv) { float *inputs; int i, error; memory_t memory; cache_t cache; membase_t *p_mem; float_heap heap; /* Set up the simulated memory. */ p_mem = make_cached_memory(argc, argv, NUM_ELEMS * sizeof(int)); /* Generate random floats to sort. */ printf("Generating %d random floats to sort.\n", NUM_ELEMS); inputs = malloc(NUM_ELEMS * sizeof(float)); srand48(SEED); for (i = 0; i < NUM_ELEMS; i++) inputs[i] = (float) drand48(); /* Use the heap to sort the sequence of floats. */ printf("Sorting numbers using the heap.\n"); init_heap(&heap, p_mem, NUM_ELEMS); for (i = 0; i < NUM_ELEMS; i++) add_value(&heap, inputs[i]); /* Sort the inputs so that we can check the heap's results. */ printf("Checking the results against the sorted inputs.\n"); qsort(inputs, NUM_ELEMS, sizeof(float), compare_float_ptrs); error = 0; for (i = 0; i < NUM_ELEMS; i++) { float val = get_first_value(&heap); if (val != inputs[i]) { printf("ERROR: heap and sorted array don't match at " "index %d! heap = %f, val = %f\n", i, val, inputs[i]); error = 1; } } if (error) { printf("Some values didn't match, aborting.\n"); abort(); } /* Print out the results of the heap sort. */ printf("\nMemory-Access Statistics:\n\n"); p_mem->print_stats(p_mem); printf("\n"); return 0; }
void sram_free(void *ptr) { if (!_info.initialized) { init_heap(); } _info.algo->free(ptr); }
/* Startup code for running on NT. When we are running as the dumped version, we need to bootstrap our heap and .bss section into our address space before we can actually hand off control to the startup code supplied by NT (primarily because that code relies upon malloc ()). */ void _start (void) { extern void mainCRTStartup (void); #if 1 /* Give us a way to debug problems with crashes on startup when running under the MSVC profiler. */ if (GetEnvironmentVariable ("EMACS_DEBUG", NULL, 0) > 0) DebugBreak (); #endif /* Cache system info, e.g., the NT page size. */ cache_system_info (); /* Grab our malloc arena space now, before CRT starts up. */ init_heap (); /* This prevents ctrl-c's in shells running while we're suspended from having us exit. */ SetConsoleCtrlHandler ((PHANDLER_ROUTINE) ctrl_c_handler, TRUE); /* Prevent Emacs from being locked up (eg. in batch mode) when accessing devices that aren't mounted (eg. removable media drives). */ SetErrorMode (SEM_FAILCRITICALERRORS); mainCRTStartup (); }
static int _mbedtls_init(struct device *device) { ARG_UNUSED(device); init_heap(); return 0; }
bool init_javascript_envirment(void) { init_native_function(); #ifdef HEAP_ALLOC return init_heap(); #else return true; #endif }
void *malloc(size_t size) { if (0 == size) { return NULL; } size += sizeof(block_meta_t); // size requested + size of block_meta_t is total size required block_meta_t *ret = NULL; init_heap(); // check for a block on the free_list of sufficient size ret = (block_meta_t *)list_find_node_with_data(&free_list, &is_enough_room, (void *)size); // found room on free_list if (NULL != ret) { list_remove_node(&free_list, ret); // no room on free_list } else { // is there room on the last partially-used page? if (size <= remaining) { ret = last; remaining -= size; } else { // no room anywhere, get new page(s) // Allocate creates new page(s), so the memory from a prevoius page where // last and remaining refer should be saved to the free_list. // // Only save if that space can fit a block_meta_t + some bytes // else let it become dangling/unusable memory. if (remaining > sizeof(block_meta_t)) { set_block_size(last, remaining); list_insert_node_at_end(&free_list, last); last = NULL; remaining = 0; } if (0 != allocate(size, 0, (void **)&ret)) { return NULL; } remaining = PAGE_SZ - (size % PAGE_SZ); } set_block_size(ret, size); last = (block_meta_t *)((unsigned char *)ret + size); } // add block to allocated_list list_insert_node_at_end(&allocated_list, ret); // need casting to make the math work correctly. return (void *)((unsigned char*)ret + sizeof(block_meta_t)); }
void _main(int seed){ printf("Seed value: %x", seed); srand_mwc(seed); /*Initialize the heap*/ init_heap(); //memcpy(contract,data,nbytes); }
void initialize_data_structures(int source) { init_edges(); /* We assume 3 is the source */ init_heap(source, heap, len_heap); /* Also initialize final array */ init_weight_array(source, weights, len_heap); }
int __low_level_init(void) #endif { init_exceptions(); init_hmatrix(); init_heap(); // EWAVR32: Request initialization of data segments. // GCC: Don't-care value. return 1; }
int kmain(multiboot_t *mboot_ptr) { monitor_clear(); printk("8888888888 d8b 888 .d88888b. .d8888b.\n"); printk("888 Y8P 888 d88P\" \"Y88b d88P Y88b\n"); printk("888 888 888 888 Y88b.\n"); printk("8888888 88888b.d88b. 888 888 888 888 \"Y888b.\n"); printk("888 888 \"888 \"88b 888 888 888 888 \"Y88b.\n"); printk("888 888 888 888 888 888 888 888 \"888\n"); printk("888 888 888 888 888 888 Y88b. .d88P Y88b d88P\n"); printk("8888888888 888 888 888 888 888 \"Y88888P\" \"Y8888P\"\n"); init_gdt (); init_idt (); init_keyboard(); setup_x87_fpu (); init_timer (20); init_pmm (mboot_ptr->mem_upper); init_vmm (); init_heap (); // Find all the usable areas of memory and inform the physical memory manager about them. uint32_t i = mboot_ptr->mmap_addr; while (i < mboot_ptr->mmap_addr + mboot_ptr->mmap_length) { mmap_entry_t *me = (mmap_entry_t*) i; // Does this entry specify usable RAM? if (me->type == 1) { uint32_t j; // For every page in this entry, add to the free page stack. for (j = me->base_addr_low; j < me->base_addr_low+me->length_low; j += 0x1000) { pmm_free_page (j); } } // The multiboot specification is strange in this respect - the size member does not include "size" itself in its calculations, // so we must add sizeof (uint32_t). i += me->size + sizeof (uint32_t); } kernel_elf = elf_from_multiboot (mboot_ptr); asm volatile ("sti"); panic ("Testing panic mechanism"); for (;;); return 0xdeadbeef; }
int main(int argc, char* argv[]) { int c = 0, amount = 100, show_date = 0, oldest = 0; char* dirname = "."; while((c = getopt(argc, argv, "c:doC:")) != -1) { switch(c) { case 'c': amount = atoi(optarg); break; case 'd': show_date = 1; break; case 'o': oldest = 1; break; case 'C': dirname = optarg; break; case ':': switch(optopt) { case '?': printf("%s", usage); return 1; default: break; } break; default: printf("%s", usage); return 1; } } if (chdir(dirname) < 0) { perror(dirname); exit(1); } DIR* dir = opendir("."); if (!dir) { perror(dirname); exit(1); } heap* heap_storage = init_heap(oldest, amount); traverse(dir, "./", traverseHandler, heap_storage); printout(heap_storage, show_date); closedir(dir); }
bool test_heap_arr_insert () { size_t arr_len = 10; size_t heap_size = 0; int *arr = init_heap(arr_len); heap_arr_insert(arr, 7, &heap_size, &arr_len); heap_arr_insert(arr, 7, &heap_size, &arr_len); heap_arr_insert(arr, 2, &heap_size, &arr_len); int expected[] = {2, 7, 7}; bool ret = arrs_equal(arr, expected, heap_size); free(arr); if (!ret) printf("failure in test_heap_arr1"); return ret; }
int main(multiboot_t *mboot_ptr) { monitor_clear(); init_gdt (); init_idt (); init_timer (20); init_pmm (mboot_ptr->mem_upper); init_vmm (); init_heap (); // Find all the usable areas of memory and inform the physical memory manager about them. uint32_t i = mboot_ptr->mmap_addr; while (i < mboot_ptr->mmap_addr + mboot_ptr->mmap_length) { mmap_entry_t *me = (mmap_entry_t*) i; // Does this entry specify usable RAM? if (me->type == 1) { uint32_t j; // For every page in this entry, add to the free page stack. for (j = me->base_addr_low; j < me->base_addr_low+me->length_low; j += 0x1000) { pmm_free_page (j); } } // The multiboot specification is strange in this respect - the size member does not include "size" itself in its calculations, // so we must add sizeof (uint32_t). i += me->size + sizeof (uint32_t); } kernel_elf = elf_from_multiboot (mboot_ptr); asm volatile ("sti"); void *a = kmalloc (8); void *b = kmalloc (8); void *c = kmalloc (8); kfree (a); kfree (b); void *d = kmalloc (24); printk ("a: %x, b: %x, c: %x, d: %x\n", a, b, c, d); panic ("Testing panic mechanism"); for (;;); return 0xdeadbeef; }
PWDB* pw_aln_contigs(CtgDB *db) { uint32_t i, j, n; int k, mn, mm, off0, off1, aln_len; PWDB *pwdb; Ctg *c0, *c1; pwdb = (PWDB*)malloc(sizeof(PWDB)); pwdb->pwctgs = init_pwctglist(6); pwdb->hp = init_heap(aln_cmp, pwdb); pwdb->ctgv = db->ctgs; AlnParam ap = {10, 2, 2, aln_sm_nt, 16, 75}; n = db->ctgnum; for (i = 0; i < n-1; i++) { c0 = ref_ctglist(db->ctgs, i); for (j = i+1; j < n; j++) { c1 = ref_ctglist(db->ctgs, j); AlnAln *aa; mn = mm = 0; off0 = off1 = -1; aa = aln_stdaln(c0->seq, c1->seq, &ap, 0, 1); aln_len = strlen(aa->out1); for (k = 0; k < aln_len; k++) { if (aa->out1[k] == '-' || aa->out2[k] == '-') continue; if (aa->out1[k] != aa->out2[k]) mm++; mn++; } PWcontig *pwc = (PWcontig*)malloc(sizeof(PWcontig)); pwc->id0 = c0->cls_id; pwc->id1 = c1->cls_id; pwc->overlap = mn; pwc->score = aa->score; pwc->het = (float)mm/mn; push_heap(pwdb->hp, pwc); push_pwctglist(pwdb->pwctgs, pwc); //fprintf(stdout, "%d\t%d\t%d\t%d\t%d\t%d\t%.3f\n", c0->cls_id, c1->cls_id, pwc->id0, pwc->id1, mn, mm, pwc->het); //fprintf(stdout, "%s\n%s\n", c0->seq, c1->seq); //fprintf(stdout, "%d\t%d\t%d\t%d\t%d\t%d\n%s\n%s\n%s\n\n", aa->start1, aa->end1,aa->start2, aa->end2, pwc->score, pwc->overlap, aa->out1, aa->outm, aa->out2); //fprintf(stdout, "%s\n%s\n%s\n\n", aa->out1, aa->outm, aa->out2); fflush(stdout); aln_free_AlnAln(aa); } } return pwdb; }
void umain(int argc, char **argv) { Heap heap; init_heap(&heap, &heapBuffer, 4*PGSIZE); set_heap(&heap); printall(); cprintf("\n\nSTARTING TESTS\n\n"); cprintf("should be empty\n\n"); testall(); cprintf("FINISHED tests\n\n"); cprintf("\n\nSTARTING FAILURES\n\n"); proof_check_expected_failures(); cprintf("FINISHED failures\n\n"); }
// Send a proof over IPC void send_proof(envid_t to, Proof p) { // Copy the proof to UTEMP sys_page_alloc(0, UTEMP, PTE_U | PTE_W); Heap tempHeap; init_heap(&tempHeap, UTEMP, PGSIZE); Heap *oldHeap = set_heap(&tempHeap); Proof copy = proof_cp(p); size_t offset = (uintptr_t)copy - (uintptr_t)UTEMP; // Send the proof ipc_send(to, offset, UTEMP, PTE_U); sys_page_unmap(0, UTEMP); // Reset the heap set_heap(oldHeap); }