void runtime·mallocinit ( void ) { byte *p; uintptr arena_size , bitmap_size; extern byte end[]; byte *want; uintptr limit; #line 2311 "C:\Go\src\pkg\runtime\malloc.goc" p = nil; arena_size = 0; bitmap_size = 0; #line 2316 "C:\Go\src\pkg\runtime\malloc.goc" USED ( p ) ; USED ( arena_size ) ; USED ( bitmap_size ) ; #line 2320 "C:\Go\src\pkg\runtime\malloc.goc" runtime·InitSizes ( ) ; #line 2322 "C:\Go\src\pkg\runtime\malloc.goc" limit = runtime·memlimit ( ) ; #line 2327 "C:\Go\src\pkg\runtime\malloc.goc" if ( sizeof ( void* ) == 8 && ( limit == 0 || limit > ( 1<<30 ) ) ) { #line 2352 "C:\Go\src\pkg\runtime\malloc.goc" arena_size = 16LL<<30; bitmap_size = arena_size / ( sizeof ( void* ) *8/4 ) ; p = runtime·SysReserve ( ( void* ) ( 0x00f8ULL<<32 ) , bitmap_size + arena_size ) ; } if ( p == nil ) { #line 2374 "C:\Go\src\pkg\runtime\malloc.goc" bitmap_size = MaxArena32 / ( sizeof ( void* ) *8/4 ) ; arena_size = 512<<20; if ( limit > 0 && arena_size+bitmap_size > limit ) { bitmap_size = ( limit / 9 ) & ~ ( ( 1<<PageShift ) - 1 ) ; arena_size = bitmap_size * 8; } #line 2390 "C:\Go\src\pkg\runtime\malloc.goc" want = ( byte* ) ( ( ( uintptr ) end + ( 1<<18 ) + ( 1<<20 ) - 1 ) &~ ( ( 1<<20 ) -1 ) ) ; p = runtime·SysReserve ( want , bitmap_size + arena_size ) ; if ( p == nil ) runtime·throw ( "runtime: cannot reserve arena virtual address space" ) ; if ( ( uintptr ) p & ( ( ( uintptr ) 1<<PageShift ) -1 ) ) runtime·printf ( "runtime: SysReserve returned unaligned address %p; asked for %p" , p , bitmap_size+arena_size ) ; } if ( ( uintptr ) p & ( ( ( uintptr ) 1<<PageShift ) -1 ) ) runtime·throw ( "runtime: SysReserve returned unaligned address" ) ; #line 2400 "C:\Go\src\pkg\runtime\malloc.goc" runtime·mheap.bitmap = p; runtime·mheap.arena_start = p + bitmap_size; runtime·mheap.arena_used = runtime·mheap.arena_start; runtime·mheap.arena_end = runtime·mheap.arena_start + arena_size; #line 2406 "C:\Go\src\pkg\runtime\malloc.goc" runtime·MHeap_Init ( &runtime·mheap , runtime·SysAlloc ) ; m->mcache = runtime·allocmcache ( ) ; #line 2410 "C:\Go\src\pkg\runtime\malloc.goc" runtime·free ( runtime·malloc ( 1 ) ) ; }
int main(int argc, char *argv[]) { const char *map; int memfd; size_t fbm; const char *ptr, *end; size_t page = get_page_size(); size_t mapbase, maplen; int err = 1; (void)argc; mapbase = memlimit() & ~(page - 1); if (!mapbase) return 2; memfd = open("/dev/mem", O_RDONLY); if (memfd < 0) { fprintf(stderr, "%s: cannot open /dev/mem: %s\n", argv[0], strerror(errno)); return 2; } map = mmap(NULL, page, PROT_READ, MAP_SHARED, memfd, 0); if (map == MAP_FAILED) { fprintf(stderr, "%s: cannot map page 0: %s\n", argv[0], strerror(errno)); return 2; } fbm = *(uint16_t *)(map + 0x413) << 10; if (fbm < mapbase) fbm = mapbase; munmap((void *)map, page); if (fbm < 64*1024 || fbm >= 640*1024) return 1; maplen = 0xa0000 - mapbase; map = mmap(NULL, maplen, PROT_READ, MAP_SHARED, memfd, mapbase); if (map == MAP_FAILED) { fprintf(stderr, "%s: cannot map base memory: %s\n", argv[0], strerror(errno)); return 2; } ptr = map + (fbm - mapbase); end = map + (0xa0000 - mapbase); while (ptr < end) { if (valid_mbft((const struct mBFT *)ptr, end-ptr)) { output_params((const struct mBFT *)ptr); err = 0; break; } ptr += 16; } munmap((void *)map, maplen); return err; }