Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
added 64-bit support for static data segments on OSX and moved the im…
Browse files Browse the repository at this point in the history
…plementation from C to D
  • Loading branch information
complexmath committed Nov 11, 2011
1 parent 0f1b868 commit 8d7a688
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 208 deletions.
5 changes: 3 additions & 2 deletions posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ MANIFEST= \
src/rt/llmath.d \
src/rt/mars.h \
src/rt/memory.d \
src/rt/memory_osx.c \
src/rt/memory_osx.d \
src/rt/memset.d \
src/rt/minit.asm \
src/rt/monitor_.d \
Expand Down Expand Up @@ -311,6 +311,7 @@ SRC_D_MODULES = \
rt/lifetime \
rt/llmath \
rt/memory \
rt/memory_osx \
rt/memset \
rt/monitor_ \
rt/obj \
Expand Down Expand Up @@ -364,7 +365,7 @@ SRC_D_MODULES = \
# NOTE: a pre-compiled minit.obj has been provided in dmd for Win32 and
# minit.asm is not used by dmd for Linux

OBJS= $(OBJDIR)/errno_c.o $(OBJDIR)/threadasm.o $(OBJDIR)/complex.o $(OBJDIR)/memory_osx.o
OBJS= $(OBJDIR)/errno_c.o $(OBJDIR)/threadasm.o $(OBJDIR)/complex.o

DOCS=\
$(DOCDIR)/object.html \
Expand Down
52 changes: 28 additions & 24 deletions src/core/sys/osx/mach/dyld.d
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
/**
* Copyright: Copyright Digital Mars 2010.
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
* Authors: Jacob Carlborg
* Version: Initial created: Feb 20, 2010
*/

/* Copyright Digital Mars 2010.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
module core.sys.osx.mach.dyld;

version (OSX):

import core.sys.osx.mach.loader;

extern (C):

uint _dyld_image_count ();
mach_header* _dyld_get_image_header (uint image_index);


/**
* Copyright: Copyright Digital Mars 2010.
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
* Authors: Jacob Carlborg
* Version: Initial created: Feb 20, 2010
*/

/* Copyright Digital Mars 2010.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
module core.sys.osx.mach.dyld;

version (OSX):

public import core.stdc.stdint; // for intptr_t
public import core.sys.osx.mach.loader;

extern (C):

uint _dyld_image_count();
const(char)* _dyld_get_image_name(uint image_index);
mach_header* _dyld_get_image_header(uint image_index);
void _dyld_register_func_for_add_image(void function(in mach_header* mh, intptr_t vmaddr_slide));
void _dyld_register_func_for_remove_image(void function(in mach_header* mh, intptr_t vmaddr_slide));


46 changes: 23 additions & 23 deletions src/core/sys/osx/mach/getsect.d
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/**
* Copyright: Copyright Digital Mars 2010.
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
* Authors: Jacob Carlborg
* Version: Initial created: Mar 16, 2010
*/

/* Copyright Digital Mars 2010.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
module core.sys.osx.mach.getsect;

version (OSX):

import core.sys.osx.mach.loader;

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);

/**
* Copyright: Copyright Digital Mars 2010.
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
* Authors: Jacob Carlborg
* Version: Initial created: Mar 16, 2010
*/

/* Copyright Digital Mars 2010.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
module core.sys.osx.mach.getsect;

version (OSX):

public import core.sys.osx.mach.loader;

extern (C):

const(section)* getsectbynamefromheader(in mach_header* mhp, in char* segname, in char* sectname);
const(section_64)* getsectbynamefromheader_64(in mach_header_64* mhp, in char* segname, in char* sectname);

174 changes: 96 additions & 78 deletions src/core/sys/osx/mach/loader.d
Original file line number Diff line number Diff line change
@@ -1,78 +1,96 @@
/**
* Copyright: Copyright Digital Mars 2010.
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
* Authors: Jacob Carlborg
* Version: Initial created: Feb 20, 2010
*/

/* Copyright Digital Mars 2010.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
module core.sys.osx.mach.loader;

version (OSX):

struct mach_header
{
uint magic;
int cputype;
int cpusubtype;
uint filetype;
uint ncmds;
uint sizeofcmds;
uint flags;
}

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,
MH_CIGAM = 0xcefaedfe,
MH_MAGIC_64 = 0xfeedfacf,
MH_CIGAM_64 = 0xcffaedfe,
}

struct section
{
char[16] sectname;
char[16] segname;
uint addr;
uint size;
uint offset;
uint align_;
uint reloff;
uint nreloc;
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;
}

/**
* Copyright: Copyright Digital Mars 2010.
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
* Authors: Jacob Carlborg
* Version: Initial created: Feb 20, 2010
*/

/* Copyright Digital Mars 2010.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
module core.sys.osx.mach.loader;

version (OSX):

struct mach_header
{
uint magic;
int cputype;
int cpusubtype;
uint filetype;
uint ncmds;
uint sizeofcmds;
uint flags;
}

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;
enum uint MH_CIGAM = 0xcefaedfe;
enum uint MH_MAGIC_64 = 0xfeedfacf;
enum uint MH_CIGAM_64 = 0xcffaedfe;

enum SEG_PAGEZERO = "__PAGEZERO";
enum SEG_TEXT = "__TEXT";
enum SECT_TEXT = "__text";
enum SECT_FVMLIB_INIT0 = "__fvmlib_init0";
enum SECT_FVMLIB_INIT1 = "__fvmlib_init1";
enum SEG_DATA = "__DATA";
enum SECT_DATA = "__data";
enum SECT_BSS = "__bss";
enum SECT_COMMON = "__common";
enum SEG_OBJC = "__OBJC";
enum SECT_OBJC_SYMBOLS = "__symbol_table";
enum SECT_OBJC_MODULES = "__module_info";
enum SECT_OBJC_STRINGS = "__selector_strs";
enum SECT_OBJC_REFS = "__selector_refs";
enum SEG_ICON = "__ICON";
enum SECT_ICON_HEADER = "__header";
enum SECT_ICON_TIFF = "__tiff";
enum SEG_LINKEDIT = "__LINKEDIT";
enum SEG_UNIXSTACK = "__UNIXSTACK";
enum SEG_IMPORT = "__IMPORT";

struct section
{
char[16] sectname;
char[16] segname;
uint addr;
uint size;
uint offset;
uint align_;
uint reloff;
uint nreloc;
uint flags;
uint reserved1;
uint reserved2;
}

struct section_64
{
char[16] sectname;
char[16] segname;
ulong addr;
ulong size;
uint offset;
uint align_;
uint reloff;
uint nreloc;
uint flags;
uint reserved1;
uint reserved2;
uint reserved3;
}

78 changes: 0 additions & 78 deletions src/rt/memory_osx.c

This file was deleted.

Loading

0 comments on commit 8d7a688

Please sign in to comment.