about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2020-11-11 13:08:42 -0500
committerRich Felker <dalias@aerifal.cx>2020-11-11 13:31:50 -0500
commit34952fe5de44a833370cbe87b63fb8eec61466d7 (patch)
tree6d1cca357ba7a71778fc790db1ae394cd59f0a06 /src
parent8d37958d58cf36f53d5fcc7a8aa6d633da6071b2 (diff)
downloadmusl-34952fe5de44a833370cbe87b63fb8eec61466d7.tar.gz
musl-34952fe5de44a833370cbe87b63fb8eec61466d7.tar.xz
musl-34952fe5de44a833370cbe87b63fb8eec61466d7.zip
convert malloc use under libc-internal locks to use internal allocator
this change lifts undocumented restrictions on calls by replacement
mallocs to libc functions that might take these locks, and sets the
stage for lifting restrictions on the child execution environment
after multithreaded fork.

care is taken to #define macros to replace all four functions (malloc,
calloc, realloc, free) even if not all of them will be used, using an
undefined symbol name for the ones intended not to be used so that any
inadvertent future use will be caught at compile time rather than
directed to the wrong implementation.
Diffstat (limited to 'src')
-rw-r--r--src/aio/aio.c5
-rw-r--r--src/exit/atexit.c5
-rw-r--r--src/ldso/dlerror.c5
-rw-r--r--src/locale/dcngettext.c5
-rw-r--r--src/locale/locale_map.c6
-rw-r--r--src/thread/sem_open.c5
-rw-r--r--src/time/__tz.c5
7 files changed, 36 insertions, 0 deletions
diff --git a/src/aio/aio.c b/src/aio/aio.c
index b488e3d6..e004f98b 100644
--- a/src/aio/aio.c
+++ b/src/aio/aio.c
@@ -11,6 +11,11 @@
 #include "pthread_impl.h"
 #include "aio_impl.h"
 
+#define malloc __libc_malloc
+#define calloc __libc_calloc
+#define realloc __libc_realloc
+#define free __libc_free
+
 /* The following is a threads-based implementation of AIO with minimal
  * dependence on implementation details. Most synchronization is
  * performed with pthread primitives, but atomics and futex operations
diff --git a/src/exit/atexit.c b/src/exit/atexit.c
index 160d277a..fcd940fa 100644
--- a/src/exit/atexit.c
+++ b/src/exit/atexit.c
@@ -3,6 +3,11 @@
 #include "libc.h"
 #include "lock.h"
 
+#define malloc __libc_malloc
+#define calloc __libc_calloc
+#define realloc undef
+#define free undef
+
 /* Ensure that at least 32 atexit handlers can be registered without malloc */
 #define COUNT 32
 
diff --git a/src/ldso/dlerror.c b/src/ldso/dlerror.c
index d8bbfc03..c782ca6c 100644
--- a/src/ldso/dlerror.c
+++ b/src/ldso/dlerror.c
@@ -5,6 +5,11 @@
 #include "dynlink.h"
 #include "lock.h"
 
+#define malloc __libc_malloc
+#define calloc __libc_calloc
+#define realloc __libc_realloc
+#define free __libc_free
+
 char *dlerror()
 {
 	pthread_t self = __pthread_self();
diff --git a/src/locale/dcngettext.c b/src/locale/dcngettext.c
index 4c304393..39a98e83 100644
--- a/src/locale/dcngettext.c
+++ b/src/locale/dcngettext.c
@@ -11,6 +11,11 @@
 #include "pleval.h"
 #include "lock.h"
 
+#define malloc __libc_malloc
+#define calloc __libc_calloc
+#define realloc undef
+#define free undef
+
 struct binding {
 	struct binding *next;
 	int dirlen;
diff --git a/src/locale/locale_map.c b/src/locale/locale_map.c
index e7eede62..94f1b04e 100644
--- a/src/locale/locale_map.c
+++ b/src/locale/locale_map.c
@@ -1,10 +1,16 @@
 #include <locale.h>
 #include <string.h>
 #include <sys/mman.h>
+#include <stdlib.h>
 #include "locale_impl.h"
 #include "libc.h"
 #include "lock.h"
 
+#define malloc __libc_malloc
+#define calloc undef
+#define realloc undef
+#define free undef
+
 const char *__lctrans_impl(const char *msg, const struct __locale_map *lm)
 {
 	const char *trans = 0;
diff --git a/src/thread/sem_open.c b/src/thread/sem_open.c
index 6fb0c5b2..dad8f177 100644
--- a/src/thread/sem_open.c
+++ b/src/thread/sem_open.c
@@ -13,6 +13,11 @@
 #include <pthread.h>
 #include "lock.h"
 
+#define malloc __libc_malloc
+#define calloc __libc_calloc
+#define realloc undef
+#define free undef
+
 static struct {
 	ino_t ino;
 	sem_t *sem;
diff --git a/src/time/__tz.c b/src/time/__tz.c
index 49a7371e..3044d206 100644
--- a/src/time/__tz.c
+++ b/src/time/__tz.c
@@ -7,6 +7,11 @@
 #include "libc.h"
 #include "lock.h"
 
+#define malloc __libc_malloc
+#define calloc undef
+#define realloc undef
+#define free undef
+
 long  __timezone = 0;
 int   __daylight = 0;
 char *__tzname[2] = { 0, 0 };