Commit e8999f7a authored by Paolo \'Blaisorblade\' Giarrusso's avatar Paolo \'Blaisorblade\' Giarrusso Committed by Linus Torvalds

[PATCH] uml: use sys_getpid bypassing glibc (fixes UML on Gentoo)

From: Bodo Stroesser <bstroesser@fujitsu-siemens.com>,
      Paolo 'Blaisorblade' Giarrusso <blaisorblade_spam@yahoo.it>
Cc: Ulrich Drepper <drepper@redhat.com>

Using NPTL, getpid() sometimes delivers the wrong pid, since it uses the
one buffered in TLS from previous calls.  This buffered pid isn't
discarded, when a child is created by a clone().

So, as a workaround, UML should use a direct kernel call to bypass the lib.

Also, I (Paolo) went replacing all remaining calls of getpid() with
os_getpid(), to make sure they use the syscall and not the normal glibc
definition.
Signed-off-by: default avatarBodo Stroesser <bstroesser@fujitsu-siemens.com>
Signed-off-by: default avatarPaolo 'Blaisorblade' Giarrusso <blaisorblade_spam@yahoo.it>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 79286dfb
...@@ -140,7 +140,7 @@ static void child_common(struct common_raw *common, sighandler_t handler, ...@@ -140,7 +140,7 @@ static void child_common(struct common_raw *common, sighandler_t handler,
} }
if(sigaltstack(&ss, NULL) < 0){ if(sigaltstack(&ss, NULL) < 0){
printf("sigaltstack failed - errno = %d\n", errno); printf("sigaltstack failed - errno = %d\n", errno);
kill(getpid(), SIGKILL); kill(os_getpid(), SIGKILL);
} }
if(restorer){ if(restorer){
...@@ -162,7 +162,7 @@ static void child_common(struct common_raw *common, sighandler_t handler, ...@@ -162,7 +162,7 @@ static void child_common(struct common_raw *common, sighandler_t handler,
if(err < 0){ if(err < 0){
printf("sigaction failed - errno = %d\n", errno); printf("sigaction failed - errno = %d\n", errno);
kill(getpid(), SIGKILL); kill(os_getpid(), SIGKILL);
} }
os_stop_process(os_getpid()); os_stop_process(os_getpid());
...@@ -191,7 +191,7 @@ static void sc_handler(int sig, struct sigcontext sc) ...@@ -191,7 +191,7 @@ static void sc_handler(int sig, struct sigcontext sc)
setup_arch_frame_raw(&raw_sc->common.arch, &sc + 1, raw_sc->common.sr); setup_arch_frame_raw(&raw_sc->common.arch, &sc + 1, raw_sc->common.sr);
os_stop_process(os_getpid()); os_stop_process(os_getpid());
kill(getpid(), SIGKILL); kill(os_getpid(), SIGKILL);
} }
static int sc_child(void *arg) static int sc_child(void *arg)
...@@ -229,7 +229,7 @@ static void si_handler(int sig, siginfo_t *si, struct ucontext *ucontext) ...@@ -229,7 +229,7 @@ static void si_handler(int sig, siginfo_t *si, struct ucontext *ucontext)
ucontext->uc_mcontext.fpregs, raw_si->common.sr); ucontext->uc_mcontext.fpregs, raw_si->common.sr);
os_stop_process(os_getpid()); os_stop_process(os_getpid());
kill(getpid(), SIGKILL); kill(os_getpid(), SIGKILL);
} }
static int si_child(void *arg) static int si_child(void *arg)
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "uml-config.h" #include "uml-config.h"
#include "irq_user.h" #include "irq_user.h"
#include "time_user.h" #include "time_user.h"
#include "os.h"
/* Set in set_stklim, which is called from main and __wrap_malloc. /* Set in set_stklim, which is called from main and __wrap_malloc.
* __wrap_malloc only calls it if main hasn't started. * __wrap_malloc only calls it if main hasn't started.
...@@ -175,7 +176,7 @@ int main(int argc, char **argv, char **envp) ...@@ -175,7 +176,7 @@ int main(int argc, char **argv, char **envp)
} }
#define CAN_KMALLOC() \ #define CAN_KMALLOC() \
(kmalloc_ok && CHOOSE_MODE((getpid() != tracing_pid), 1)) (kmalloc_ok && CHOOSE_MODE((os_getpid() != tracing_pid), 1))
extern void *__real_malloc(int); extern void *__real_malloc(int);
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
int is_skas_winch(int pid, int fd, void *data) int is_skas_winch(int pid, int fd, void *data)
{ {
if(pid != getpid()) if(pid != os_getpid())
return(0); return(0);
register_winch_irq(-1, fd, -1, data); register_winch_irq(-1, fd, -1, data);
......
...@@ -107,6 +107,10 @@ void os_usr1_process(int pid) ...@@ -107,6 +107,10 @@ void os_usr1_process(int pid)
kill(pid, SIGUSR1); kill(pid, SIGUSR1);
} }
/*Don't use the glibc version, which caches the result in TLS. It misses some
* syscalls, and also breaks with clone(), which does not unshare the TLS.*/
inline _syscall0(pid_t, getpid)
int os_getpid(void) int os_getpid(void)
{ {
return(getpid()); return(getpid());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment