Index: src/rt/memory.d
===================================================================
--- src/rt/memory.d	(revision 423)
+++ src/rt/memory.d	(working copy)
@@ -12,7 +12,6 @@
  */
 module rt.memory;
 
-
 private
 {
     version( linux )
@@ -174,10 +173,6 @@
             alias __data_start  Data_Start;
             alias _end          Data_End;
     }
-    else version( OSX )
-    {
-        extern (C) void _d_osx_image_init();
-    }
     else version( FreeBSD )
     {
         extern (C)
@@ -230,3 +225,114 @@
         static assert( false, "Operating system not supported." );
     }
 }
+
+version (OSX):
+
+import core.sys.osx.mach.dyld;
+import core.sys.osx.mach.getsect;
+import core.sys.osx.mach.loader;
+import rt.deh2;
+
+struct SegmentSection
+{
+    const char* segment;
+    const char* section;
+}
+
+SegmentSection[5] dataSegments = [SegmentSection(SEG_DATA, SECT_DATA),
+								  SegmentSection(SEG_DATA, SECT_BSS),
+								  SegmentSection(SEG_DATA, SECT_COMMON),
+								  SegmentSection(SEG_DATA, "__tls_data".ptr),
+								  SegmentSection(SEG_DATA, "__tlscoal_nt".ptr)];
+
+extern (C) extern __gshared ModuleInfo*[] _moduleinfo_array;
+extern (C) extern __gshared FuncTable[] _eh_tables;
+
+bool isSectionValid (const section* sect)
+{
+	return sect !is null && sect.size > 0;
+}
+
+const(section*) getSection (const mach_header* header, in char* segment, in char* section)
+{
+	version (D_LP64)
+		return getsectbynamefromheader_64(header, segment, section);
+		
+	else
+		return getsectbynamefromheader(header, segment, section);
+}
+
+void getSectionData (string segmentName, string sectionName, T) (const mach_header* header, ref T[] array)
+{
+    const c_segmentName = segmentName.ptr;
+    const c_sectionName = sectionName.ptr; 
+
+	const sect = getSection(header, c_segmentName, c_sectionName);
+
+	if (!isSectionValid(sect))
+		return;
+
+	void* start = cast(void*) (cast(byte*) header + sect.offset);
+    void* end = cast(void*) (cast(byte*) start + sect.size);
+
+    size_t len = cast(T*)end - cast(T*)start;
+	array ~= (cast(T*)start)[0 .. len];
+}
+									
+extern (C) void onAddImage (const mach_header* header, ptrdiff_t slide)
+{
+	foreach (s ;  dataSegments)
+	{
+		const sect = getSection(header, s.segment, s.section);
+			
+		if (!isSectionValid(sect))
+			continue;
+			
+		gc_addRange(cast(void*) sect.addr + slide, sect.size);
+	}
+	
+	addModuleInfo(header);
+	addEHTables(header);
+}
+
+extern (C) void onRemoveImage (const mach_header* header, ptrdiff_t slide)
+{
+	foreach (s ;  dataSegments)
+	{
+		const sect = getSection(header, s.segment, s.section);
+			
+		if (!isSectionValid(sect))
+			continue;
+			
+		gc_removeRange(cast(void*) sect.addr + slide);
+	}
+	
+	removeModuleInfo(header);
+	removeEHTables(header);
+}
+
+void addModuleInfo (const mach_header* header)
+{
+	getSectionData!("__DATA", "__minfodata")(header, _moduleinfo_array);
+}
+
+void removeModuleInfo (const mach_header* header)
+{
+	
+}
+
+void addEHTables (const mach_header* header)
+{
+	getSectionData!("__DATA", "__deh_eh")(header, _eh_tables);
+}
+
+void removeEHTables (const mach_header* header)
+{
+	
+}
+
+void _d_osx_image_init ()
+{
+    _dyld_register_func_for_add_image(&onAddImage);
+	_dyld_register_func_for_remove_image(&onRemoveImage);
+}
\ No newline at end of file
Index: src/rt/deh2.d
===================================================================
--- src/rt/deh2.d	(revision 423)
+++ src/rt/deh2.d	(working copy)
@@ -15,11 +15,19 @@
 //debug=1;
 
 extern (C)
