Mercurial > projects > ldc
comparison tango/lib/compiler/llvmdc/memory.d @ 132:1700239cab2e trunk
[svn r136] MAJOR UNSTABLE UPDATE!!!
Initial commit after moving to Tango instead of Phobos.
Lots of bugfixes...
This build is not suitable for most things.
author | lindquist |
---|---|
date | Fri, 11 Jan 2008 17:57:40 +0100 |
parents | |
children | 0806379a5eca |
comparison
equal
deleted
inserted
replaced
131:5825d48b27d1 | 132:1700239cab2e |
---|---|
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 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 else | |
40 { | |
41 import tango.stdc.posix.dlfcn; | |
42 } | |
43 } | |
44 version(LLVMDC) | |
45 { | |
46 pragma(LLVM_internal, "intrinsic", "llvm.frameaddress") | |
47 { | |
48 void* llvm_frameaddress(uint level=0); | |
49 } | |
50 } | |
51 } | |
52 | |
53 | |
54 /** | |
55 * | |
56 */ | |
57 extern (C) void* rt_stackBottom() | |
58 { | |
59 version( Win32 ) | |
60 { | |
61 asm | |
62 { | |
63 naked; | |
64 mov EAX,FS:4; | |
65 ret; | |
66 } | |
67 } | |
68 else version( linux ) | |
69 { | |
70 version( SimpleLibcStackEnd ) | |
71 { | |
72 return __libc_stack_end; | |
73 } | |
74 else | |
75 { | |
76 // See discussion: http://autopackage.org/forums/viewtopic.php?t=22 | |
77 static void** libc_stack_end; | |
78 | |
79 if( libc_stack_end == libc_stack_end.init ) | |
80 { | |
81 void* handle = dlopen( null, RTLD_NOW ); | |
82 libc_stack_end = cast(void**) dlsym( handle, "__libc_stack_end" ); | |
83 dlclose( handle ); | |
84 } | |
85 return *libc_stack_end; | |
86 } | |
87 } | |
88 else | |
89 { | |
90 static assert( false, "Operating system not supported." ); | |
91 } | |
92 } | |
93 | |
94 | |
95 /** | |
96 * | |
97 */ | |
98 extern (C) void* rt_stackTop() | |
99 { | |
100 version( D_InlineAsm_X86 ) | |
101 { | |
102 asm | |
103 { | |
104 naked; | |
105 mov EAX, ESP; | |
106 ret; | |
107 } | |
108 } | |
109 else version(LLVMDC) | |
110 { | |
111 return llvm_frameaddress(); | |
112 } | |
113 else | |
114 { | |
115 static assert( false, "Architecture not supported." ); | |
116 } | |
117 } | |
118 | |
119 | |
120 private | |
121 { | |
122 version( Win32 ) | |
123 { | |
124 extern (C) | |
125 { | |
126 extern int _xi_a; // &_xi_a just happens to be start of data segment | |
127 extern int _edata; // &_edata is start of BSS segment | |
128 extern int _end; // &_end is past end of BSS | |
129 } | |
130 } | |
131 else version( linux ) | |
132 { | |
133 extern (C) | |
134 { | |
135 extern int _data; | |
136 extern int __data_start; | |
137 extern int _end; | |
138 extern int _data_start__; | |
139 extern int _data_end__; | |
140 extern int _bss_start__; | |
141 extern int _bss_end__; | |
142 extern int __fini_array_end; | |
143 } | |
144 | |
145 alias __data_start Data_Start; | |
146 alias _end Data_End; | |
147 } | |
148 | |
149 alias void delegate( void*, void* ) scanFn; | |
150 } | |
151 | |
152 | |
153 /** | |
154 * | |
155 */ | |
156 extern (C) void rt_scanStaticData( scanFn scan ) | |
157 { | |
158 version( Win32 ) | |
159 { | |
160 scan( &_xi_a, &_end ); | |
161 } | |
162 else version( linux ) | |
163 { | |
164 scan( &__data_start, &_end ); | |
165 } | |
166 else | |
167 { | |
168 static assert( false, "Operating system not supported." ); | |
169 } | |
170 } |