[Git][cmucl/cmucl][master] 56 commits: Let the OS mmap the binding and control stacks wherever.

Raymond Toy rtoy at common-lisp.net
Sat May 21 17:39:17 UTC 2016


Raymond Toy pushed to branch master at cmucl / cmucl


Commits:
3ee55ba5 by Raymond Toy at 2015-09-28T15:17:37-07:00
Let the OS mmap the binding and control stacks wherever.

- - - - -
586ca74d by Raymond Toy at 2015-10-02T18:50:45-07:00
Merge branch 'master' into rtoy-mmap-anon-control-and-binding-stacks

- - - - -
1869d093 by Raymond Toy at 2015-10-03T07:55:34-07:00
Updates to handle random stack locations better.

* Print out some better messages from os_protect
* Add make_hole to actually make a hole
* make_holes only does the read-only and static spaces.
* make_stack_holes handles the binding and control stacks.

- - - - -
4b838e3f by Raymond Toy at 2015-10-03T07:56:07-07:00
Make holes in the stacks, as before.

- - - - -
67befdb5 by Raymond Toy at 2015-10-03T13:55:50-07:00
Fix typo: index -> k.

- - - - -
1aa6477b by Raymond Toy at 2015-10-03T13:56:20-07:00
The start of the control stack is control_stack, not
control_stack_start.

- - - - -
65b5ed77 by Raymond Toy at 2015-10-03T13:56:47-07:00
The start of the control stack is control_stack, not
control_stack_start.

- - - - -
57a7df13 by Raymond Toy at 2015-10-03T14:10:24-07:00
Replace CONTROL_STACK_START with control_stack.

Cast to appropriate pointer types too.

- - - - -
e0ae3367 by Raymond Toy at 2015-10-03T14:11:08-07:00
Replace CONTROL_STACK_START with control_stack and BINDING_STACK_START
with binding_stack.

- - - - -
748991e2 by Raymond Toy at 2015-10-03T14:11:33-07:00
Cast os_validate to the appropriate type to get rid of warning.

- - - - -
e4897224 by Raymond Toy at 2015-10-03T14:11:43-07:00
Declare validate_stacks().

- - - - -
bcb73a5e by Raymond Toy at 2015-10-03T14:26:17-07:00
Simplify make_hole:  just pass in address and size.

- - - - -
32ae8b14 by Raymond Toy at 2015-10-03T14:30:14-07:00
Fix silly typos.

- - - - -
cf1990dc by Raymond Toy at 2015-10-04T12:42:34-07:00
Don't define a SIGNAL_STACK mapped region.  Use altstack, like on
other platforms.

- - - - -
b2dc0b2c by Raymond Toy at 2015-10-04T12:42:55-07:00
Don't define a SIGNAL_STACK mapped region.  Use altstack, like on
other platforms.

- - - - -
316d2279 by Raymond Toy at 2015-10-04T12:43:26-07:00
Use control_stack, not CONTROL_STACK_START.

- - - - -
bdb299d3 by Raymond Toy at 2015-10-04T12:44:04-07:00
Put -O2 on it's own line to make switching this off and on slightly
easier.

- - - - -
9de8cd88 by Raymond Toy at 2015-10-04T12:47:42-07:00
Remove definitions of BINDING_STACK_START and CONTROL_STACK_START.

- - - - -
e4553e8a by Raymond Toy at 2015-10-04T12:54:25-07:00
Replace BINDING_STACK_START and CONTROL_STACK_START appropriately.

- - - - -
ec4c78fb by Raymond Toy at 2015-10-04T12:58:54-07:00
Define SIGNAL_STACK_SIZE

- - - - -
0e258fd9 by Raymond Toy at 2015-10-04T15:05:08-07:00
Rename local control_stack_size to current_stack_size to prevent
confusion with the global control_stack_size.

- - - - -
1d8db41a by Raymond Toy at 2015-10-04T15:05:22-07:00
Replace BINDING_STACK_START and CONTROL_STACK_START appropriately.

- - - - -
43e24775 by Raymond Toy at 2015-10-11T15:38:24-07:00
Support asdf's static-image-op.

* src/lisp/GNUMakefile
    * Don't add exec-final.o to lisp.a.  (But still remove exec-init.o
      from it.)
* src/tools/linker.sh
    * When linking the executable, need to link exec-final.o too.
* bin/make-main-dist.sh
    * Need to install exec-init.o and exec-final.o.  exec-init.o is
      needed to link a normal lisp; exec-final.o is used for the
      executable image.
    * Fix modes on some installed files.  exec-init.o, exec-final.o,
      and lisp.a don't need to be executable.

- - - - -
c49d87c7 by Raymond Toy at 2015-10-11T15:38:24-07:00
Exit with the return code from obj_run_linker.

obj_run_linker() returns the return code from the call to system().
Exit lisp with this return code to indicate if running the executable
linker script worked or not.

- - - - -
c614c412 by Raymond Toy at 2015-10-11T15:38:24-07:00
Include the exit code when printing the process structure.

It's really nice to see the exit code of the process when printing out
the process structure.

Fix a typo too: "tings" -> "things".

- - - - -
7c199b29 by Raymond Toy at 2015-10-11T15:38:24-07:00
Use correct path for git clone.

