__uc_malloc hooks
Denys Vlasenko
vda.linux at googlemail.com
Sat Sep 15 21:09:17 UTC 2007
On Saturday 15 September 2007 20:03, Mike Frysinger wrote:
> think of libc_hidden_proto() as a function prototype and libc_hidden_def() as
> the function definition ... the proto makes sure everyone who calls said
> function uses the internal hidden version while the def creates that internal
> hidden version. thus you should see libc_hidden_proto(mmap) in every file
> that calls mmap() while you should see libc_hidden_def(mmap) in every file
> that defines mmap().
This explanation is good. Please add it to the libc-symbols.h
Regarding libc_hidden_proto's. We can group them in one internal .h
file and #include it last in the #includes:
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <pwd.h>
#include <string.h>
#include <crypt.h>
#include <stdlib.h>
#include <malloc.h>
+#include <hidden_protos.h> <-------------- here
The file itself will add only those protos which are visible, by analyzing
guard defines (those which are defined at the top of each include file):
#ifdef _SYS_MMAN_H
/* sys/mman.h */
libc_hidden_proto(mmap)
libc_hidden_proto(munmap)
libc_hidden_proto(mprotect)
libc_hidden_proto(msync)
#endif
This way, you don't need to sprinkle e.g. libc_hidden_proto(mmap)
into dozen .c files.
I am committing a change which deals with __uc_malloc, is it looks right?
Index: include/malloc.h
===================================================================
--- include/malloc.h (revision 19854)
+++ include/malloc.h (working copy)
@@ -190,6 +190,8 @@
* NB: do not use stdio in __uc_malloc_failed handler! */
extern void *__uc_malloc(size_t size);
extern void (*__uc_malloc_failed)(size_t size);
+libc_hidden_proto(__uc_malloc);
+libc_hidden_proto(__uc_malloc_failed);
#ifdef __cplusplus
} /* end of extern "C" */
Index: libc/stdlib/__uc_malloc.c
===================================================================
--- libc/stdlib/__uc_malloc.c (revision 19854)
+++ libc/stdlib/__uc_malloc.c (working copy)
@@ -25,6 +25,7 @@
#include <malloc.h>
void (*__uc_malloc_failed)(size_t size);
+libc_hidden_data_def(__uc_malloc_failed);
void *__uc_malloc(size_t size)
{
@@ -39,3 +40,4 @@
__uc_malloc_failed(size);
}
}
+libc_hidden_def(__uc_malloc);
--
vda
More information about the uClibc
mailing list