aboutsummaryrefslogtreecommitdiffstats
path: root/mps/code
diff options
context:
space:
mode:
authorRichard Brooksby2012-09-13 17:33:36 +0100
committerRichard Brooksby2012-09-13 17:33:36 +0100
commitf86ed754a90d464f21c685673dd0bd297f764bd7 (patch)
tree3e280d8afe927eef02206180ebbbe5db3d1cd849 /mps/code
parentcd4ece9201b1dffc3469e194740d6e3eb3f81c12 (diff)
downloademacs-f86ed754a90d464f21c685673dd0bd297f764bd7.tar.gz
emacs-f86ed754a90d464f21c685673dd0bd297f764bd7.zip
Merging recent improvements from custom/cet/main to masters, but carefully excluding inclusion of configura-specific modules in mps.c.
Copied from Perforce Change: 179473 ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code')
-rw-r--r--mps/code/commpost.nmk2
-rw-r--r--mps/code/mpmtypes.h1
-rw-r--r--mps/code/sc.h205
-rw-r--r--mps/code/ssw3i3mv.c45
-rw-r--r--mps/code/ssw3i6mv.c45
-rw-r--r--mps/code/w3i3mv.nmk2
-rw-r--r--mps/code/w3i6mv.nmk2
7 files changed, 295 insertions, 7 deletions
diff --git a/mps/code/commpost.nmk b/mps/code/commpost.nmk
index 483acb09710..15b77940b29 100644
--- a/mps/code/commpost.nmk
+++ b/mps/code/commpost.nmk
@@ -232,7 +232,7 @@ $(PFM)\$(VARIETY)\zmess.exe: $(PFM)\$(VARIETY)\zmess.obj \
232 $(TESTLIBOBJ) 232 $(TESTLIBOBJ)
233 233
234$(PFM)\$(VARIETY)\eventcnv.exe: $(PFM)\$(VARIETY)\eventcnv.obj \ 234$(PFM)\$(VARIETY)\eventcnv.exe: $(PFM)\$(VARIETY)\eventcnv.obj \
235 $(PFM)\$(VARIETY)\eventpro.obj $(MPMOBJ) $(PLINTHOBJ) 235 $(PFM)\$(VARIETY)\eventpro.obj $(PFM)\$(VARIETY)\mps.lib
236 236
237$(PFM)\$(VARIETY)\replay.exe: $(PFM)\$(VARIETY)\replay.obj \ 237$(PFM)\$(VARIETY)\replay.exe: $(PFM)\$(VARIETY)\replay.obj \
238 $(PFM)\$(VARIETY)\eventrep.obj \ 238 $(PFM)\$(VARIETY)\eventrep.obj \
diff --git a/mps/code/mpmtypes.h b/mps/code/mpmtypes.h
index 9246d10e67d..984790baf56 100644
--- a/mps/code/mpmtypes.h
+++ b/mps/code/mpmtypes.h
@@ -103,6 +103,7 @@ typedef struct PoolDebugMixinStruct *PoolDebugMixin;
103typedef struct AllocPatternStruct *AllocPattern; 103typedef struct AllocPatternStruct *AllocPattern;
104typedef struct AllocFrameStruct *AllocFrame; /* <design/alloc-frame/> */ 104typedef struct AllocFrameStruct *AllocFrame; /* <design/alloc-frame/> */
105typedef struct ReservoirStruct *Reservoir; /* <design/reservoir/> */ 105typedef struct ReservoirStruct *Reservoir; /* <design/reservoir/> */
106typedef struct StackContextStruct *StackContext;
106 107
107 108
108/* Arena*Method -- see <code/mpmst.h#ArenaClassStruct> */ 109/* Arena*Method -- see <code/mpmst.h#ArenaClassStruct> */
diff --git a/mps/code/sc.h b/mps/code/sc.h
new file mode 100644
index 00000000000..765c4ccb033
--- /dev/null
+++ b/mps/code/sc.h
@@ -0,0 +1,205 @@
1/* sc.h: STACK CONTEXT
2 *
3 * $Id$
4 * Copyright (c) 2012 Ravenbrook Limited. See end of file for license.
5 *
6 * Provides a context to hold the registers and stack pointer
7 *
8 * This file provide wrappers for using setjmp or some similar mechanism
9 * to save the current callee-saves on the stack.
10 *
11 * See http://info.ravenbrook.com/mail/2012/08/03/14-36-35/0/ and the rest of
12 * the thread for the origin of the idea.
13 *
14 * TODO: Make StackScan take a StackContext
15 */
16
17#ifndef sc_h
18#define sc_h
19
20#include "mpm.h"
21
22
23/* StackContext -- holds the registers including a stack pointer
24 *
25 * This contains the callee-save registers and the stack pointer.
26 *
27 * This is used to save the registers after or on entry to the arena so that
28 * they can be scanned.
29 */
30
31/* STACK_CONTEXT_SAVE - save the callee-saves and stack pointer
32 *
33 * This macro saves the callee-saves and stack pointer for the
34 * current function into the passed StackContext. The StackContext
35 * is no longer valid after the function returns.
36 *
37 * This needs to be a macro because the compiler may need to do
38 * setjmp magic.
39 */
40
41/* StackContextStackTop - return the stack top from the stack context.
42 *
43 * We assume the stack is full. In other words the stack top points at
44 * a word that contains a potential Ref.
45 */
46
47
48/* Mac OS X on 32-bit Intel built with Clang or GCC */
49
50#if defined(MPS_PF_XCI3LL) || defined(MPS_PF_XCI3GC)
51
52#include <setjmp.h>
53
54typedef struct StackContextStruct {
55 jmp_buf jumpBuffer;
56} StackContextStruct;
57
58/* See the implementation of _setjmp in
59 * <http://www.opensource.apple.com/source/Libc/Libc-825.24/i386/sys/_setjmp.s> */
60
61#define JB_ESP 36 /* offset into the jmp_buf in bytes as defined in _setjmp.s */
62
63#define STACK_CONTEXT_SAVE(sc) ((void)_setjmp((sc)->jumpBuffer))
64
65#define StackContextSP(sc) ((Addr *)(sc)->jumpBuffer[JB_ESP/sizeof(int)])
66
67/* On MacOS X the stackPointer can end up pointing above the StackContext
68 * which we assume to be stored on the stack because it is no longer
69 * needed once we have _longjmp()ed back. So take the minimum of the
70 * SP and the base of the StackContext structure. */
71#define StackContextStackTop(sc) \
72 (StackContextSP(sc) < (Addr*)(sc) ? StackContextSP(sc) : (Addr*)(sc))
73
74
75/* Mac OS X on 64-bit Intel build with Clang or GCC */
76
77#elif defined(MPS_PF_XCI6LL) || defined(MPS_PF_XCI6GC)
78
79#include <setjmp.h>
80
81/* We could use getcontext() from libunwind but that produces
82 * deprecation warnings. See
83 * <http://stackoverflow.com/questions/3592914/how-can-i-implement-cooperative-lightweight-threading-with-c-on-mac-os-x>
84 */
85
86typedef struct StackContextStruct {
87 jmp_buf jumpBuffer;
88} StackContextStruct;
89
90/* See the implementation of _setjmp in
91 * <http://www.opensource.apple.com/source/Libc/Libc-825.24/x86_64/sys/_setjmp.s> */
92
93#define STACK_CONTEXT_SAVE(sc) ((void)_setjmp((sc)->jumpBuffer))
94
95#define JB_RSP 16 /* offset into the jmp_buf in bytes as defined in _setjmp.s */
96
97/* jmp_buf is an int[] but the stack pointer is 8 bytes so we need a cast */
98/* FIXME: possible aliasing problem */
99#define StackContextSP(sc) \
100 (*(Addr **)((char *)(sc)->jumpBuffer+JB_RSP))
101
102/* On MacOS X the stackPointer can end up pointing above the StackContext
103 * which we assume to be stored on the stack because it is no longer
104 * needed once we have _longjmp()ed back. So take the minimum of the
105 * SP and the base of the StackContext structure. */
106#define StackContextStackTop(sc) \
107 (StackContextSP(sc) < (Addr*)(sc) ? StackContextSP(sc) : (Addr*)(sc))
108
109
110/* Windows on 32-bit Intel with Microsoft Visual Studio */
111
112#elif defined(MPS_PF_W3I3MV)
113
114#include <setjmp.h>
115
116typedef struct StackContextStruct {
117 jmp_buf jumpBuffer;
118} StackContextStruct;
119
120#define STACK_CONTEXT_SAVE(sc) ((void)setjmp((sc)->jumpBuffer))
121
122#define StackContextStackTop(sc) \
123 ((Addr *)((_JUMP_BUFFER *)(sc)->jumpBuffer)->Esp)
124
125
126/* Windows on 64-bit Intel with Microsoft Visual Studio */
127
128#elif defined(MPS_PF_W3I6MV)
129
130#include <setjmp.h>
131
132typedef struct StackContextStruct {
133 jmp_buf jumpBuffer;
134} StackContextStruct;
135
136#define STACK_CONTEXT_SAVE(sc) ((void)setjmp((sc)->jumpBuffer))
137
138#define StackContextStackTop(sc) \
139 ((Addr *)((_JUMP_BUFFER *)(sc)->jumpBuffer)->Rsp)
140
141
142#else
143
144/* TODO: implement this on other platforms in a safer way.
145 * Potentially the callee saves from the calling function could be spilled
146 * underneath the jmp_buf so returning the address of the jmp_buf for the
147 * stack top is not completely safe.
148 */
149
150#include <setjmp.h>
151
152typedef struct StackContextStruct {
153 jmp_buf jumpBuffer;
154} StackContextStruct;
155
156#define STACK_CONTEXT_SAVE(sc) ((void)setjmp((sc)->jumpBuffer))
157
158#define StackContextStackTop(sc) ((Addr *)(sc)->jumpBuffer)
159
160
161#endif /* platform defines */
162
163#endif /* sc_h */
164
165
166/* C. COPYRIGHT AND LICENSE
167 *
168 * Copyright (C) 2001-2012 Ravenbrook Limited <http://www.ravenbrook.com/>.
169 * All rights reserved. This is an open source license. Contact
170 * Ravenbrook for commercial licensing options.
171 *
172 * Redistribution and use in source and binary forms, with or without
173 * modification, are permitted provided that the following conditions are
174 * met:
175 *
176 * 1. Redistributions of source code must retain the above copyright
177 * notice, this list of conditions and the following disclaimer.
178 *
179 * 2. Redistributions in binary form must reproduce the above copyright
180 * notice, this list of conditions and the following disclaimer in the
181 * documentation and/or other materials provided with the distribution.
182 *
183 * 3. Redistributions in any form must be accompanied by information on how
184 * to obtain complete source code for this software and any accompanying
185 * software that uses this software. The source code must either be
186 * included in the distribution or be available for no more than the cost
187 * of distribution plus a nominal fee, and must be freely redistributable
188 * under reasonable conditions. For an executable file, complete source
189 * code means the source code for all modules it contains. It does not
190 * include source code for modules or files that typically accompany the
191 * major components of the operating system on which the executable file
192 * runs.
193 *
194 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
195 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
196 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
197 * PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE
198 * COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
199 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
200 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
201 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
202 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
203 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
204 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
205 */
diff --git a/mps/code/ssw3i3mv.c b/mps/code/ssw3i3mv.c
index 608ff2741bf..ac0b09fd670 100644
--- a/mps/code/ssw3i3mv.c
+++ b/mps/code/ssw3i3mv.c
@@ -1,4 +1,4 @@
1/* ssw3mv.c: STACK SCANNING FOR WIN32 WITH MICROSOFT C 1/* ssw3i3mv.c: STACK SCANNING FOR WIN32 WITH MICROSOFT C
2 * 2 *
3 * $Id$ 3 * $Id$
4 * Copyright (c) 2001 Ravenbrook Limited. See end of file for license. 4 * Copyright (c) 2001 Ravenbrook Limited. See end of file for license.
@@ -19,7 +19,7 @@
19#include "mpm.h" 19#include "mpm.h"
20#include <setjmp.h> 20#include <setjmp.h>
21 21
22SRCID(ssw3mv, "$Id$"); 22SRCID(ssw3i3mv, "$Id$");
23 23
24 24
25Res StackScan(ScanState ss, Addr *stackBot) 25Res StackScan(ScanState ss, Addr *stackBot)
@@ -42,3 +42,44 @@ Res StackScan(ScanState ss, Addr *stackBot)
42 42
43 return StackScanInner(ss, stackBot, (Addr *)&((_JUMP_BUFFER *)jb)->Ebx, 3); 43 return StackScanInner(ss, stackBot, (Addr *)&((_JUMP_BUFFER *)jb)->Ebx, 3);
44} 44}
45
46/* C. COPYRIGHT AND LICENSE
47 *
48 * Copyright (C) 2001-2002 Ravenbrook Limited <http://www.ravenbrook.com/>.
49 * All rights reserved. This is an open source license. Contact
50 * Ravenbrook for commercial licensing options.
51 *
52 * Redistribution and use in source and binary forms, with or without
53 * modification, are permitted provided that the following conditions are
54 * met:
55 *
56 * 1. Redistributions of source code must retain the above copyright
57 * notice, this list of conditions and the following disclaimer.
58 *
59 * 2. Redistributions in binary form must reproduce the above copyright
60 * notice, this list of conditions and the following disclaimer in the
61 * documentation and/or other materials provided with the distribution.
62 *
63 * 3. Redistributions in any form must be accompanied by information on how
64 * to obtain complete source code for this software and any accompanying
65 * software that uses this software. The source code must either be
66 * included in the distribution or be available for no more than the cost
67 * of distribution plus a nominal fee, and must be freely redistributable
68 * under reasonable conditions. For an executable file, complete source
69 * code means the source code for all modules it contains. It does not
70 * include source code for modules or files that typically accompany the
71 * major components of the operating system on which the executable file
72 * runs.
73 *
74 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
75 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
76 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
77 * PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE
78 * COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
79 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
80 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
81 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
82 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
83 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
84 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
85 */
diff --git a/mps/code/ssw3i6mv.c b/mps/code/ssw3i6mv.c
index a4e4e4301c4..807577a89a2 100644
--- a/mps/code/ssw3i6mv.c
+++ b/mps/code/ssw3i6mv.c
@@ -1,4 +1,4 @@
1/* ssw3mv.c: STACK SCANNING FOR WIN32 WITH MICROSOFT C 1/* ssw3i6mv.c: STACK SCANNING FOR WIN32 WITH MICROSOFT C
2 * 2 *
3 * $Id$ 3 * $Id$
4 * Copyright (c) 2001 Ravenbrook Limited. See end of file for license. 4 * Copyright (c) 2001 Ravenbrook Limited. See end of file for license.
@@ -27,7 +27,7 @@
27#include "mpm.h" 27#include "mpm.h"
28#include <setjmp.h> 28#include <setjmp.h>
29 29
30SRCID(ssw3mv, "$Id$"); 30SRCID(ssw3i6mv, "$Id$");
31 31
32 32
33Res StackScan(ScanState ss, Addr *stackBot) 33Res StackScan(ScanState ss, Addr *stackBot)
@@ -61,3 +61,44 @@ Res StackScan(ScanState ss, Addr *stackBot)
61 61
62 return StackScanInner(ss, stackBot, (Addr *)&((_JUMP_BUFFER *)jb)->Rbx, 9); 62 return StackScanInner(ss, stackBot, (Addr *)&((_JUMP_BUFFER *)jb)->Rbx, 9);
63} 63}
64
65/* C. COPYRIGHT AND LICENSE
66 *
67 * Copyright (C) 2001-2002 Ravenbrook Limited <http://www.ravenbrook.com/>.
68 * All rights reserved. This is an open source license. Contact
69 * Ravenbrook for commercial licensing options.
70 *
71 * Redistribution and use in source and binary forms, with or without
72 * modification, are permitted provided that the following conditions are
73 * met:
74 *
75 * 1. Redistributions of source code must retain the above copyright
76 * notice, this list of conditions and the following disclaimer.
77 *
78 * 2. Redistributions in binary form must reproduce the above copyright
79 * notice, this list of conditions and the following disclaimer in the
80 * documentation and/or other materials provided with the distribution.
81 *
82 * 3. Redistributions in any form must be accompanied by information on how
83 * to obtain complete source code for this software and any accompanying
84 * software that uses this software. The source code must either be
85 * included in the distribution or be available for no more than the cost
86 * of distribution plus a nominal fee, and must be freely redistributable
87 * under reasonable conditions. For an executable file, complete source
88 * code means the source code for all modules it contains. It does not
89 * include source code for modules or files that typically accompany the
90 * major components of the operating system on which the executable file
91 * runs.
92 *
93 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
94 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
95 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
96 * PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE
97 * COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
98 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
99 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
100 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
101 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
102 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
103 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
104 */
diff --git a/mps/code/w3i3mv.nmk b/mps/code/w3i3mv.nmk
index 37d440235e8..ebe971e1626 100644
--- a/mps/code/w3i3mv.nmk
+++ b/mps/code/w3i3mv.nmk
@@ -19,7 +19,7 @@ MPM = <ring> <mpm> <bt> <protocol> <boot> \
19 <shield> <vmw3> <table> \ 19 <shield> <vmw3> <table> \
20 <thw3> <thw3i3> <ss> <ssw3i3mv> <mpsi> <mpsiw3> <ld> <spi3> \ 20 <thw3> <thw3i3> <ss> <ssw3i3mv> <mpsi> <mpsiw3> <ld> <spi3> \
21 <event> <seg> <sac> <poolmrg> <message> <dbgpool> <dbgpooli> \ 21 <event> <seg> <sac> <poolmrg> <message> <dbgpool> <dbgpooli> \
22 <abq> <meter> <cbs> <poolmv2> <splay> <diag> <version> 22 <abq> <meter> <cbs> <poolmv2> <splay> <diag>
23PLINTH = <mpsliban> <mpsioan> 23PLINTH = <mpsliban> <mpsioan>
24AMC = <poolamc> 24AMC = <poolamc>
25AMS = <poolams> <poolamsi> 25AMS = <poolams> <poolamsi>
diff --git a/mps/code/w3i6mv.nmk b/mps/code/w3i6mv.nmk
index 23fc63ef66d..729509f05dc 100644
--- a/mps/code/w3i6mv.nmk
+++ b/mps/code/w3i6mv.nmk
@@ -20,7 +20,7 @@ MPM = <ring> <mpm> <bt> <protocol> <boot> \
20 <shield> <vmw3> <table> \ 20 <shield> <vmw3> <table> \
21 <thw3> <thw3i6> <ss> <ssw3i6mv> <mpsi> <mpsiw3> <ld> <span> \ 21 <thw3> <thw3i6> <ss> <ssw3i6mv> <mpsi> <mpsiw3> <ld> <span> \
22 <event> <seg> <sac> <poolmrg> <message> <dbgpool> <dbgpooli> \ 22 <event> <seg> <sac> <poolmrg> <message> <dbgpool> <dbgpooli> \
23 <abq> <meter> <cbs> <poolmv2> <splay> <diag> <version> 23 <abq> <meter> <cbs> <poolmv2> <splay> <diag>
24PLINTH = <mpsliban> <mpsioan> 24PLINTH = <mpsliban> <mpsioan>
25AMC = <poolamc> 25AMC = <poolamc>
26AMS = <poolams> <poolamsi> 26AMS = <poolams> <poolamsi>