Mercurial > projects > ldc
comparison runtime/internal/memory.d @ 443:44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Reworked the LLVMDC specific pragmas.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Fri, 01 Aug 2008 00:32:06 +0200 |
parents | |
children | 02fb65cddc3e |
comparison
equal
deleted
inserted
replaced
442:76078c8ab5b9 | 443:44f08170f4ef |
---|---|
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(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(LLVMDC) | |
101 { | |
102 return llvm_frameaddress(); | |
103 } | |
104 else version( D_InlineAsm_X86 ) | |
105 { | |
106 asm | |
107 { | |
108 naked; | |
109 mov EAX, ESP; | |
110 ret; | |
111 } | |
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 _data_start__; | |
127 extern int _bss_end__; | |
128 | |
129 alias _data_start__ Data_Start; | |
130 alias _bss_end__ Data_End; | |
131 } | |
132 } | |
133 else version( linux ) | |
134 { | |
135 extern (C) | |
136 { | |
137 extern int _data; | |
138 extern int __data_start; | |
139 extern int _end; | |
140 extern int _data_start__; | |
141 extern int _data_end__; | |
142 extern int _bss_start__; | |
143 extern int _bss_end__; | |
144 extern int __fini_array_end; | |
145 } | |
146 | |
147 alias __data_start Data_Start; | |
148 alias _end Data_End; | |
149 } | |
150 | |
151 alias void delegate( void*, void* ) scanFn; | |
152 } | |
153 | |
154 | |
155 /** | |
156 * | |
157 */ | |
158 extern (C) void rt_scanStaticData( scanFn scan ) | |
159 { | |
160 version( Win32 ) | |
161 { | |
162 scan( &Data_Start, &Data_End ); | |
163 } | |
164 else version( linux ) | |
165 { | |
166 //printf("scanning static data from %p to %p\n", &Data_Start, &Data_End); | |
167 scan( &Data_Start, &Data_End ); | |
168 } | |
169 else | |
170 { | |
171 static assert( false, "Operating system not supported." ); | |
172 } | |
173 } |