Noticed by Joram Schrijver who gave the correct path.

- - - - -
776f7f63 by Raymond Toy at 2015-10-11T15:38:24-07:00
Use PRINT-UNREADABLE-OBJECT to print the process structure.

- - - - -
c415308a by Raymond Toy at 2015-10-11T15:38:24-07:00
Give hint on what the last value of the printed process is

Left this out in the previous commit.

- - - - -
3e5e8ebb by Raymond Toy at 2015-10-11T15:38:24-07:00
Remove -mmacosx-version-min=10.5

When making an executable on some random machine, we can't depend on
the user having the 10.5 SDK around.  So remove the flag, but add
-Wl,-no_pie to suppress the warning about PIE disabled due to absolute
addressing.

- - - - -
1a3f83f6 by Raymond Toy at 2015-10-11T15:38:24-07:00
Update version so bootfiles are loaded from the dir

- - - - -
de896d6e by Raymond Toy at 2015-10-11T15:38:24-07:00
Add new release notes file for 21b.

- - - - -
46d1d014 by Raymond Toy at 2015-10-11T15:38:24-07:00
Add some comments.

MIN_VER requires the 10.5 SDK be available.
Add -Wl,-no_pie to turn off warning (and add comment).

- - - - -
16fbb323 by Raymond Toy at 2015-10-11T15:38:24-07:00
Cleanup.

Remove old comment, and remove the min OSX version on ppc too.

- - - - -
00bb8d4e by Raymond Toy at 2015-10-11T15:38:24-07:00
Disassemble BREAK inst as INT3.

The break inst is really the int3 instruction, so disassemble it as
int3.

- - - - -
33cb8d6c by Raymond Toy at 2015-10-11T15:38:24-07:00
Change disassembly to use .byte and .word instead of byte and word
when printing random bytes and words.

- - - - -
5a413e60 by Raymond Toy at 2015-10-11T16:00:39-07:00
Support stacks at fixed addresses as before.

If CONTROL_STACK_START or BINDING_STACK_START are defined, we take
that as a hint that the system wants the stacks mapped at fixed
addresses.  Otherwise, the stacks are mapped wherever there's room.

- - - - -
a97bcea0 by Raymond Toy at 2015-10-18T22:12:48-07:00
Fix for NetBSD:  Use control_stack/binding_stack instead of
CONTROL_STACK_START and BINDING_STACK_START.

>From Robert Swindells.

- - - - -
20f530c4 by Raymond Toy at 2015-10-19T21:13:12-07:00
Fix for FreeBSD:  Use control_stack/binding_stack instead of
CONTROL_STACK_START and BINDING_STACK_START.

Fred Gilham says the same fix is needed for FreeBSD as for NetBSD.

- - - - -
138310f9 by Raymond Toy at 2015-10-31T20:41:30-07:00
Merge branch 'master' into rtoy-mmap-anon-control-and-binding-stacks

Conflicts:
	bin/make-main-dist.sh
	src/general-info/release-21b.txt

- - - - -
694331c1 by Raymond Toy at 2015-11-04T19:42:41-08:00
Fix merge mistake:  Don't print break as int3.

- - - - -
0fb5c699 by Raymond Toy at 2015-11-04T19:44:58-08:00
Define CONTROL_STACK_START and BINDING_STACK_START.

ppc currently only supports allocating the control stack and binding
stack at fixed addresses.  (This used to work, but something broke it
recently.  Until the ppc machine comes back, we're going to disable
that feature there.)

- - - - -
70f15c09 by Raymond Toy at 2015-11-04T19:49:31-08:00
Remove some unused code.

- - - - -
275011da by Raymond Toy at 2015-12-13T21:35:03-08:00
Merge branch 'master' into rtoy-mmap-anon-control-and-binding-stacks

- - - - -
583140fc by Raymond Toy at 2016-05-08T09:11:48-07:00
Merge branch 'master' into rtoy-mmap-anon-control-and-binding-stacks

- - - - -
951611cf by Raymond Toy at 2016-05-09T21:02:47-07:00
Add RELOCATABLE_STACK_START to control stack spaces

When RELOCATABLE_STACK_START is defined, the control stack, binding
stack, and sigalt stack are located wherever mmap finds room for them.

Currently only implemented for Darwin, but should work for linux and
solaris.  We enable this by default on Darwin now.

- - - - -
603fb6a0 by Raymond Toy at 2016-05-10T19:13:32-07:00
Add RELOCATABLE_STACK_START to control stack spaces for linux.

When RELOCATABLE_STACK_START is defined, the control stack, binding
stack, and sigalt stack are located wherever mmap finds room for them.

- - - - -
8b1ba846 by Raymond Toy at 2016-05-10T19:32:43-07:00
Fix typo.

We want #ifndef, not #ifdef to enable the relocatable stacks.

- - - - -
75d4ea45 by Raymond Toy at 2016-05-10T20:04:58-07:00
Add RELOCATABLE_STACK_START to control stack spaces for solaris/sparc..

When RELOCATABLE_STACK_START is defined, the control stack, binding
stack, and sigalt stack are located wherever mmap finds room for them.

Only implemented with sparc_sunc config.

