Martin Pohlack
2004-01-27 00:28:06 UTC
Hi again,
recently I ported the dietLibC to a non--unix-like OS (DROPS,
http://os.inf.tu-dresden.de/drops/). As DROPS is based on a microkernel
there are no such fancy syscalls as gettimeofday() or mmap().
Consequently, colleagues and me had to come up with a set of "backends"
to implement the missing functionality.
One such backend is a memory backend, which just provides anonymous
mmap(). However, there were reasons to completely exchange the malloc()
functions. Therefore, it is helpful that malloc(), realloc(), and
free() are defined as weak symbols. For some reasons, calloc() is not.
Is there any reason for this?
Anyway here is a patch for dietlibc/lib/alloc.c:
--- alloc.c 21 Dec 2003 12:06:36 -0000 1.35
+++ alloc.c 27 Jan 2004 00:31:19 -0000
@@ -175,7 +175,8 @@
void* __libc_malloc(size_t size) __attribute__((alias("_alloc_libc_malloc")));
void* malloc(size_t size) __attribute__((weak,alias("_alloc_libc_malloc")));
-void *calloc(size_t nmemb, size_t _size) {
+void* calloc(size_t nmemb, size_t _size) __attribute__((weak));
+void* calloc(size_t nmemb, size_t _size) {
register size_t size=_size*nmemb;
if (nmemb && size/nmemb!=_size) {
(*__errno_location())=ENOMEM;
@@ -234,4 +235,3 @@
return ptr;
}
void* realloc(void* ptr, size_t size) __attribute__((weak,alias("__libc_realloc")));
-
Please let me know, if there is a better way to propose changes than
this list. Probably I will come up with more.
recently I ported the dietLibC to a non--unix-like OS (DROPS,
http://os.inf.tu-dresden.de/drops/). As DROPS is based on a microkernel
there are no such fancy syscalls as gettimeofday() or mmap().
Consequently, colleagues and me had to come up with a set of "backends"
to implement the missing functionality.
One such backend is a memory backend, which just provides anonymous
mmap(). However, there were reasons to completely exchange the malloc()
functions. Therefore, it is helpful that malloc(), realloc(), and
free() are defined as weak symbols. For some reasons, calloc() is not.
Is there any reason for this?
Anyway here is a patch for dietlibc/lib/alloc.c:
--- alloc.c 21 Dec 2003 12:06:36 -0000 1.35
+++ alloc.c 27 Jan 2004 00:31:19 -0000
@@ -175,7 +175,8 @@
void* __libc_malloc(size_t size) __attribute__((alias("_alloc_libc_malloc")));
void* malloc(size_t size) __attribute__((weak,alias("_alloc_libc_malloc")));
-void *calloc(size_t nmemb, size_t _size) {
+void* calloc(size_t nmemb, size_t _size) __attribute__((weak));
+void* calloc(size_t nmemb, size_t _size) {
register size_t size=_size*nmemb;
if (nmemb && size/nmemb!=_size) {
(*__errno_location())=ENOMEM;
@@ -234,4 +235,3 @@
return ptr;
}
void* realloc(void* ptr, size_t size) __attribute__((weak,alias("__libc_realloc")));
-
Please let me know, if there is a better way to propose changes than
this list. Probably I will come up with more.
--
Martin Pohlack
gpg key: http://os.inf.tu-dresden.de/~mp26/keys/Martin_Pohlack.asc
fingerprint: 4506 2C3C F5FA 96E6 0EA4 314D A8C2 1C32 1545 8E58
Martin Pohlack
gpg key: http://os.inf.tu-dresden.de/~mp26/keys/Martin_Pohlack.asc
fingerprint: 4506 2C3C F5FA 96E6 0EA4 314D A8C2 1C32 1545 8E58