Mercurial > projects > ldc
annotate tango/lib/compiler/llvmdc/memory.d @ 270:d9d5d59873d8 trunk
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
Branch statements now emit a new block after it.
Fixed the _adSort runtime function had a bad signature.
Added a missing dot prefix on compiler generated string tables for string switch.
Fixed, PTRSIZE seems like it was wrong on 64bit, now it definitely gets set properly.
author | lindquist |
---|---|
date | Mon, 16 Jun 2008 16:01:19 +0200 |
parents | 0806379a5eca |
children | 94394be61589 |
rev | line source |
---|---|
132 | 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 { | |
270
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
217
diff
changeset
|
100 version(LLVMDC) |
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
217
diff
changeset
|
101 { |
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
217
diff
changeset
|
102 return llvm_frameaddress(); |
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
217
diff
changeset
|
103 } |
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
217
diff
changeset
|
104 else version( D_InlineAsm_X86 ) |
132 | 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 _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 { | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
132
diff
changeset
|
164 //printf("scanning static data from %p to %p\n", &__data_start, &_end); |
132 | 165 scan( &__data_start, &_end ); |
166 } | |
167 else | |
168 { | |
169 static assert( false, "Operating system not supported." ); | |
170 } | |
171 } |