use weak aliases rather than function pointers to simplify some code
authorRich Felker <dalias@aerifal.cx>
Sun, 7 Aug 2011 00:09:51 +0000 (20:09 -0400)
committerRich Felker <dalias@aerifal.cx>
Sun, 7 Aug 2011 00:09:51 +0000 (20:09 -0400)
src/internal/libc.h
src/process/fork.c
src/thread/cancel_dummy.c
src/thread/cancel_impl.c
src/thread/pthread_atfork.c
src/thread/pthread_testcancel.c

index 929ff97ae4257d8493d6c6c0e7c32c6ce58c5445..07ed70cd24c881967aff13dda149a980b1ffc4d4 100644 (file)
@@ -6,10 +6,8 @@
 
 struct __libc {
        int *(*errno_location)(void);
-       void (*testcancel)(void);
        int threaded;
        int canceldisable;
-       void (*fork_handler)(int);
        int (*atexit)(void (*)(void));
        void (*fini)(void);
        void (*ldso_fini)(void);
index 7530ff9376ce6689c9b34f6dd68c2cd5c3cc88bb..a8bdbe0b03833cd763a0ad661de90d6d8d295dd2 100644 (file)
@@ -3,10 +3,16 @@
 #include "libc.h"
 #include "pthread_impl.h"
 
+static void dummy(int x)
+{
+}
+
+weak_alias(dummy, __fork_handler);
+
 pid_t fork(void)
 {
        pid_t ret;
-       if (libc.fork_handler) libc.fork_handler(-1);
+       __fork_handler(-1);
        ret = syscall(SYS_fork);
        if (libc.main_thread && !ret) {
                pthread_t self = __pthread_self();
@@ -15,6 +21,6 @@ pid_t fork(void)
                libc.threads_minus_1 = 0;
                libc.main_thread = self;
        }
-       if (libc.fork_handler) libc.fork_handler(!ret);
+       __fork_handler(!ret);
        return ret;
 }
index a39117e75c289a4b43c73808265c179ee5751b93..047692c407007cf282ff3e4e7bb64b65b7450382 100644 (file)
@@ -6,3 +6,9 @@ static long sccp(long nr, long u, long v, long w, long x, long y, long z)
 }
 
 weak_alias(sccp, __syscall_cp);
+
+static void dummy()
+{
+}
+
+weak_alias(dummy, __testcancel);
index 9a02e1a10fbdfdc9b69f32db021a8d8e9e5ef4c4..4f78a63a84ccc87c6736abb8b5c2589a14755f34 100644 (file)
@@ -58,7 +58,7 @@ static void cancel_handler(int sig, siginfo_t *si, void *ctx)
                __syscall(SYS_tgkill, self->pid, self->tid, SIGCANCEL);
 }
 
-static void testcancel()
+void __testcancel()
 {
        pthread_t self = __pthread_self();
        if (self->cancel && !self->canceldisable)
@@ -73,7 +73,6 @@ static void init_cancellation()
        };
        sigfillset(&sa.sa_mask);
        __libc_sigaction(SIGCANCEL, &sa, 0);
-       libc.testcancel = testcancel;
 }
 
 int pthread_cancel(pthread_t t)
index 0773dc8f4d36e924cd11e0eb711cf1f3a42b2ab8..a7a82016d84736cb81de03dbaf53d0c91734cde9 100644 (file)
@@ -10,9 +10,10 @@ static struct atfork_funcs {
 
 static int lock;
 
-static void fork_handler(int who)
+void __fork_handler(int who)
 {
        struct atfork_funcs *p;
+       if (!funcs) return;
        if (who < 0) {
                LOCK(&lock);
                for (p=funcs; p; p = p->next) {
@@ -35,7 +36,6 @@ int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(vo
        if (!new) return -1;
 
        LOCK(&lock);
-       libc.fork_handler = fork_handler;
        new->next = funcs;
        new->prev = 0;
        new->prepare = prepare;
index c6b250b2ccd6cb1af3a65587b21e229b92e055f8..33238c0f70c5af59e17c40a0537b8bc578b36116 100644 (file)
@@ -1,6 +1,8 @@
 #include "pthread_impl.h"
 
+void __testcancel(void);
+
 void pthread_testcancel()
 {
-       if (libc.testcancel) libc.testcancel();
+       __testcancel();
 }