22 #include <sys/types.h> 
  124 #define MADDR 0x100000000 
  126 static char shm_mm_name[NAME_MAX];
 
  127 static int shm_mm_on = 0;
 
  128 static int shm_mm_fd = -1;
 
  129 static off_t shm_mm_length = 0;
 
  130 static void *shm_mm_base = (
void *)0;
 
  131 static mspace global_mspace;
 
  138     printf(
"morecore: %d\n",size);
 
  141     if (!shm_mm_base || shm_mm_fd < 0)
 
  146     printf(
"morecore: ret 0x%lx\n",(uintptr_t)(shm_mm_base + shm_mm_length + 1));
 
  147     return (shm_mm_base + shm_mm_length + 1);
 
  150     if (ftruncate(shm_mm_fd,shm_mm_length + size)) {
 
  151     verror(
"ftruncate: %s\n",strerror(errno));
 
  153     return (
void *)
MFAIL;
 
  155     else if (mremap(shm_mm_base,shm_mm_length,shm_mm_length + size,0)
 
  157     verror(
"mremap: %s\n",strerror(errno));
 
  159     return (
void *)
MFAIL;
 
  162     shm_mm_length += size;
 
  164     printf(
"morecore: ret 0x%lx (0x%lx,0x%lx)\n",
 
  165            (uintptr_t)(shm_mm_base + shm_mm_length - size + 1),
 
  166            (uintptr_t)shm_mm_base,(uintptr_t)shm_mm_length);
 
  167     return (shm_mm_base + shm_mm_length - size + 1);
 
  172     shm_mm_fd = shm_open(name,O_CREAT | O_EXCL | O_RDWR,
 
  173              S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
 
  177     if (ftruncate(shm_mm_fd,size)) {
 
  178     shm_unlink(shm_mm_name);
 
  184          shm_mm_fd,0) != (
void *)
MADDR) {
 
  185     shm_unlink(shm_mm_name);
 
  190     shm_mm_base = (
void *)
MADDR;
 
  191     shm_mm_length = size;
 
  192     strncpy(shm_mm_name,name,NAME_MAX);
 
  193     shm_mm_name[NAME_MAX - 1] = 
'\0';
 
  194     global_mspace = create_mspace_with_base(shm_mm_base,shm_mm_length,0);
 
  204     return mspace_calloc(global_mspace,nmemb,size);
 
  211     return mspace_free(global_mspace,ptr);
 
  218     return mspace_malloc(global_mspace,size);
 
  225     return mspace_realloc(global_mspace,ptr,size);
 
  232     return mspace_memalign(global_mspace,alignment,size);
 
  239     return mspace_posix_memalign(global_mspace,memptr,alignment,size);
 
  246     return mspace_memalign(global_mspace,
PAGE_SIZE,size);
 
  254     return mspace_memalign(global_mspace,
PAGE_SIZE,rsize);
 
  262     return mspace_mallinfo(global_mspace);
 
  270     return mspace_mallopt(param,value);
 
  277     return mspace_trim(global_mspace,pad);
 
  284     return mspace_malloc_stats(global_mspace);
 
  292     return mspace_usable_size((
const void *)ptr);
 
  297     munmap((
void *)
MADDR,shm_mm_length);
 
  298     shm_unlink(shm_mm_name);
 
  306 int main(
int argc,
char **argv) {
 
  309     char sname[NAME_MAX];
 
  313     verror(
"Must supply a debugfile pathname!\n");
 
  317     if (geteuid() != 0) {
 
  318     verror(
"must be root!\n");
 
  322     if (stat(
"/var/lib/vmi",&sbuf) && mkdir(
"/var/lib/vmi",0)) {
 
  323     verror(
"could not create /var/lib/vmi: %s\n",strerror(errno));
 
  330     strncpy(sname,argv[1],NAME_MAX);
 
  331     sname[NAME_MAX - 1] = 
'\0';
 
  334     for (cptr = sname; *cptr != 
'\0'; ++cptr)
 
  339     verror(
"Could not initialize shm-backed heap: %s\n",strerror(errno));
 
  352     printf(
"shm_base = 0x%lx, shm_length = 0x%lx, debugfile = 0x%lx ...\n",
 
  353        (uintptr_t)shm_mm_base,(uintptr_t)shm_mm_length,(uintptr_t)debugfile);
 
struct debugfile * debugfile_from_file(char *filename, char *root_prefix, struct array_list *debugfile_load_opts_list)
int shm_init(char *name, off_t size)
int mallopt(int param, int value)
int malloc_trim(size_t pad)
#define verror(format,...)
void * memalign(size_t alignment, size_t size)
void * shm_morecore(int size)
int main(int argc, char **argv)
void * mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
int posix_memalign(void **memptr, size_t alignment, size_t size)
void * valloc(size_t size)
void * realloc(void *ptr, size_t size)
void * calloc(size_t nmemb, size_t size)
size_t malloc_usable_size(void *ptr)
#define dlmalloc_usable_size
void * malloc(size_t size)
void * pvalloc(size_t size)