hphp/hack/src/heap/hh_shared.c
// DON'T WRITE TO THE SHARED MEMORY IN THIS FUNCTION!!!  This function just
// calculates where the memory is and sets local globals. The shared memory
// might not be ready for writing yet! If you want to initialize a bit of
// shared memory, check out init_shared_globals
DON'T WRITE TO THE SHARED MEMORY IN THIS FUNCTION!!.  This function just
calculates where the memory is and sets local globals. The shared memory
might not be ready for writing yet. If you want to initialize a bit of
shared memory, check out init_shared_globals
DON ' T WRITE TO THE SHARED MEMORY IN THIS FUNCTION!! . This function just calculates where the memory is and sets local globals . The shared memory might not be ready for writing yet . If you want to initialize a bit of shared memory check out init_shared_globals
static void define_globals(char * shared_mem_init) {
  size_t page_size = getpagesize();
  char *mem = shared_mem_init;
  shared_mem = mem;
  #ifdef MADV_DONTDUMP
    madvise(shared_mem, shared_mem_size, MADV_DONTDUMP);
  #endif
  heap = (char**)mem;
  assert(CACHE_LINE_SIZE >= sizeof(uint64_t));
  hcounter = (uint64_t*)(mem + CACHE_LINE_SIZE);
  assert(CACHE_LINE_SIZE >= sizeof(uint64_t));
  dcounter = (uint64_t*)(mem + 2*CACHE_LINE_SIZE);
  assert (CACHE_LINE_SIZE >= sizeof(uintptr_t));
  counter = (uintptr_t*)(mem + 3*CACHE_LINE_SIZE);
  assert (CACHE_LINE_SIZE >= sizeof(pid_t));
  master_pid = (pid_t*)(mem + 4*CACHE_LINE_SIZE);
  assert (CACHE_LINE_SIZE >= sizeof(size_t));
  log_level = (size_t*)(mem + 5*CACHE_LINE_SIZE);
  mem += page_size;
  assert(page_size > 6*CACHE_LINE_SIZE + (int)sizeof(int));
  db_filename = (char*)mem;
  mem += page_size;
  hashtable_db_filename = (char*)mem;
  mem += page_size;
  global_storage = (value*)mem;
  mem += global_size_b;
  deptbl = (deptbl_entry_t*)mem;
  mem += dep_size_b;
  deptbl_bindings = (uint64_t*)mem;
  mem += bindings_size_b;
  hashtbl = (helt_t*)mem;
  mem += hashtbl_size_b;
  heap_init = mem;
  heap_max = heap_init + heap_size;
#ifdef _WIN32
  memfd_reserve((char *)global_storage, sizeof(global_storage[0]));
  memfd_reserve((char *)heap, heap_init - (char *)heap);
#endif
}
static void define_globals ( char * shared_mem_init ) { size_t page_size = getpagesize ( ) ; char * mem = shared_mem_init ; shared_mem = mem ; #ifdef MADV_DONTDUMP madvise ( shared_mem , shared_mem_size , MADV_DONTDUMP ) ; #endif heap = ( char * * ) mem ; assert ( CACHE_LINE_SIZE >= sizeof ( uint64_t ) ) ; hcounter = ( uint64_t * ) ( mem + CACHE_LINE_SIZE ) ; assert ( CACHE_LINE_SIZE >= sizeof ( uint64_t ) ) ; dcounter = ( uint64_t * ) ( mem + 2 * CACHE_LINE_SIZE ) ; assert ( CACHE_LINE_SIZE >= sizeof ( uintptr_t ) ) ; counter = ( uintptr_t * ) ( mem + 3 * CACHE_LINE_SIZE ) ; assert ( CACHE_LINE_SIZE >= sizeof ( pid_t ) ) ; master_pid = ( pid_t * ) ( mem + 4 * CACHE_LINE_SIZE ) ; assert ( CACHE_LINE_SIZE >= sizeof ( size_t ) ) ; log_level = ( size_t * ) ( mem + 5 * CACHE_LINE_SIZE ) ; mem += page_size ; assert ( page_size > 6 * CACHE_LINE_SIZE + ( int ) sizeof ( int ) ) ; db_filename = ( char * ) mem ; mem += page_size ; hashtable_db_filename = ( char * ) mem ; mem += page_size ; global_storage = ( value * ) mem ; mem += global_size_b ; deptbl = ( deptbl_entry_t * ) mem ; mem += dep_size_b ; deptbl_bindings = ( uint64_t * ) mem ; mem += bindings_size_b ; hashtbl = ( helt_t * ) mem ; mem += hashtbl_size_b ; heap_init = mem ; heap_max = heap_init + heap_size ; #ifdef _WIN32 memfd_reserve ( ( char * ) global_storage , sizeof ( global_storage [ 0 ] ) ) ; memfd_reserve ( ( char * ) heap , heap_init - ( char * ) heap ) ; #endif }
DON'T WRITE TO THE SHARED MEMORY IN THIS FUNCTION!!!
DON ' T WRITE TO THE SHARED MEMORY IN THIS FUNCTION!!!
// Beginning of the shared memory // We are unlikely to get much useful information out of the shared heap in // a core file. Moreover, it can be HUGE, and the extensive work done dumping // it once for each CPU can mean that the user will reboot their machine // before the much more useful stack gets dumped! /* BEGINNING OF THE SMALL OBJECTS PAGE
   * We keep all the small objects in this page.
   * They are on different cache lines because we modify them atomically.
   */ /* The pointer to the top of the heap.
   * We will atomically increment *heap every time we want to allocate.
   */ // The number of elements in the hashtable // The number of elements in the deptable // Just checking that the page is large enough. /* File name we get in hh_load_dep_table_sqlite needs to be smaller than
   * page_size - it should be since page_size is quite big for a string
   */ /* END OF THE SMALL OBJECTS PAGE */ /* Global storage initialization */ /* Dependencies */ /* Hashtable */ /* Heap */ /* Reserve all memory space except the "huge" `global_size_b`. This is
   * required for Windows but we don't do this for Linux since it lets us run
   * more processes in parallel without running out of memory immediately
   * (though we do risk it later on) */