-{
+{	
+	version (OSX)
+		__gshared FuncTable[] _eh_tables;
+		
     extern __gshared
     {
-        void* _deh_beg;
-        void* _deh_end;
+		version (OSX) {}
+	
+		else
+		{
+			void* _deh_beg;
+	        void* _deh_end;
+		}
     }
     
     Throwable.TraceInfo _d_traceContext(void* ptr = null);
@@ -94,25 +102,37 @@
 
 DHandlerTable *__eh_finddata(void *address)
 {
-    debug printf("FuncTable.sizeof = %p\n", FuncTable.sizeof);
-    debug printf("__eh_finddata(address = %p)\n", address);
-    debug printf("_deh_beg = %p, _deh_end = %p\n", &_deh_beg, &_deh_end);
-    for (auto ft = cast(FuncTable *)&_deh_beg;
-         ft < cast(FuncTable *)&_deh_end;
-         ft++)
-    {
-      debug printf("\tft = %p, fptr = %p, fsize = x%03x, handlertable = %p\n",
-              ft, ft.fptr, ft.fsize, ft.handlertable);
+	version (OSX)
+	{
+        foreach (ft ; _eh_tables)
+            if (ft.fptr <= address && address < cast(void *)(cast(char *)ft.fptr + ft.fsize))
+                return ft.handlertable;
 
-        if (ft.fptr <= address &&
-            address < cast(void *)(cast(char *)ft.fptr + ft.fsize))
-        {
-          debug printf("\tfound handler table\n");
-            return ft.handlertable;
-        }
-    }
-    debug printf("\tnot found\n");
-    return null;
+        return null;
+	}
+	
+	else
+	{
+		debug printf("FuncTable.sizeof = %p\n", FuncTable.sizeof);
+	    debug printf("__eh_finddata(address = %p)\n", address);
+	    debug printf("_deh_beg = %p, _deh_end = %p\n", &_deh_beg, &_deh_end);
+	    for (auto ft = cast(FuncTable *)&_deh_beg;
+	         ft < cast(FuncTable *)&_deh_end;
+	         ft++)
+	    {
+	      debug printf("\tft = %p, fptr = %p, fsize = x%03x, handlertable = %p\n",
+	              ft, ft.fptr, ft.fsize, ft.handlertable);
+
+	        if (ft.fptr <= address &&
+	            address < cast(void *)(cast(char *)ft.fptr + ft.fsize))
+	        {
+	          debug printf("\tfound handler table\n");
+	            return ft.handlertable;
+	        }
+	    }
+	    debug printf("\tnot found\n");
+	    return null;
+	}
 }
 
 
Index: src/object_.d
===================================================================
--- src/object_.d	(revision 423)
+++ src/object_.d	(working copy)
@@ -1731,15 +1731,6 @@
     extern (C) __gshared ModuleReference* _Dmodule_ref;   // start of linked list
 }
 
-version (OSX)
-{
-    extern (C)
-    {
-        extern __gshared void* _minfo_beg;
-        extern __gshared void* _minfo_end;
-    }
-}
-
 __gshared ModuleInfo*[] _moduleinfo_dtors;
 __gshared uint          _moduleinfo_dtors_i;
 
@@ -1801,7 +1792,8 @@
         }
     }
 
-    version (OSX)
+	// this is now handled in memory.d
+    /+version (OSX)
     {
         /* The ModuleInfo references are stored in the special segment
          * __minfodata, which is bracketed by the segments __minfo_beg
@@ -1809,6 +1801,7 @@
          * are of zero size and are in the two bracketing segments,
          * respectively.
          */
+		
          size_t length = cast(ModuleInfo**)&_minfo_end - cast(ModuleInfo**)&_minfo_beg;
          _moduleinfo_array = (cast(ModuleInfo**)&_minfo_beg)[0 .. length];
          debug printf("moduleinfo: ptr = %p, length = %d\n", _moduleinfo_array.ptr, _moduleinfo_array.length);
@@ -1818,7 +1811,7 @@
              //printf("\t%p\n", m);
              printf("\t%.*s\n", m.name);
          }
