Revision 680c877a

b/Makefile.target
85 85

  
86 86
QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR)
87 87
obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \
88
      elfload.o linuxload.o uaccess.o gdbstub.o cpu-uname.o
88
      elfload.o linuxload.o uaccess.o gdbstub.o cpu-uname.o \
89
      qemu-malloc.o
89 90

  
90 91
obj-$(TARGET_HAS_BFLT) += flatload.o
91 92

  
b/linux-user/mmap.c
77 77
}
78 78
#endif
79 79

  
80
void *qemu_vmalloc(size_t size)
81
{
82
    void *p;
83

  
84
    mmap_lock();
85
    /* Use map and mark the pages as used.  */
86
    p = mmap(NULL, size, PROT_READ | PROT_WRITE,
87
             MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
88
    mmap_unlock();
89
    return p;
90
}
91

  
92
void *qemu_malloc(size_t size)
93
{
94
    char * p;
95
    size += 16;
96
    p = qemu_vmalloc(size);
97
    *(size_t *)p = size;
98
    return p + 16;
99
}
100

  
101
/* We use map, which is always zero initialized.  */
102
void * qemu_mallocz(size_t size)
103
{
104
    return qemu_malloc(size);
105
}
106

  
107
void qemu_free(void *ptr)
108
{
109
    /* FIXME: We should unmark the reserved pages here.  However this gets
110
       complicated when one target page spans multiple host pages, so we
111
       don't bother.  */
112
    size_t *p;
113
    p = (size_t *)((char *)ptr - 16);
114
    munmap(p, *p);
115
}
116

  
117
void *qemu_realloc(void *ptr, size_t size)
118
{
119
    size_t old_size, copy;
120
    void *new_ptr;
121

  
122
    if (!ptr)
123
        return qemu_malloc(size);
124
    old_size = *(size_t *)((char *)ptr - 16);
125
    copy = old_size < size ? old_size : size;
126
    new_ptr = qemu_malloc(size);
127
    memcpy(new_ptr, ptr, copy);
128
    qemu_free(ptr);
129
    return new_ptr;
130
}
131

  
132 80
/* NOTE: all the constants are the HOST ones, but addresses are target. */
133 81
int target_mprotect(abi_ulong start, abi_ulong len, int prot)
134 82
{

Also available in: Unified diff