- - - - -
a6339d00 by Raymond Toy at 2016-05-10T21:33:43-07:00
Remove #if 0 code.

- - - - -
67f59a2d by Raymond Toy at 2016-05-10T21:33:57-07:00
Add some comments.

- - - - -
38fdea64 by Raymond Toy at 2016-05-10T21:34:14-07:00
Fix indentation, add some comments.

- - - - -
f81b1ed0 by Raymond Toy at 2016-05-11T19:19:00-07:00
Add comments.

- - - - -
c15a3f70 by Raymond Toy at 2016-05-11T19:20:40-07:00
Fix up to preserve old behavior without RELOCATABLE_STACK_START.

- - - - -
e9838801 by Raymond Toy at 2016-05-11T19:28:39-07:00
Fix compiler warnings.

- - - - -
f75df562 by Raymond Toy at 2016-05-11T19:30:48-07:00
Fix compiler warnings.

- - - - -
040fbc1d by Raymond Toy at 2016-05-21T17:39:06+00:00
Merge branch 'rtoy-mmap-anon-control-and-binding-stacks' into 'master'

Map control and binding stacks wherever the OS wants to put them.



See merge request !3
- - - - -


23 changed files:

- src/lisp/Config.sparc_sunc
- src/lisp/Config.x86_common
- src/lisp/Config.x86_darwin
- src/lisp/Config.x86_linux
- src/lisp/Darwin-os.c
- src/lisp/FreeBSD-os.c
- src/lisp/Linux-os.c
- src/lisp/NetBSD-os.c
- src/lisp/backtrace.c
- src/lisp/gencgc.c
- src/lisp/globals.c
- src/lisp/interrupt.c
- src/lisp/lisp.c
- src/lisp/os-common.c
- src/lisp/ppc-validate.h
- src/lisp/save.c
- src/lisp/solaris-os.c
- src/lisp/sparc-validate.h
- src/lisp/validate.c
- src/lisp/validate.h
- src/lisp/x86-assem.S
- src/lisp/x86-validate-darwin.h
- src/lisp/x86-validate-linux.h


Changes:

=====================================
src/lisp/Config.sparc_sunc
=====================================
--- a/src/lisp/Config.sparc_sunc
+++ b/src/lisp/Config.sparc_sunc
@@ -24,7 +24,7 @@ CC_V8PLUS = -m32 -xarch=sparc
 AS_V8PLUS = -m32 -xarch=sparc
 endif
 
-CFLAGS += -xlibmieee -O
+CFLAGS += -xlibmieee -O -DRELOCATABLE_STACK_START
 DEPEND_FLAGS = -xM
 ASFLAGS = $(AS_V8PLUS)
 OS_LINK_FLAGS = -M /usr/lib/ld/map.noexstk


=====================================
src/lisp/Config.x86_common
=====================================
--- a/src/lisp/Config.x86_common
+++ b/src/lisp/Config.x86_common
@@ -43,7 +43,8 @@ CPP_INCLUDE_OPTIONS := -I. -I$(PATH1) -I-
 endif
 
 CPPFLAGS := $(CPP_DEFINE_OPTIONS) $(CPP_INCLUDE_OPTIONS) 
-CFLAGS += -Wstrict-prototypes -Wall -O2 -g -fno-omit-frame-pointer
+CFLAGS += -Wstrict-prototypes -Wall -g -fno-omit-frame-pointer
+CFLAGS += -O2
 ASFLAGS = -g 
 
 ASSEM_SRC = x86-assem.S


=====================================
src/lisp/Config.x86_darwin
=====================================
--- a/src/lisp/Config.x86_darwin
+++ b/src/lisp/Config.x86_darwin
@@ -6,7 +6,7 @@ include Config.x86_common
 # you have the 10.5 SDK available.
 MIN_VER = -mmacosx-version-min=10.5
 
-CPPFLAGS += -DDARWIN $(MIN_VER) -m32
+CPPFLAGS += -DDARWIN $(MIN_VER) -m32 -DRELOCATABLE_STACK_START
 CFLAGS += -g3 -mtune=generic
 ASFLAGS += -g3 $(MIN_VER)
 


=====================================
src/lisp/Config.x86_linux
=====================================
--- a/src/lisp/Config.x86_linux
+++ b/src/lisp/Config.x86_linux
@@ -1,7 +1,7 @@
 # -*- Mode: makefile -*-
 include Config.x86_common
 
-CPPFLAGS += -m32 -D__NO_CTYPE -D_GNU_SOURCE
+CPPFLAGS += -m32 -D__NO_CTYPE -D_GNU_SOURCE -DRELOCATABLE_STACK_START
 CFLAGS += -rdynamic  -march=pentium4 -mfpmath=sse -mtune=generic
 
 UNDEFSYMPATTERN = -Xlinker -u -Xlinker &


=====================================
src/lisp/Darwin-os.c
=====================================
--- a/src/lisp/Darwin-os.c
+++ b/src/lisp/Darwin-os.c
@@ -464,8 +464,8 @@ valid_addr(os_vm_address_t addr)
 #ifndef GENCGC
 	|| in_range_p(addr, DYNAMIC_1_SPACE_START, dynamic_space_size)
 #endif
