From a91fd736527b29aa9cd786b3d239d0708bc67e72 Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Wed, 18 Sep 2002 13:47:39 +0000 Subject: Fix trampoline issues, by making sure the right stack portion is PROT_EXEC. tested by miod@, millert@ With comments from theo and mickey. ok miod@ --- gnu/egcs/gcc/config.gcc | 9 ++++++++- gnu/egcs/gcc/config/exec-stack.h | 39 +++++++++++++++++++++++++++++++++++++++ gnu/egcs/gcc/config/i386/i386.h | 8 ++++++++ gnu/egcs/gcc/config/vax/vax.h | 8 ++++++++ gnu/egcs/gcc/config/xm-openbsd.h | 5 ++++- 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 gnu/egcs/gcc/config/exec-stack.h (limited to 'gnu') diff --git a/gnu/egcs/gcc/config.gcc b/gnu/egcs/gcc/config.gcc index 501d4e996b5..f6de0cb53ee 100644 --- a/gnu/egcs/gcc/config.gcc +++ b/gnu/egcs/gcc/config.gcc @@ -211,6 +211,7 @@ alpha*-*-netbsd*) alpha*-*-openbsd*) # default x-alpha is only appropriate for dec-osf. + tm_file="${tm_file} exec-stack.h" target_cpu_default="MASK_GAS" tmake_file="alpha/t-ieee" gas=yes gnu_ld=yes @@ -421,6 +422,7 @@ h8300-*-*) float_format=i32 ;; hppa*-*-openbsd*) +# tm_file="${tm_file} exec-stack.h" target_cpu_default="MASK_PA_11" tmake_file=pa/t-openbsd ;; @@ -717,6 +719,7 @@ use_collect2=yes ;; i[34567]86-*-openbsd*) # needed to unconfuse gdb + tm_file="${tm_file} exec-stack.h" tmake_file="t-libc-ok t-openbsd i386/t-openbsd" # we need collect2 until our bug is fixed... use_collect2=yes @@ -1527,6 +1530,7 @@ m68k*-*-netbsd*) use_collect2=yes ;; m68k*-*-openbsd*) +# tm_file="${tm_file} exec-stack.h" tmake_file="t-libc-ok t-openbsd m68k/t-openbsd" float_format=m68k # we need collect2 until our bug is fixed... @@ -1652,6 +1656,7 @@ m88k-*-luna*) fi ;; m88k-*-openbsd*) +# tm_file="${tm_file} exec-stack.h" tmake_file="${tmake_file} m88k/t-luna-gas" ;; m88k-*-sysv3*) @@ -2493,12 +2498,13 @@ sparc-*-netbsd*) use_collect2=yes ;; sparc-*-openbsd*) + tm_file="${tm_file} exec-stack.h" tmake_file="t-libc-ok t-openbsd sparc/t-openbsd" gas=yes gnu_ld=yes use_collect2=no ;; sparc64-*-openbsd*) - tm_file=sparc/openbsd64.h + tm_file="sparc/openbsd64.h exec-stack.h" xm_file=sparc/xm-sp64.h gas=yes gnu_ld=yes ;; @@ -2739,6 +2745,7 @@ vax-*-netbsd*) use_collect2=yes ;; vax-*-openbsd*) + tm_file="${tm_file} exec-stack.h" tmake_file="${tmake_file} vax/t-openbsd" float_format=vax use_collect2=yes diff --git a/gnu/egcs/gcc/config/exec-stack.h b/gnu/egcs/gcc/config/exec-stack.h new file mode 100644 index 00000000000..96c99787304 --- /dev/null +++ b/gnu/egcs/gcc/config/exec-stack.h @@ -0,0 +1,39 @@ +/* Enable stack execute around trampoline address. + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#undef FINALIZE_TRAMPOLINE +#define FINALIZE_TRAMPOLINE(TRAMP) \ + emit_library_call(gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"), \ + 0, VOIDmode, 1, memory_address (SImode, (TRAMP)), Pmode) + +#define TRANSFER_FROM_TRAMPOLINE \ +extern void __enable_execute_stack (void *); \ +void \ +__enable_execute_stack (addr) \ + void *addr; \ +{ \ + long size = getpagesize (); \ + long mask = ~(size-1); \ + char *page = (char *) (((long) addr) & mask); \ + char *end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \ + \ + if (mprotect (page, end - page, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) \ + perror ("mprotect of trampoline code"); \ +} diff --git a/gnu/egcs/gcc/config/i386/i386.h b/gnu/egcs/gcc/config/i386/i386.h index 33cd918469b..4dfa7171a23 100644 --- a/gnu/egcs/gcc/config/i386/i386.h +++ b/gnu/egcs/gcc/config/i386/i386.h @@ -1577,6 +1577,13 @@ do { \ #define TRAMPOLINE_SIZE 10 +/* Targets redefine this to invoke code to either flush the cache, + or enable stack execution (or both). */ + +#ifndef FINALIZE_TRAMPOLINE +#define FINALIZE_TRAMPOLINE(TRAMP) +#endif + /* Emit RTL insns to initialize the variable parts of a trampoline. FNADDR is an RTX for the address of the function's pure code. CXT is an RTX for the static chain value for the function. */ @@ -1591,6 +1598,7 @@ do { \ emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 1)), CXT); \ emit_move_insn (gen_rtx_MEM (QImode, plus_constant (TRAMP, 5)), GEN_INT (0xe9));\ emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 6)), disp); \ + FINALIZE_TRAMPOLINE(TRAMP); \ } /* Definitions for register eliminations. diff --git a/gnu/egcs/gcc/config/vax/vax.h b/gnu/egcs/gcc/config/vax/vax.h index ad8fb7cc476..89f6b8a639d 100644 --- a/gnu/egcs/gcc/config/vax/vax.h +++ b/gnu/egcs/gcc/config/vax/vax.h @@ -544,6 +544,13 @@ gen_rtx (PLUS, Pmode, frame, GEN_INT (12)) #define TRAMPOLINE_SIZE 15 +/* Targets redefine this to invoke code to either flush the cache, + or enable stack execution (or both). */ + +#ifndef FINALIZE_TRAMPOLINE +#define FINALIZE_TRAMPOLINE(TRAMP) +#endif + /* Emit RTL insns to initialize the variable parts of a trampoline. FNADDR is an RTX for the address of the function's pure code. CXT is an RTX for the static chain value for the function. */ @@ -559,6 +566,7 @@ gen_rtx (PLUS, Pmode, frame, GEN_INT (12)) emit_move_insn (gen_rtx (MEM, SImode, plus_constant (TRAMP, 4)), CXT);\ emit_move_insn (gen_rtx (MEM, SImode, plus_constant (TRAMP, 11)), \ plus_constant (FNADDR, 2)); \ + FINALIZE_TRAMPOLINE(TRAMP); \ } /* Byte offset of return address in a stack frame. The "saved PC" field diff --git a/gnu/egcs/gcc/config/xm-openbsd.h b/gnu/egcs/gcc/config/xm-openbsd.h index 74a842184c3..dd46f50e384 100644 --- a/gnu/egcs/gcc/config/xm-openbsd.h +++ b/gnu/egcs/gcc/config/xm-openbsd.h @@ -32,4 +32,7 @@ Boston, MA 02111-1307, USA. */ #define alloca __builtin_alloca #endif - +#ifdef L_trampoline +#include +#include +#endif -- cgit v1.2.3