Mercurial > projects > ldc
comparison druntime/src/compiler/dmd/memory.d @ 759:d3eb054172f9
Added copy of druntime from DMD 2.020 modified for LDC.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Tue, 11 Nov 2008 01:52:37 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
758:f04dde6e882c | 759:d3eb054172f9 |
---|---|
1 /** | |
2 * This module exposes functionality for inspecting and manipulating memory. | |
3 * | |
4 * Copyright: Copyright (C) 2005-2006 Digital Mars, www.digitalmars.com. | |
5 * All rights reserved. | |
6 * License: | |
7 * This software is provided 'as-is', without any express or implied | |
8 * warranty. In no event will the authors be held liable for any damages | |
9 * arising from the use of this software. | |
10 * | |
11 * Permission is granted to anyone to use this software for any purpose, | |
12 * including commercial applications, and to alter it and redistribute it | |
13 * freely, in both source and binary form, subject to the following | |
14 * restrictions: | |
15 * | |
16 * o The origin of this software must not be misrepresented; you must not | |
17 * claim that you wrote the original software. If you use this software | |
18 * in a product, an acknowledgment in the product documentation would be | |
19 * appreciated but is not required. | |
20 * o Altered source versions must be plainly marked as such, and must not | |
21 * be misrepresented as being the original software. | |
22 * o This notice may not be removed or altered from any source | |
23 * distribution. | |
24 * Authors: Walter Bright, Sean Kelly | |
25 */ | |
26 module rt.memory; | |
27 | |
28 | |
29 private | |
30 { | |
31 version( linux ) | |
32 { | |
33 version = SimpleLibcStackEnd; | |
34 | |
35 version( SimpleLibcStackEnd ) | |
36 { | |
37 extern (C) extern void* __libc_stack_end; | |
38 } | |
39 } | |
40 } | |
41 | |
42 | |
43 /** | |
44 * | |
45 */ | |
46 extern (C) void* rt_stackBottom() | |
47 { | |
48 version( Windows ) | |
49 { | |
50 asm | |
51 { | |
52 naked; | |
53 mov EAX,FS:4; | |
54 ret; | |
55 } | |
56 } | |
57 else version( linux ) | |
58 { | |
59 version( SimpleLibcStackEnd ) | |
60 { | |
61 return __libc_stack_end; | |
62 } | |
63 else | |
64 { | |
65 // See discussion: http://autopackage.org/forums/viewtopic.php?t=22 | |
66 static void** libc_stack_end; | |
67 | |
68 if( libc_stack_end == libc_stack_end.init ) | |
69 { | |
70 void* handle = dlopen( null, RTLD_NOW ); | |
71 libc_stack_end = cast(void**) dlsym( handle, "__libc_stack_end" ); | |
72 dlclose( handle ); | |
73 } | |
74 return *libc_stack_end; | |
75 } | |
76 } | |
77 else | |
78 { | |
79 static assert( false, "Operating system not supported." ); | |
80 } | |
81 } | |
82 | |
83 | |
84 /** | |
85 * | |
86 */ | |
87 extern (C) void* rt_stackTop() | |
88 { | |
89 version( D_InlineAsm_X86 ) | |
90 { | |
91 asm | |
92 { | |
93 naked; | |
94 mov EAX, ESP; | |
95 ret; | |
96 } | |
97 } | |
98 else | |
99 { | |
100 static assert( false, "Architecture not supported." ); | |
101 } | |
102 } | |
103 | |
104 | |
105 private | |
106 { | |
107 version( Windows ) | |
108 { | |
109 extern (C) | |
110 { | |
111 extern int _xi_a; // &_xi_a just happens to be start of data segment | |
112 extern int _edata; // &_edata is start of BSS segment | |
113 extern int _end; // &_end is past end of BSS | |
114 } | |
115 } | |
116 else version( linux ) | |
117 { | |
118 extern (C) | |
119 { | |
120 extern int _data; | |
121 extern int __data_start; | |
122 extern int _end; | |
123 extern int _data_start__; | |
124 extern int _data_end__; | |
125 extern int _bss_start__; | |
126 extern int _bss_end__; | |
127 extern int __fini_array_end; | |
128 } | |
129 | |
130 alias __data_start Data_Start; | |
131 alias _end Data_End; | |
132 } | |
133 | |
134 alias void delegate( void*, void* ) scanFn; | |
135 } | |
136 | |
137 | |
138 /** | |
139 * | |
140 */ | |
141 extern (C) void rt_scanStaticData( scanFn scan ) | |
142 { | |
143 scan(rt_staticDataBottom(), rt_staticDataTop()); | |
144 } | |
145 | |
146 /** | |
147 * | |
148 */ | |
149 extern (C) void* rt_staticDataBottom() | |
150 { | |
151 version( Windows ) | |
152 { | |
153 return &_xi_a; | |
154 } | |
155 else version( linux ) | |
156 { | |
157 return &__data_start; | |
158 } | |
159 else | |
160 { | |
161 static assert( false, "Operating system not supported." ); | |
162 } | |
163 } | |
164 | |
165 /** | |
166 * | |
167 */ | |
168 extern (C) void* rt_staticDataTop() | |
169 { | |
170 version( Windows ) | |
171 { | |
172 return &_end; | |
173 } | |
174 else version( linux ) | |
175 { | |
176 return &_end; | |
177 } | |
178 else | |
179 { | |
180 static assert( false, "Operating system not supported." ); | |
181 } | |
182 } | |
183 | |
184 |