* [PATCH] Fix ia64 clone2
@ 2004-12-07 20:08 Jakub Jelinek
2004-12-07 20:34 ` Ulrich Drepper
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2004-12-07 20:08 UTC (permalink / raw)
To: Ulrich Drepper; +Cc: Glibc hackers, davidm
Hi!
Besides adding the RESET_PID stuff, this patch also fixes the _exit
call if function passed to clone2 ever returns (before gp was not restored
and thus _exit segfaulted).
2004-12-07 Jakub Jelinek <jakub@redhat.com>
* sysdeps/unix/sysv/linux/ia64/clone2.S (__clone2): Add support for
NPTL where the PID is stored at userlevel and needs to be reset when
CLONE_THREAD is not used. Restore gp before calling _exit.
nptl/
* sysdeps/ia64/tcb-offsets.sym (TID): Add.
* sysdeps/unix/sysv/linux/ia64/clone2.S: New file.
* Makefile (tests): Add tst-getpid2.c.
* tst-getpid1.c (TEST_CLONE_FLAGS): Define.
(do_test): Use it. Use __clone2 instead of clone on ia64.
* tst-getpid2.c: New test.
--- libc/sysdeps/unix/sysv/linux/ia64/clone2.S.jj 2004-04-28 20:39:49.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/ia64/clone2.S 2004-12-07 14:23:52.971586610 +0100
@@ -30,7 +30,7 @@
ENTRY(__clone2)
.prologue
- alloc r2=ar.pfs,8,0,6,0
+ alloc r2=ar.pfs,8,1,6,0
cmp.eq p6,p0=0,in0
mov r8=EINVAL
mov out0=in3 /* Flags are first syscall argument. */
@@ -63,15 +63,34 @@ ENTRY(__clone2)
cmp.eq CHILD,PARENT=0,r8 /* Are we the child? */
(p6) br.cond.spnt.many __syscall_error
;;
-(CHILD) ld8 out1=[in0],8 /* Retrieve code pointer. */
-(CHILD) mov out0=in4 /* Pass proper argument to fn */
+(CHILD) mov loc0=gp
(PARENT) ret
;;
+#ifdef RESET_PID
+ tbit.nz p6,p0=in3,16 /* CLONE_THREAD */
+ tbit.z p7,p10=in3,8 /* CLONE_VM */
+(p6) br.cond.dptk 1f
+ ;;
+ mov r15=SYS_ify (getpid)
+(p10) addl r8=-1,r0
+(p7) break __BREAK_SYSCALL
+ ;;
+ add r9=PID,r13
+ add r10=TID,r13
+ ;;
+ st4 [r9]=r8
+ st4 [r10]=r8
+ ;;
+#endif
+1: ld8 out1=[in0],8 /* Retrieve code pointer. */
+ mov out0=in4 /* Pass proper argument to fn */
+ ;;
ld8 gp=[in0] /* Load function gp. */
mov b6=out1
br.call.dptk.many rp=b6 /* Call fn(arg) in the child */
;;
mov out0=r8 /* Argument to _exit */
+ mov gp=loc0
.globl HIDDEN_JUMPTARGET(_exit)
br.call.dpnt.many rp=HIDDEN_JUMPTARGET(_exit)
/* call _exit with result from fn. */
--- libc/nptl/sysdeps/unix/sysv/linux/ia64/clone2.S.jj 2004-12-07 15:10:34.480852179 +0100
+++ libc/nptl/sysdeps/unix/sysv/linux/ia64/clone2.S 2004-12-07 15:10:41.277637762 +0100
@@ -0,0 +1,2 @@
+#define RESET_PID
+#include <sysdeps/unix/sysv/linux/ia64/clone2.S>
--- libc/nptl/sysdeps/ia64/tcb-offsets.sym.jj 2004-03-10 20:02:20.000000000 +0100
+++ libc/nptl/sysdeps/ia64/tcb-offsets.sym 2004-12-07 14:19:54.824158224 +0100
@@ -2,5 +2,6 @@
#include <tls.h>
PID offsetof (struct pthread, pid) - sizeof (struct pthread)
+TID offsetof (struct pthread, tid) - sizeof (struct pthread)
MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) - sizeof (struct pthread)
SYSINFO_OFFSET offsetof (tcbhead_t, private)
--- libc/nptl/tst-getpid2.c.jj 2004-12-07 14:17:13.094068910 +0100
+++ libc/nptl/tst-getpid2.c 2004-12-07 14:17:09.551702136 +0100
@@ -0,0 +1,2 @@
+#define TEST_CLONE_FLAGS CLONE_VM
+#include "tst-getpid1.c"
--- libc/nptl/tst-getpid1.c.jj 2004-12-05 08:46:02.000000000 +0100
+++ libc/nptl/tst-getpid1.c 2004-12-07 14:14:45.748407926 +0100
@@ -5,6 +5,10 @@
#include <sys/types.h>
#include <sys/wait.h>
+#ifndef TEST_CLONE_FLAGS
+#define TEST_CLONE_FLAGS 0
+#endif
+
static int sig;
static int
@@ -35,8 +39,16 @@ do_test (void)
return 1;
}
+#ifdef __ia64__
+ extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
+ size_t __child_stack_size, int __flags,
+ void *__arg, ...);
+ char st[256 * 1024];
+ pid_t p = __clone2 (f, st, sizeof (st), TEST_CLONE_FLAGS, 0);
+#else
char st[128 * 1024];
- pid_t p = clone (f, st + sizeof (st), 0, 0);
+ pid_t p = clone (f, st + sizeof (st), TEST_CLONE_FLAGS, 0);
+#endif
if (p == -1)
{
printf("clone failed: %m\n");
--- libc/nptl/Makefile.jj 2004-12-06 12:40:54.000000000 +0100
+++ libc/nptl/Makefile 2004-12-07 14:17:27.958411793 +0100
@@ -241,7 +241,7 @@ tests = tst-attr1 tst-attr2 tst-attr3 \
tst-backtrace1 \
tst-oddstacklimit \
tst-vfork1 tst-vfork2 tst-vfork1x tst-vfork2x \
- tst-getpid1
+ tst-getpid1 tst-getpid2
xtests = tst-setuid1 tst-setuid1-static
# Files which must not be linked with libpthread.
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix ia64 clone2
2004-12-07 20:08 [PATCH] Fix ia64 clone2 Jakub Jelinek
@ 2004-12-07 20:34 ` Ulrich Drepper
0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2004-12-07 20:34 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Glibc hackers
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Applied.
- --
⧠Ulrich Drepper ⧠Red Hat, Inc. ⧠444 Castro St ⧠Mountain View, CA â
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
iD8DBQFBthON2ijCOnn/RHQRAnk1AJ9Z8IIJ1BOb7w6/8VwuVy8U3+TldACgtXm9
QUdd3HByo5nyqXi3BappNBw=
=huuK
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-12-07 20:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-07 20:08 [PATCH] Fix ia64 clone2 Jakub Jelinek
2004-12-07 20:34 ` Ulrich Drepper
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).