void * kernel_malloc(size_t nbytes) { union overhead *op; int bucket; size_t amt; /* * First time malloc is called, setup page size and * align break pointer so all data will be page aligned. */ if (pagesz == 0) { pagesz = CHERIOS_PAGESIZE; init_pagebucket(); __init_heap(pagesz); } kernel_assert(pagesz != 0); /* * Convert amount of memory requested into closest block size * stored in hash buckets which satisfies request. * Account for space used per block for accounting. */ if (nbytes <= pagesz - sizeof (*op)) { amt = 32; /* size of first bucket */ bucket = 2; } else { amt = pagesz; bucket = pagebucket; } while (nbytes > (size_t)amt - sizeof(*op)) { amt <<= 1; if (amt == 0) return (NULL); bucket++; } /* * If nothing in hash bucket right now, * request more memory from the system. */ if ((op = nextf[bucket]) == NULL) { morecore(bucket); if ((op = nextf[bucket]) == NULL) return (NULL); } /* remove from linked list */ nextf[bucket] = op->ov_next; op->ov_magic = MAGIC; op->ov_index = bucket; return (cheri_setbounds(op + 1, nbytes)); }
void initialize_before(image_id imageID) { char *programPath = __gRuntimeLoader->program_args->args[0]; if (programPath) { if ((__progname = strrchr(programPath, '/')) == NULL) __progname = programPath; else __progname++; } __libc_argc = __gRuntimeLoader->program_args->arg_count; __libc_argv = __gRuntimeLoader->program_args->args; __gRuntimeLoader->call_atexit_hooks_for_range = _call_atexit_hooks_for_range; __init_exit_stack_lock(); __init_time(); __init_fork(); __init_heap(); __init_env(__gRuntimeLoader->program_args); __init_pwd_backend(); }
void initialize_before(image_id imageID) { system_info info; char *programPath = __gRuntimeLoader->program_args->args[0]; __gCommPageAddress = __gRuntimeLoader->commpage_address; __gABIVersion = __gRuntimeLoader->abi_version; if (programPath) { if ((__progname = strrchr(programPath, '/')) == NULL) __progname = programPath; else __progname++; } __libc_argc = __gRuntimeLoader->program_args->arg_count; __libc_argv = __gRuntimeLoader->program_args->args; __gRuntimeLoader->call_atexit_hooks_for_range = _call_atexit_hooks_for_range; if (__gRuntimeLoader->program_args->umask != (mode_t)-1) umask(__gRuntimeLoader->program_args->umask); pthread_self()->id = find_thread(NULL); get_system_info(&info); __gCPUCount = info.cpu_count; __init_time((addr_t)__gCommPageAddress); __init_heap(); __init_env(__gRuntimeLoader->program_args); __init_heap_post_env(); __init_pwd_backend(); __set_stack_protection(); }