home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / CLISP-2.LHA / CLISP960530-ki.lha / ffcall / trampoline / protexec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  3.6 KB  |  153 lines

  1. /* This file is derived from gcc-2.6.3/libgcc2.c, section L_trampoline */
  2.  
  3. /* Copyright (C) 1989, 1992, 1993, 1994 Free Software Foundation, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* Jump to a trampoline, loading the static chain address.  */
  23.  
  24. #if defined (__alpha__)
  25.  
  26. void
  27. __enable_execute_stack (addr)
  28.      void *addr;
  29. {
  30.   long size = getpagesize ();
  31.   long mask = ~(size-1);
  32.   char *page = (char *) (((long) addr) & mask);
  33.   char *end  = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size);
  34.  
  35.   /* 7 is PROT_READ | PROT_WRITE | PROT_EXEC */
  36.   if (mprotect (page, end - page, 7) < 0)
  37.     perror ("mprotect of trampoline code");
  38. }
  39.  
  40. #endif
  41.  
  42. #if defined (NeXT) && defined (__MACH__)
  43.  
  44. /* Make stack executable so we can call trampolines on stack.
  45.    This is called from INITIALIZE_TRAMPOLINE in next.h.  */
  46. #ifdef NeXTStep21
  47.  #include <mach.h>
  48. #else
  49.  #include <mach/mach.h>
  50. #endif
  51.  
  52. void
  53. __enable_execute_stack (addr)
  54.      char *addr;
  55. {
  56.   kern_return_t r;
  57.   char *eaddr = addr + TRAMPOLINE_SIZE;
  58.   vm_address_t a = (vm_address_t) addr;
  59.  
  60.   /* turn on execute access on stack */
  61.   r = vm_protect (task_self (), a, TRAMPOLINE_SIZE, FALSE, VM_PROT_ALL);
  62.   if (r != KERN_SUCCESS)
  63.     {
  64.       mach_error("vm_protect VM_PROT_ALL", r);
  65.       exit(1);
  66.     }
  67.  
  68. #endif /* defined (NeXT) && defined (__MACH__) */
  69.  
  70. #ifdef __convex__
  71.  
  72. /* Make stack executable so we can call trampolines on stack.
  73.    This is called from INITIALIZE_TRAMPOLINE in convex.h.  */
  74.  
  75. #include <sys/mman.h>
  76. #include <sys/vmparam.h>
  77. #include <machine/machparam.h>
  78.  
  79. void
  80. __enable_execute_stack ()
  81. {
  82.   int fp;
  83.   static unsigned lowest = USRSTACK;
  84.   unsigned current = (unsigned) &fp & -NBPG;
  85.  
  86.   if (lowest > current)
  87.     {
  88.       unsigned len = lowest - current;
  89.       mremap (current, &len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
  90.       lowest = current;
  91.     }
  92. }
  93. #endif /* __convex__ */
  94.  
  95. #ifdef __DOLPHIN__
  96.  
  97. /* Modified from the convex -code above. */
  98.  
  99. #include <sys/param.h>
  100. #include <errno.h>
  101. #include <sys/m88kbcs.h>
  102.  
  103. void
  104. __enable_execute_stack ()
  105. {
  106.   int save_errno;
  107.   static unsigned long lowest = USRSTACK;
  108.   unsigned long current = (unsigned long) &save_errno & -NBPC;
  109.   
  110.   /* Ignore errno being set. memctl sets errno to EINVAL whenever the
  111.      address is seen as 'negative'. That is the case with the stack.   */
  112.  
  113.   save_errno=errno;
  114.   if (lowest > current)
  115.     {
  116.       unsigned len=lowest-current;
  117.       memctl(current,len,MCT_TEXT);
  118.       lowest = current;
  119.     }
  120.   else
  121.     memctl(current,NBPC,MCT_TEXT);
  122.   errno=save_errno;
  123. }
  124.  
  125. #endif /* __DOLPHIN__ */
  126.  
  127. #ifdef __pyr__
  128.  
  129. #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch.  */
  130. #include <stdio.h>
  131. #include <sys/mman.h>
  132. #include <sys/types.h>
  133. #include <sys/param.h>
  134. #include <sys/vmmac.h>
  135.  
  136. /* Modified from the convex -code above.
  137.    mremap promises to clear the i-cache. */
  138.  
  139. void
  140. __enable_execute_stack ()
  141. {
  142.   int fp;
  143.   if (mprotect (((unsigned int)&fp/PAGSIZ)*PAGSIZ, PAGSIZ,
  144.         PROT_READ|PROT_WRITE|PROT_EXEC))
  145.     {
  146.       perror ("mprotect in __enable_execute_stack");
  147.       fflush (stderr);
  148.       abort ();
  149.     }
  150. }
  151. #endif /* __pyr__ */
  152.