-	|| in_range_p(addr, CONTROL_STACK_START, control_stack_size)
-	|| in_range_p(addr, BINDING_STACK_START, binding_stack_size))
+	|| in_range_p(addr, (lispobj)control_stack, control_stack_size)
+	|| in_range_p(addr, (lispobj)binding_stack, binding_stack_size))
 	return TRUE;
     return FALSE;
 }


=====================================
src/lisp/FreeBSD-os.c
=====================================
--- a/src/lisp/FreeBSD-os.c
+++ b/src/lisp/FreeBSD-os.c
@@ -224,8 +224,8 @@ valid_addr(os_vm_address_t addr)
 #ifndef GENCGC
 	|| in_range_p(addr, DYNAMIC_1_SPACE_START, dynamic_space_size)
 #endif
-	|| in_range_p(addr, CONTROL_STACK_START, control_stack_size)
-	|| in_range_p(addr, BINDING_STACK_START, binding_stack_size))
+	|| in_range_p(addr, control_stack, control_stack_size)
+	|| in_range_p(addr, binding_stack, binding_stack_size))
 	return TRUE;
     return FALSE;
 }


=====================================
src/lisp/Linux-os.c
=====================================
--- a/src/lisp/Linux-os.c
+++ b/src/lisp/Linux-os.c
@@ -385,8 +385,8 @@ valid_addr(os_vm_address_t addr)
 	|| in_range_p(addr, STATIC_SPACE_START, static_space_size)
 	|| in_range_p(addr, DYNAMIC_0_SPACE_START, dynamic_space_size)
 	|| in_range_p(addr, DYNAMIC_1_SPACE_START, dynamic_space_size)
-	|| in_range_p(addr, CONTROL_STACK_START, control_stack_size)
-	|| in_range_p(addr, BINDING_STACK_START, binding_stack_size))
+	|| in_range_p(addr, control_stack, control_stack_size)
+	|| in_range_p(addr, binding_stack, binding_stack_size))
 	return TRUE;
     return FALSE;
 }
@@ -454,17 +454,17 @@ sigsegv_handler(HANDLER_ARGS)
 #ifdef i386
     interrupt_handle_now(signal, contextstruct);
 #else
-#define CONTROL_STACK_TOP (((char*) CONTROL_STACK_START) + control_stack_size)
+#define CONTROL_STACK_TOP (((char*) control_stack) + control_stack_size)
 
     addr = arch_get_bad_addr(signal, code, context);
 
     if (addr != NULL && context->sc_regs[reg_ALLOC] & (1 << 63)) {
 	context->sc_regs[reg_ALLOC] -= (1 << 63);
 	interrupt_handle_pending(context);
-    } else if (addr > CONTROL_STACK_TOP && addr < BINDING_STACK_START) {
+    } else if (addr > CONTROL_STACK_TOP && addr < (os_vm_address_t)binding_stack) {
 	fprintf(stderr, "Possible stack overflow at 0x%08lX!\n", addr);
 	/* try to fix control frame pointer */
-	while (!(CONTROL_STACK_START <= *current_control_frame_pointer &&
+	while (!((lispobj)control_stack <= *current_control_frame_pointer &&
 		 *current_control_frame_pointer <= CONTROL_STACK_TOP))
 	    ((char *) current_control_frame_pointer) -= sizeof(lispobj);
 	ldb_monitor();


=====================================
src/lisp/NetBSD-os.c
=====================================
--- a/src/lisp/NetBSD-os.c
+++ b/src/lisp/NetBSD-os.c
@@ -277,8 +277,8 @@ valid_addr(os_vm_address_t addr)
 #ifndef GENCGC
 	|| in_range_p(addr, DYNAMIC_1_SPACE_START, dynamic_space_size)
 #endif
-	|| in_range_p(addr, CONTROL_STACK_START, control_stack_size)
-	|| in_range_p(addr, BINDING_STACK_START, binding_stack_size))
+	|| in_range_p(addr, control_stack, control_stack_size)
+	|| in_range_p(addr, binding_stack, binding_stack_size))
 	return TRUE;
     return FALSE;
 }


