Mercurial > projects > ldc
comparison druntime/src/compiler/dmd/memory_osx.c @ 1458:e0b2d67cfe7c
Added druntime (this should be removed once it works).
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Tue, 02 Jun 2009 17:43:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1456:7b218ec1044f | 1458:e0b2d67cfe7c |
---|---|
1 /** | |
2 * This module provides OSX-specific support routines for memory.d. | |
3 * | |
4 * Copyright: Copyright Digital Mars 2008 - 2009. | |
5 * License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>. | |
6 * Authors: Walter Bright, Sean Kelly | |
7 * | |
8 * Copyright Digital Mars 2008 - 2009. | |
9 * Distributed under the Boost Software License, Version 1.0. | |
10 * (See accompanying file LICENSE_1_0.txt or copy at | |
11 * http://www.boost.org/LICENSE_1_0.txt) | |
12 */ | |
13 #ifdef __APPLE__ | |
14 | |
15 | |
16 #include <mach-o/dyld.h> | |
17 #include <mach-o/getsect.h> | |
18 | |
19 void gc_addRange( void* p, size_t sz ); | |
20 void gc_removeRange( void* p ); | |
21 | |
22 typedef struct | |
23 { | |
24 const char* seg; | |
25 const char* sect; | |
26 } seg_ref; | |
27 | |
28 const static seg_ref data_segs[] = {{SEG_DATA, SECT_DATA}, | |
29 {SEG_DATA, SECT_BSS}, | |
30 {SEG_DATA, SECT_COMMON}}; | |
31 const static int NUM_DATA_SEGS = sizeof(data_segs) / sizeof(seg_ref); | |
32 | |
33 | |
34 static void on_add_image( const struct mach_header* h, intptr_t slide ) | |
35 { | |
36 const struct section* sect; | |
37 int i; | |
38 | |
39 for( i = 0; i < NUM_DATA_SEGS; ++i ) | |
40 { | |
41 sect = getsectbynamefromheader( h, | |
42 data_segs[i].seg, | |
43 data_segs[i].sect ); | |
44 if( sect == NULL || sect->size == 0 ) | |
45 continue; | |
46 gc_addRange( (void*) sect->addr + slide, sect->size ); | |
47 } | |
48 } | |
49 | |
50 | |
51 static void on_remove_image( const struct mach_header* h, intptr_t slide ) | |
52 { | |
53 const struct section* sect; | |
54 int i; | |
55 | |
56 for( i = 0; i < NUM_DATA_SEGS; ++i ) | |
57 { | |
58 sect = getsectbynamefromheader( h, | |
59 data_segs[i].seg, | |
60 data_segs[i].sect ); | |
61 if( sect == NULL || sect->size == 0 ) | |
62 continue; | |
63 gc_removeRange( (void*) sect->addr + slide ); | |
64 } | |
65 } | |
66 | |
67 | |
68 void _d_osx_image_init() | |
69 { | |
70 _dyld_register_func_for_add_image( &on_add_image ); | |
71 _dyld_register_func_for_remove_image( &on_remove_image ); | |
72 } | |
73 | |
74 | |
75 #endif |