-    }    
+    }+/    
 
     version (Windows)
     {
Index: src/core/sys/osx/mach/getsect.d
===================================================================
--- src/core/sys/osx/mach/getsect.d	(revision 423)
+++ src/core/sys/osx/mach/getsect.d	(working copy)
@@ -17,6 +17,8 @@
 
 extern (C):
 
-section* getsectbynamefromheader (in mach_header* mhp, in char* segname, in char* sectname);
-section_64* getsectbynamefromheader_64 (mach_header_64* mhp, in char* segname, in char* sectname);
-
+version (D_LP64)
+	const(section*) getsectbynamefromheader_64 (in mach_header* mhp, in char* segname, in char* sectname);
+	
+else
+	const(section*) getsectbynamefromheader (in mach_header* mhp, in char* segname, in char* sectname);
\ No newline at end of file
Index: src/core/sys/osx/mach/loader.d
===================================================================
--- src/core/sys/osx/mach/loader.d	(revision 423)
+++ src/core/sys/osx/mach/loader.d	(working copy)
@@ -13,6 +13,11 @@
 
 version (OSX):
 
+enum immutable(char)* SEG_DATA = "__DATA".ptr;
+enum immutable(char)* SECT_DATA = "__data".ptr;
+enum immutable(char)* SECT_BSS = "__bss".ptr;
+enum immutable(char)* SECT_COMMON = "__common".ptr;
+
 struct mach_header
 {
 	uint magic;
@@ -22,20 +27,11 @@
 	uint ncmds;
 	uint sizeofcmds;
 	uint flags;
+	
+	version (D_LP64)
+		uint reserved;
 }
 
-struct mach_header_64
-{
-	uint magic;
-	int cputype;
-	int cpusubtype;
-	uint filetype;
-	uint ncmds;
-	uint sizeofcmds;
-	uint flags;
-	uint reserved;
-}
-
 enum : uint
 {
 	MH_MAGIC = 0xfeedface,
@@ -57,21 +53,7 @@
 	uint flags;
 	uint reserved1;
 	uint reserved2;
-}
-
-struct section_64
-{
-	char[16] sectname;
-	char[16] segname;
-	long addr;
-	long size;
-	uint offset;
-	uint align_;
-	uint reloff;
-	uint nreloc;
-	uint flags;
-	uint reserved1;
-	uint reserved2;
-	uint reserved3;
-}
-
+	
+	version (D_LP64)
+		uint reserved3;
+}
\ No newline at end of file
Index: src/core/sys/osx/mach/dyld.d
===================================================================
--- src/core/sys/osx/mach/dyld.d	(revision 423)
+++ src/core/sys/osx/mach/dyld.d	(working copy)
@@ -17,7 +17,9 @@
 
 extern (C):
 
+alias void function (mach_header* mh, ptrdiff_t vmaddr_slide) DyldFuncPointer;
+
 uint _dyld_image_count ();
 mach_header* _dyld_get_image_header (uint image_index);
-
-
+void _dyld_register_func_for_add_image (DyldFuncPointer);
+void _dyld_register_func_for_remove_image (DyldFuncPointer);
\ No newline at end of file
Index: posix.mak
===================================================================
--- posix.mak	(revision 423)
+++ posix.mak	(working copy)
@@ -153,14 +153,12 @@
 	src/rt/deh2.d \
 	src/rt/dmain2.d \
 	src/rt/dylib_fixes.c \
-	src/rt/image.d \
 	src/rt/invariant.d \
 	src/rt/invariant_.d \
 	src/rt/lifetime.d \
 	src/rt/llmath.d \
 	src/rt/mars.h \
 	src/rt/memory.d \
-	src/rt/memory_osx.c \
 	src/rt/memset.d \
 	src/rt/minit.asm \
 	src/rt/monitor.c \
@@ -339,7 +337,7 @@
 #       minit.asm is not used by dmd for Linux
 
 OBJS= $(OBJDIR)/errno_c.o $(OBJDIR)/threadasm.o $(OBJDIR)/complex.o	\
-$(OBJDIR)/critical.o $(OBJDIR)/memory_osx.o $(OBJDIR)/monitor.o
+$(OBJDIR)/critical.o $(OBJDIR)/monitor.o
 
 DOCS=\
 	$(DOCDIR)/object.html \