=====================================
src/lisp/backtrace.c
=====================================
--- a/src/lisp/backtrace.c
+++ b/src/lisp/backtrace.c
@@ -252,7 +252,7 @@ backtrace(int nframes)
 static int
 stack_pointer_p(unsigned long p)
 {
-    return (p < CONTROL_STACK_START + control_stack_size
+    return ((void *)p < (void *)control_stack + control_stack_size
 	    && p > (unsigned long) &p && (p & 3) == 0);
 }
 


=====================================
src/lisp/gencgc.c
=====================================
--- a/src/lisp/gencgc.c
+++ b/src/lisp/gencgc.c
@@ -166,7 +166,7 @@ check_escaped_stack_object(lispobj * where, lispobj obj)
 
     if (Pointerp(obj)
 	&& (p = (void *) PTR(obj),
-	    (p >= (void *) CONTROL_STACK_START
+	    (p >= (void *) control_stack
 	     && p < (void *) control_stack_end))) {
 	char *space;
 
@@ -195,7 +195,7 @@ check_escaped_stack_object(lispobj * where, lispobj obj)
 	    lose("Escaped stack-allocated object 0x%08lx at %p in %s\n",
 		 (unsigned long) obj, where, space);
 #ifndef i386
-	else if ((where >= (lispobj *) CONTROL_STACK_START
+	else if ((where >= (lispobj *) control_stack
 		  && where < (lispobj *) (control_stack_end))
 		 || (space == NULL)) {
 	    /* Do nothing if it the reference is from the control stack,
@@ -2136,17 +2136,19 @@ read_only_space_p(lispobj obj)
 static inline boolean
 control_stack_space_p(lispobj obj)
 {
-    lispobj end = CONTROL_STACK_START + control_stack_size;
+    char *object = (char *) obj;
+    char *end = (char *)control_stack + control_stack_size;
 
-    return (obj >= CONTROL_STACK_START) && (obj < end);
+    return (object >= (char *) control_stack) && (object < end);
 }
 
 static inline boolean
 binding_stack_space_p(lispobj obj)
 {
-    lispobj end = BINDING_STACK_START + binding_stack_size;
+    char *object = (char *) obj;
+    char *end = (char *)binding_stack + binding_stack_size;
 
-    return (obj >= BINDING_STACK_START) && (obj < end);
+    return (object >= (char *) binding_stack) && (object < end);
 }
     
 static inline boolean
@@ -2157,7 +2159,12 @@ signal_space_p(lispobj obj)
 
     return (obj >= SIGNAL_STACK_START) && (obj < end);
 #else
-    return FALSE;
+    extern char altstack[];
+    
+    char* object = (char*) obj;
+    char* end = altstack + SIGNAL_STACK_SIZE;
+    
+    return (object >= altstack && object < end);
 #endif    
 }
 
@@ -7322,11 +7329,11 @@ verify_gc(void)
     int static_space_size = (lispobj *) SymbolValue(STATIC_SPACE_FREE_POINTER)
 	- (lispobj *) static_space;
     int binding_stack_size = (lispobj *) get_binding_stack_pointer()
-	- (lispobj *) BINDING_STACK_START;
+	- (lispobj *) binding_stack;
 
     verify_space((lispobj *) READ_ONLY_SPACE_START, read_only_space_size);
     verify_space((lispobj *) static_space, static_space_size);
-    verify_space((lispobj *) BINDING_STACK_START, binding_stack_size);
+    verify_space((lispobj *) binding_stack, binding_stack_size);
     verify_space((lispobj *) (void *) &scavenger_hooks, 1);
 }
 
@@ -7494,16 +7501,16 @@ scavenge_interrupt_handlers(void)
 static void
 scavenge_control_stack(void)
 {
-    unsigned long control_stack_size;
+    unsigned long current_stack_size;
 
-    control_stack_size = current_control_stack_pointer - control_stack;
+    current_stack_size = current_control_stack_pointer - control_stack;
 
 #ifdef PRINTNOISE
     printf("Scavenging the control stack (%d bytes) ...\n",
-	   control_stack_size * sizeof(lispobj));
+	   current_stack_size * sizeof(lispobj));
 #endif
 
-    scavenge(control_stack, control_stack_size);
+    scavenge(control_stack, current_stack_size);
 
 #ifdef PRINTNOISE
     printf("Done scavenging the control stack.\n");
@@ -7523,7 +7530,7 @@ garbage_collect_generation(int generation, int raise)
 
 #ifdef GC_ASSERTIONS
 #if defined(i386) || defined(__x86_64)
-    invalid_stack_start = (void *) CONTROL_STACK_START;
+    invalid_stack_start = (void *) control_stack;
     invalid_stack_end = (void *) &raise;
 #else /* not i386 */
     invalid_stack_start = (void *) &raise;


=====================================
src/lisp/globals.c
=====================================
--- a/src/lisp/globals.c
+++ b/src/lisp/globals.c
@@ -28,7 +28,6 @@ lispobj *dynamic_1_space;
 unsigned dynamic_space_size;
 lispobj *control_stack;
 
-
 #if (defined(i386) || defined(__x86_64))
 lispobj *control_stack_end;
 #endif


=====================================
src/lisp/interrupt.c
=====================================
--- a/src/lisp/interrupt.c
+++ b/src/lisp/interrupt.c
@@ -405,10 +405,7 @@ interrupt_maybe_gc(HANDLER_ARGS)
 * Noise to install handlers.                                     *
 \****************************************************************/
 
-#if !(defined(i386) || defined(__x86_64))
-#define SIGNAL_STACK_SIZE SIGSTKSZ
-static char altstack[SIGNAL_STACK_SIZE];
-#endif
+char altstack[SIGNAL_STACK_SIZE];
 
 void
 interrupt_install_low_level_handler(int signal, void handler(HANDLER_ARGS))
@@ -431,7 +428,7 @@ interrupt_install_low_level_handler(int signal, void handler(HANDLER_ARGS))
     if (signal == PROTECTION_VIOLATION_SIGNAL) {
 	stack_t sigstack;
 
-#if (defined( i386 ) || defined(__x86_64))
+#if defined(SIGNAL_STACK_START)
 	sigstack.ss_sp = (void *) SIGNAL_STACK_START;
 #else
 	sigstack.ss_sp = (void *) altstack;


=====================================
src/lisp/lisp.c
=====================================
--- a/src/lisp/lisp.c
+++ b/src/lisp/lisp.c
@@ -687,8 +687,16 @@ main(int argc, const char *argv[], const char *envp[])
     if (builtin_image_flag != 0)
 	map_core_sections(argv[0]);
 #endif
+
+    /*
+     * Validate the basic lisp spaces first like the heap and static
+     * and read-only spaces.  Do this so that the stacks (if thy're
+     * relocatable) don't get randomly allocated on top of our desired
+     * lisp spaces.
+     */
     validate();
     gc_init();
+    validate_stacks();
 
     /* This is the first use of malloc() and must come after the
      * static memory layout is mmapped to avoid conflicts with possible


=====================================
src/lisp/os-common.c
=====================================
--- a/src/lisp/os-common.c
+++ b/src/lisp/os-common.c
@@ -413,7 +413,7 @@ guard_zones(char **yellow_start, char **red_start)
     /*
      * All x86's have a control stack (aka C stack) that grows down.
      */
-    char *end = (char *) CONTROL_STACK_START;
+    char *end = (char *) control_stack;
 
     *red_start = end;
     *yellow_start = *red_start + RED_ZONE_SIZE;
@@ -424,7 +424,7 @@ guard_zones(char **yellow_start, char **red_start)
      * control stack area.
      */
 
-    char *end = (char *) CONTROL_STACK_START + control_stack_size;
+    char *end = (char *) control_stack + control_stack_size;
 
     *red_start = end - RED_ZONE_SIZE;
     *yellow_start = *red_start - YELLOW_ZONE_SIZE;


=====================================
src/lisp/ppc-validate.h
=====================================
--- a/src/lisp/ppc-validate.h
+++ b/src/lisp/ppc-validate.h
@@ -45,6 +45,8 @@
 #define CONTROL_STACK_SIZE  	(0x07ff8000)	/* 128 MB, almost */
 #define CONTROL_STACK_END       (CONTROL_STACK_START + control_stack_size)
 
+#define SIGNAL_STACK_SIZE	SIGSTKSZ
+
 #define BINDING_STACK_START 	(0x38000000)
 #define BINDING_STACK_SIZE  	(0x07ff8000)	/* 128 MB, almost */
 


=====================================
src/lisp/save.c
=====================================
--- a/src/lisp/save.c
+++ b/src/lisp/save.c
@@ -136,7 +136,9 @@ save(char *filename, lispobj init_function, int sse2_mode)
     }
     printf("[Undoing binding stack... ");
     fflush(stdout);
-    unbind_to_here((lispobj *) BINDING_STACK_START);
+
+    unbind_to_here((lispobj *) binding_stack);
+
     SetSymbolValue(CURRENT_CATCH_BLOCK, 0);
     SetSymbolValue(CURRENT_UNWIND_PROTECT_BLOCK, 0);
     SetSymbolValue(EVAL_STACK_TOP, 0);
@@ -278,7 +280,9 @@ save_executable(char *filename, lispobj init_function)
 
     printf("[Undoing binding stack... ");
     fflush(stdout);
-    unbind_to_here((lispobj *)BINDING_STACK_START);
+
+    unbind_to_here((lispobj *)binding_stack);
+
     SetSymbolValue(CURRENT_CATCH_BLOCK, 0);
     SetSymbolValue(CURRENT_UNWIND_PROTECT_BLOCK, 0);
     SetSymbolValue(EVAL_STACK_TOP, 0);


=====================================
src/lisp/solaris-os.c
=====================================
--- a/src/lisp/solaris-os.c
+++ b/src/lisp/solaris-os.c
@@ -169,8 +169,14 @@ os_flush_icache(os_vm_address_t address, os_vm_size_t length)
 void
 os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot)
 {
-    if (mprotect((void *) address, length, prot) == -1)
-	perror("mprotect");
+    if (mprotect((void *) address, length, prot) == -1) {
+        char msg[1000];
+
+        snprintf(msg, sizeof(msg), "mprotect: os_protect(0x%p, %u, 0x%x): ",
+                 address, length, prot);
+        
+	perror(msg);
+    }
 }
 
 static boolean
@@ -193,8 +199,8 @@ boolean valid_addr(os_vm_address_t addr)
 #ifndef GENCGC
 	    || in_range_p(addr, DYNAMIC_1_SPACE_START, dynamic_space_size)
 #endif
-	    || in_range_p(addr, CONTROL_STACK_START, control_stack_size)
-	    || in_range_p(addr, BINDING_STACK_START, binding_stack_size));
+	    || in_range_p(addr, (lispobj)control_stack, control_stack_size)
+	    || in_range_p(addr, (lispobj)binding_stack, binding_stack_size));
 }
 
 /* ---------------------------------------------------------------- */
@@ -403,11 +409,16 @@ os_vm_address_t round_up_sparse_size(os_vm_address_t addr)
 /*
  * An array of the start of the spaces which should have holes placed
  * after them.  Must not include the dynamic spaces because the size
- * of the dynamic space can be controlled from the command line.
+ * of the dynamic space can be controlled from the command line.  Also
+ * must not include the binding and control stacks.  They're handled
+ * below.
  */
 static os_vm_address_t spaces[] = {
     READ_ONLY_SPACE_START, STATIC_SPACE_START,
-    BINDING_STACK_START, CONTROL_STACK_START
+#ifndef RELOCATABLE_STACK_START
+    BINDING_STACK_START,
+    CONTROL_STACK_START
+#endif    
 };
 
 /*
@@ -430,27 +441,41 @@ static unsigned long *space_size[] = {
 #define HOLE_SIZE 0x2000
 
 void
-make_holes(void)
+make_hole(os_vm_address_t space_start, size_t space_size)
 {
-    int k;
     os_vm_address_t hole;
 
     /* Make holes of the appropriate size for desired spaces */
 
-    for (k = 0; k < sizeof(spaces) / sizeof(spaces[0]); ++k) {
-
-	hole = spaces[k] + *space_size[k];
+    hole = space_start + space_size;
 
-	if (os_validate(hole, HOLE_SIZE) == NULL) {
-	    fprintf(stderr,
-		    "ensure_space: Failed to validate hole of %d bytes at 0x%08lX\n",
-		    HOLE_SIZE, (unsigned long) hole);
-	    exit(1);
-	}
-	/* Make it inaccessible */
-	os_protect(hole, HOLE_SIZE, 0);
+    if (os_validate(hole, HOLE_SIZE) == NULL) {
+        fprintf(stderr,
+                "ensure_space: Failed to validate hole of %d bytes at 0x%08lX\n",
+                HOLE_SIZE, (unsigned long) hole);
+        exit(1);
     }
+    /* Make it inaccessible */
+    os_protect(hole, HOLE_SIZE, 0);
+}
+
+void
+make_holes(void)
+{
+    int k;
+    os_vm_address_t hole;
+
+    /*
+     * Make holes of the appropriate size for desired spaces.  The
+     * stacks are handled in make_stack_holes, if they are
+     * relocatable.
+     */
 
+    for (k = 0; k < sizeof(spaces) / sizeof(spaces[0]); ++k) {
+        make_hole(spaces[k], *space_size[k]);
+    }
+    
+    
     /* Round up the dynamic_space_size to the nearest SPARSE_BLOCK_SIZE */
     dynamic_space_size = round_up_sparse_size(dynamic_space_size);
 
@@ -477,6 +502,15 @@ make_holes(void)
 #endif
 }
 
+void
+make_stack_holes(void)
+{
+#ifdef RELOCATABLE_STACK_START
+    make_hole((os_vm_address_t)control_stack, control_stack_size);
+    make_hole((os_vm_address_t)binding_stack, binding_stack_size);
+#endif
+}
+    
 void *
 os_dlsym(const char *sym_name, lispobj lib_list)
 {


=====================================
src/lisp/sparc-validate.h
=====================================
--- a/src/lisp/sparc-validate.h
+++ b/src/lisp/sparc-validate.h
@@ -92,15 +92,24 @@
 #define READ_ONLY_SPACE_START	(SpaceStart_TargetReadOnly)
 #define READ_ONLY_SPACE_SIZE	((2*MB_128) - SPARSE_BLOCK_SIZE)	/* 256 MB - 32 KB, 256 MB max */
 
+#ifndef RELOCATABLE_STACK_START
 #define BINDING_STACK_START 	(0x20000000)
+#endif
+
 #define BINDING_STACK_SIZE  	(MB_128 - SPARSE_BLOCK_SIZE)	/* 128 MB - 32 KB, 128 MB max */
 
 #define STATIC_SPACE_START  	(SpaceStart_TargetStatic)
 #define STATIC_SPACE_SIZE   	((2*MB_128) - SPARSE_BLOCK_SIZE)	/* 256 MB - 32 KB, 256 MB max */
 
+#ifndef RELOCATABLE_STACK_START
 #define CONTROL_STACK_START 	(0x38000000)
+#endif
 #define CONTROL_STACK_SIZE  	(MB_128 - SPARSE_BLOCK_SIZE)	/* 128 MB - 32 KB, 128 MB max */
+#if 0
 #define CONTROL_STACK_END       (CONTROL_STACK_START + control_stack_size)
+#endif
+
+#define SIGNAL_STACK_SIZE	SIGSTKSZ
 
 #define DYNAMIC_0_SPACE_START	(SpaceStart_TargetDynamic)
 


=====================================
src/lisp/validate.c
=====================================
--- a/src/lisp/validate.c
+++ b/src/lisp/validate.c
@@ -18,6 +18,7 @@
 
 #ifdef sparc
 extern void make_holes(void);
+extern void make_stack_holes(void);
 #endif
 
 static void
@@ -92,20 +93,10 @@ validate(void)
     */
 #endif
 
-    /* Control Stack */
-    control_stack = (lispobj *) CONTROL_STACK_START;
-#if (defined(i386) || defined(__x86_64))
-    control_stack_end = (lispobj *) (CONTROL_STACK_START + control_stack_size);
-#endif
-    ensure_space(control_stack, control_stack_size);
-
 #ifdef SIGNAL_STACK_START
     ensure_space((lispobj *) SIGNAL_STACK_START, SIGNAL_STACK_SIZE);
 #endif
 
-    /* Binding Stack */
-    binding_stack = (lispobj *) BINDING_STACK_START;
-    ensure_space(binding_stack, binding_stack_size);
 #ifdef LINKAGE_TABLE
     ensure_space((lispobj *) FOREIGN_LINKAGE_SPACE_START,
 		 FOREIGN_LINKAGE_SPACE_SIZE);
@@ -118,6 +109,40 @@ validate(void)
     printf(" done.\n");
 #endif
 
+}
+
+void
+validate_stacks()
+{
+    /* Control Stack */
+#ifdef CONTROL_STACK_START
+    /* Map the control stack at a fixed location */
+    control_stack = (lispobj *) CONTROL_STACK_START;
+#if (defined(i386) || defined(__x86_64))
+    control_stack_end = (lispobj *) (CONTROL_STACK_START + control_stack_size);
+#endif
+    ensure_space(control_stack, control_stack_size);
+#else
+    /* Map the conrol stack wherever we have space */
+    control_stack = (lispobj*) os_validate(NULL, control_stack_size);
+
+#if (defined(i386) || defined(__x86_64))
+    control_stack_end = (void*)control_stack + control_stack_size;
+#endif
+#endif
+
+    /* Binding Stack */
+#ifdef BINDING_STACK_START
+    binding_stack = (lispobj *) BINDING_STACK_START;
+    ensure_space(binding_stack, binding_stack_size);
+#else
+    /* Map the binding stack wherever we have space */
+    binding_stack = (lispobj*) os_validate(NULL, binding_stack_size);
+#endif
+#ifdef sparc
+    make_stack_holes();
+#endif
+
 #ifdef RED_ZONE_HIT
     os_guard_control_stack(0, 1);
 #endif


=====================================
src/lisp/validate.h
=====================================
--- a/src/lisp/validate.h
+++ b/src/lisp/validate.h
@@ -37,5 +37,6 @@
 #endif
 
 extern void validate(void);
+extern void validate_stacks(void);
 
 #endif /* _VALIDATE_H_ */


=====================================
src/lisp/x86-assem.S
=====================================
--- a/src/lisp/x86-assem.S
+++ b/src/lisp/x86-assem.S
@@ -143,7 +143,8 @@ FUNCDEF(call_into_lisp)
 	movl	%eax, GNAME(foreign_function_call_active)
 
 	movl	%esp,%ebx	# remember current stack
-	cmpl	$CONTROL_STACK_START,%esp
+	cmpl	GNAME(control_stack), %esp
+
 	jbe	ChangeToLispStack
 	cmpl	GNAME(control_stack_end), %esp
 	jbe	OnLispStack


=====================================
src/lisp/x86-validate-darwin.h
=====================================
--- a/src/lisp/x86-validate-darwin.h
+++ b/src/lisp/x86-validate-darwin.h
@@ -18,10 +18,14 @@
 #define STATIC_SPACE_START	(SpaceStart_TargetStatic)
 #define STATIC_SPACE_SIZE	(0x0ffff000)	/* 256MB - 1 page */
 
+#ifndef RELOCATABLE_STACK_START
 #define BINDING_STACK_START	(0x38000000)
+#endif
 #define BINDING_STACK_SIZE	(0x07fff000)	/* 128MB - 1 page */
 
+#ifdef RELOCATABLE_STACK_START
 #define CONTROL_STACK_START	(0x40000000)
+#endif
 
 /*
  * According to /usr/include/sys/signal.h, MINSIGSTKSZ is 32K and
@@ -29,7 +33,9 @@
  */
 #define CONTROL_STACK_SIZE	(0x07fdf000)	/* 128MB - SIGSTKSZ - 1 page */
 
+#ifndef RELOCATABLE_STACK_START
 #define SIGNAL_STACK_START	(0x47fe0000)    /* One page past the end of the control stack */
+#endif
 #define SIGNAL_STACK_SIZE	SIGSTKSZ
 
 #define DYNAMIC_0_SPACE_START	(SpaceStart_TargetDynamic)


=====================================
src/lisp/x86-validate-linux.h
=====================================
--- a/src/lisp/x86-validate-linux.h
+++ b/src/lisp/x86-validate-linux.h
@@ -45,13 +45,19 @@
 #define STATIC_SPACE_START	(SpaceStart_TargetStatic)
 #define STATIC_SPACE_SIZE	(0x0ffff000)	/* 256MB - 1 page */
 
+#ifndef RELOCATABLE_STACK_START
 #define BINDING_STACK_START	(0x20000000)
+#endif
 #define BINDING_STACK_SIZE	(0x07fff000)	/* 128MB - 1 page */
 
+#ifndef RELOCATABLE_STACK_START
 #define CONTROL_STACK_START	0x38000000
+#endif
 #define CONTROL_STACK_SIZE	(0x07fff000 - 8192)
 
+#ifndef RELOCATABLE_STACK_START
 #define SIGNAL_STACK_START	CONTROL_STACK_END
+#endif
 #define SIGNAL_STACK_SIZE	SIGSTKSZ
 
 #define DYNAMIC_0_SPACE_START	(SpaceStart_TargetDynamic)



View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/compare/d003a22443cd8325a87817e29c9caf933488975d...040fbc1d73aef926967a0554265f40c7aaac71ad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cmucl-cvs/attachments/20160521/359b0885/attachment-0001.html>


More information about the cmucl-cvs mailing list