1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2026-01-01 01:41:18 +01:00

guard malloc/free family

This commit is contained in:
Ludwig Ortmann 2014-01-24 17:03:01 +01:00
parent 5566734575
commit 4939473afb
3 changed files with 48 additions and 1 deletions

View File

@ -32,6 +32,10 @@ void _native_syscall_enter();
*/
extern ssize_t (*real_read)(int fd, void *buf, size_t count);
extern ssize_t (*real_write)(int fd, const void *buf, size_t count);
extern void* (*real_malloc)(size_t size);
extern void (*real_free)(void *ptr);
extern void* (*real_calloc)(size_t nmemb, size_t size);
extern void* (*real_realloc)(void *ptr, size_t size);
/**
* data structures

View File

@ -184,7 +184,12 @@ __attribute__((constructor)) static void startup(int argc, char **argv)
/* get system read/write/printf */
*(void **)(&real_read) = dlsym(RTLD_NEXT, "read");
*(void **)(&real_write) = dlsym(RTLD_NEXT, "write");
*(void **)(&real_printf) = dlsym(RTLD_NEXT, "printf");
*(void **)(&real_malloc) = dlsym(RTLD_NEXT, "malloc");
*(void **)(&real_calloc) = dlsym(RTLD_NEXT, "calloc");
*(void **)(&real_realloc) = dlsym(RTLD_NEXT, "realloc");
*(void **)(&real_free) = dlsym(RTLD_NEXT, "free");
*(void **)(&real_printf) = dlsym(RTLD_NEXT, "printf");
_progname = argv[0];
int argp = 1;

View File

@ -42,6 +42,10 @@ extern volatile tcb_t *active_thread;
ssize_t (*real_read)(int fd, void *buf, size_t count);
ssize_t (*real_write)(int fd, const void *buf, size_t count);
void* (*real_malloc)(size_t size);
void (*real_free)(void *ptr);
void* (*real_calloc)(size_t nmemb, size_t size);
void* (*real_realloc)(void *ptr, size_t size);
void _native_syscall_enter()
{
@ -72,6 +76,40 @@ void _native_syscall_leave()
}
}
void *malloc(size_t size)
{
void *r;
_native_syscall_enter();
r = real_malloc(size);
_native_syscall_leave();
return r;
}
void free(void *ptr)
{
_native_syscall_enter();
real_free(ptr);
_native_syscall_leave();
}
void *calloc(size_t nmemb, size_t size)
{
void *r;
_native_syscall_enter();
r = real_calloc(nmemb, size);
_native_syscall_leave();
return r;
}
void *realloc(void *ptr, size_t size)
{
void *r;
_native_syscall_enter();
r = real_realloc(ptr, size);
_native_syscall_leave();
return r;
}
ssize_t read(int fd, void *buf, size_t count)
{
ssize_t r;