static void __attribute__((constructor)) mallocsetup(void) { hts_lwmutex_init(&mutex); #ifdef USE_VIRTUAL_MEM int size = MB(256); int psize = MB(96); Lv2Syscall6(300, size, psize, 0xFFFFFFFFU, 0x200ULL, 1UL, (u64)&heap_base); #else int size = MB(96); Lv2Syscall3(348, size, 0x400, (u64)&heap_base); #endif total_avail = size; gpool = tlsf_create((void *)(intptr_t)heap_base, size); // Malloc is initialized now so we can safely do this http_path_add("/api/memstats", NULL, memstats, 1); }
//----------------------------------------------------------------// ZIPFS_TLSF_POOL* zipfs_tlsf_create_pool ( size_t bytes ) { ZIPFSTlsfPool* pool = ( ZIPFSTlsfPool* )malloc ( sizeof ( ZIPFSTlsfPool )); pool->mBuffer = malloc ( bytes ); pool->mPool = tlsf_create ( pool->mBuffer, bytes ); return ( ZIPFS_TLSF_POOL* )pool; }
void AllocatorTLSF_Impl::Reset() { memset(&Stats, 0, sizeof(Stats)); void* pRealArenaStart = oByteAlign(oByteAdd(Desc.pArena, sizeof(*this)), DEFAULT_MEMORY_ALIGNMENT); size_t realArenaSize = Desc.ArenaSize - std::distance((char*)Desc.pArena, (char*)pRealArenaStart); hPool = tlsf_create(pRealArenaStart, realArenaSize); Stats.NumAllocations = 0; Stats.BytesAllocated = 0; Stats.PeakBytesAllocated = 0; Stats.BytesFree = Desc.ArenaSize - tlsf_overhead(); }
void kernel_main(void* mem) { init_serial(); terminal_init(); terminal_writeln("Kernel Startup."); pool = tlsf_create((void*)0x2000000, 32768); //terminal_writehexln(pool); lua_State* L = lua_newstate(l_alloc, pool); lua_pushcfunction(L, l_Print); lua_setglobal(L, "print"); #define BUFFER_SIZE 128 #if 0 char test[BUFFER_SIZE]; test[BUFFER_SIZE-1] = 0; int i ; for(i = 0; i < BUFFER_SIZE-1; ++i) { test[i] = read_serial(); if(test[i] == 0 || test[i] == '\r' || test[i] == '\n') { break; } if(!IsValid(test[i])) { i--; continue; } } test[i] = 0; terminal_write("Read "); terminal_writehexln(i); terminal_writeln(test); #else char* test = "print(1 + 2)"; #endif size_t len = strlen(test); if(luaL_loadbufferx(L, test, len, "Sample", 0) != 0) { terminal_writeln(lua_tostring(L, -1)); } if(lua_pcall(L, 0, LUA_MULTRET, 0) != 0) { terminal_writeln(lua_tostring(L, -1)); } terminal_writeln("Finished"); }
void attachTlsMemoryPool(void *memPtr, size_t size, size_t maxThread) { g_tlsfPool_tls[0] = tlsf_create( memPtr, size ); }
void attachMemoryForCommonHeap( void* memPtr, size_t size ) { g_tlsfPool = tlsf_create( memPtr, size ); }
void initializeMemoryAllocator( void* memResource, size_t memSize ) { g_tlsfPool = tlsf_create( memResource, memSize ); }
void sunxi_init(void) { sunxi.dispfd = open("/dev/disp", O_RDWR); if(sunxi.dispfd == -1) { perror("open(/dev/disp)"); exit(1); } sunxi.fb0fd = open("/dev/fb0", O_RDWR); if(sunxi.fb0fd == -1) { perror("open(/dev/fb0)"); exit(1); } #if 0 int tmp = SUNXI_DISP_VERSION; if(ioctl(sunxi.dispfd, DISP_CMD_VERSION, &tmp) < 0) { perror("ioctl(DISP_CMD_VERSION))"); exit(1); } #endif disp_cleanup(); sunxi.cedarfd = open("/dev/cedar_dev", O_RDWR); if(sunxi.cedarfd == -1) { perror("open(/dev/cedar_dev)"); exit(1); } if(ioctl(sunxi.cedarfd, IOCTL_GET_ENV_INFO, &sunxi.env_info)) { perror("ioctl(IOCTL_GET_ENV_INFO)"); exit(1); } sunxi.macc = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, sunxi.cedarfd, sunxi.env_info.address_macc); if(sunxi.macc == MAP_FAILED) { perror("mmap of macc failed"); exit(1); } void *ptr = mmap(NULL, sunxi.env_info.phymem_total_size, PROT_READ | PROT_WRITE, MAP_SHARED, sunxi.cedarfd, sunxi.env_info.phymem_start); if(ptr == MAP_FAILED) { perror("mmap failed"); exit(1); } sunxi.gfxmembase = (intptr_t)ptr; sunxi.gfxmem = tlsf_create(ptr, sunxi.env_info.phymem_total_size); if(ioctl(sunxi.cedarfd, IOCTL_ENGINE_REQ, 0)) { perror("IOCTL_ENGINE_REQ"); exit(1); } ioctl(sunxi.cedarfd, IOCTL_ENABLE_VE, 0); ioctl(sunxi.cedarfd, IOCTL_SET_VE_FREQ, 320); ioctl(sunxi.cedarfd, IOCTL_RESET_VE, 0); ve_write(VE_CTRL, 0x00130007); sunxi.ve_version = ve_read(VE_VERSION) >> 16; TRACE(TRACE_INFO, "CEDAR", "Version 0x%04x opened. PA: %x VA: %p", sunxi.ve_version, sunxi.env_info.phymem_start, sunxi.gfxmembase); hts_mutex_init(&sunxi.gfxmem_mutex); unsigned long args[4] = {0}; args[1] = 0x64; if(ioctl(sunxi.dispfd, DISP_CMD_LAYER_CK_OFF, args)) { perror("DISP_CMD_LAYER_CK_OFF"); exit(1); } args[1] = 0x64; if(ioctl(sunxi.dispfd, DISP_CMD_LAYER_ALPHA_OFF, args)) { perror("DISP_CMD_LAYER_ALPHA_OFF"); exit(1); } #if 0 __disp_colorkey_t colorkey; colorkey.ck_min.alpha = 0; colorkey.ck_min.red = 0; colorkey.ck_min.green = 0; colorkey.ck_min.blue = 0; colorkey.ck_max.alpha = 255; colorkey.ck_max.red = 255; colorkey.ck_max.green = 255; colorkey.ck_max.blue = 255; colorkey.red_match_rule = 3; colorkey.green_match_rule = 3; colorkey.blue_match_rule = 3; args[1] = (intptr_t)&colorkey; if(ioctl(sunxi.dispfd, DISP_CMD_SET_COLORKEY, args)) { perror("DISP_CMD_SET_COLORKEY failed.\n"); } #endif sunxi_set_bg("/root/background.jpg"); }
void static_malloc_init(void) { static unsigned char heap[HEAP_SIZE]; g_pool = tlsf_create(heap, HEAP_SIZE); }