Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 113720 Details for
Bug 164656
sandbox: use own malloc
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
malloc.c
malloc.c (text/plain), 1.13 KB, created by
SpanKY
on 2007-03-18 22:16:42 UTC
(
hide
)
Description:
malloc.c
Filename:
MIME Type:
Creator:
SpanKY
Created:
2007-03-18 22:16:42 UTC
Size:
1.13 KB
patch
obsolete
>/* > */ > >#include <stdlib.h> /* malloc()/free() prototypes */ >#include <string.h> /* mem*() */ >#include <sys/mman.h> /* mmap() */ > >#define SB_MALLOC_TO_MMAP(ptr) ((void*)(((size_t*)ptr) - 1)) >#define SB_MMAP_TO_MALLOC(ptr) ((void*)(((size_t*)ptr) + 1)) >#define SB_MALLOC_TO_SIZE(ptr) (*((size_t*)SB_MALLOC_TO_MMAP(ptr))) > >void *malloc(size_t size) >{ > size_t *ret; > size += sizeof(size_t); > ret = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); > if (ret == MAP_FAILED) > return NULL; > *ret = size; > return SB_MMAP_TO_MALLOC(ret); >} > >void free(void *ptr) >{ > if (ptr == NULL) > return; > munmap(SB_MALLOC_TO_MMAP(ptr), SB_MALLOC_TO_SIZE(ptr)); >} > >void *calloc(size_t nmemb, size_t size) >{ > void *ret; > size_t malloc_size = nmemb * size; > ret = malloc(malloc_size); /* dont care about overflow */ > memset(ret, 0x00, malloc_size); > return ret; >} > >void *realloc(void *ptr, size_t size) >{ > void *ret; > size_t old_malloc_size; > > if (ptr == NULL) > return malloc(size); > if (size == 0) { > free(ptr); > return ptr; > } > > old_malloc_size = SB_MALLOC_TO_SIZE(ptr); > ret = malloc(size); > memcpy(ret, ptr, old_malloc_size); > free(ptr); > return ret; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 164656
:
108718
|
113681
| 113720 |
122973
|
132779
|
132845
|
134085