From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5804 invoked by alias); 20 Sep 2006 14:22:41 -0000 Received: (qmail 5788 invoked by uid 22791); 20 Sep 2006 14:22:40 -0000 X-Spam-Check-By: sourceware.org Received: from mtagate6.de.ibm.com (HELO mtagate6.de.ibm.com) (195.212.29.155) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 20 Sep 2006 14:22:33 +0000 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate6.de.ibm.com (8.13.8/8.13.8) with ESMTP id k8KEMU9q031448 for ; Wed, 20 Sep 2006 14:22:30 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.6/8.13.6/NCO v8.1.1) with ESMTP id k8KERHMh2629670 for ; Wed, 20 Sep 2006 16:27:17 +0200 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id k8KEMUwT009066 for ; Wed, 20 Sep 2006 16:22:30 +0200 Received: from localhost (dyn-9-152-216-78.boeblingen.de.ibm.com [9.152.216.78]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id k8KEMUBH009063 for ; Wed, 20 Sep 2006 16:22:30 +0200 Date: Wed, 20 Sep 2006 14:22:00 -0000 From: Martin Schwidefsky To: libc-hacker@sources.redhat.com Subject: [patch] s390: makecontext trampoline. Message-ID: <20060920142230.GA4587@skybase> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2006-09/txt/msg00036.txt.bz2 Hi, the makecontext function should not use the stack for a trampoline for no good reason. If we ever want to implement non-executable-stack this will bite us. -- blue skies, Martin. Martin Schwidefsky Linux for zSeries Development & Services IBM Deutschland Entwicklung GmbH "Reality continues to ruin my life." - Calvin. --- 2006-09-20 Martin Schwidefsky * sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c (__makecontext): Cast sp to unsigned long to avoid compiler warning. (__makecontext): Use __makecontext_ret function instead of a trampoline on the stack. (__makecontext_ret): New function. * sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c: Likewise. diff -urpN libc/sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c libc-s390/sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c --- libc/sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c 2001-07-06 06:56:19.000000000 +0200 +++ libc-s390/sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c 2006-08-25 14:38:22.000000000 +0200 @@ -37,8 +37,6 @@ +-----------------------+ n | overflow parameters | 96 +-----------------------+ - 8 | trampoline | 96+n - +-----------------------+ The registers are set up like this: %r2-%r6: parameters 1 to 5 %r7 : (*func) pointer @@ -55,18 +53,16 @@ void __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...) { + extern void __makecontext_ret (void); unsigned long *sp; va_list ap; int i; - sp = (long *) (((long) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & -8L); - - /* Setup the trampoline. */ - *--sp = 0x07f90000; - *--sp = 0x0de71828; + sp = (unsigned long *) (((unsigned long) ucp->uc_stack.ss_sp + + ucp->uc_stack.ss_size) & -8L); /* Set the return address to trampoline. */ - ucp->uc_mcontext.gregs[14] = (long) sp; + ucp->uc_mcontext.gregs[14] = (long) __makecontext_ret; /* Set register parameters. */ va_start (ap, argc); @@ -98,4 +94,12 @@ __makecontext (ucontext_t *ucp, void (*f ucp->uc_mcontext.gregs[15] = (long) sp; } +asm(".text\n" + ".type __makecontext_ret,@function\n" + "__makecontext_ret:\n" + " basr %r14,%r7\n" + " lr %r2,%r8\n" + " br %r9\n" + ".size __makecontext_ret, .-__makecontext_ret"); + weak_alias (__makecontext, makecontext) diff -urpN libc/sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c libc-s390/sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c --- libc/sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c 2001-07-06 06:56:20.000000000 +0200 +++ libc-s390/sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c 2006-08-25 14:38:27.000000000 +0200 @@ -37,8 +37,6 @@ +-----------------------+ n | overflow parameters | 160 +-----------------------+ - 8 | trampoline | 160+n - +-----------------------+ The registers are set up like this: %r2-%r6: parameters 1 to 5 %r7 : (*func) pointer @@ -55,17 +53,16 @@ void __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...) { + extern void __makecontext_ret (void); unsigned long *sp; va_list ap; int i; - sp = (long *) (((long) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & -8L); - - /* Setup the trampoline. */ - *--sp = 0x0de7b904002807f9; + sp = (unsigned long *) (((unsigned long) ucp->uc_stack.ss_sp + + ucp->uc_stack.ss_size) & -8L); /* Set the return address to trampoline. */ - ucp->uc_mcontext.gregs[14] = (long) sp; + ucp->uc_mcontext.gregs[14] = (long) __makecontext_ret; /* Set register parameters. */ va_start (ap, argc); @@ -97,4 +94,12 @@ __makecontext (ucontext_t *ucp, void (*f ucp->uc_mcontext.gregs[15] = (long) sp; } +asm(".text\n" + ".type __makecontext_ret,@function\n" + "__makecontext_ret:\n" + " basr %r14,%r7\n" + " lgr %r2,%r8\n" + " br %r9\n" + ".size __makecontext_ret, .-__makecontext_ret"); + weak_alias (__makecontext, makecontext)