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

Commit

Permalink
add core.sys.linux.dlfcn
Browse files Browse the repository at this point in the history
- core.sys.posix.dlfcn
  - fix linux-MIPS constants
  - deprecate non-POSIX function
  • Loading branch information
MartinNowak committed Feb 15, 2013
1 parent 3c4a334 commit 4482b95
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 11 deletions.
1 change: 1 addition & 0 deletions mak/COPY
Expand Up @@ -40,6 +40,7 @@ COPY=\
$(IMPDIR)\core\sys\freebsd\sys\event.d \
\
$(IMPDIR)\core\sys\linux\config.d \
$(IMPDIR)\core\sys\linux\dlfcn.d \
$(IMPDIR)\core\sys\linux\elf.d \
$(IMPDIR)\core\sys\linux\epoll.d \
$(IMPDIR)\core\sys\linux\execinfo.d \
Expand Down
1 change: 1 addition & 0 deletions mak/MANIFEST
Expand Up @@ -66,6 +66,7 @@ MANIFEST=\
src\core\sys\freebsd\sys\event.d \
\
src\core\sys\linux\config.d \
src\core\sys\linux\dlfcn.d \
src\core\sys\linux\elf.d \
src\core\sys\linux\epoll.d \
src\core\sys\linux\execinfo.d \
Expand Down
162 changes: 162 additions & 0 deletions src/core/sys/linux/dlfcn.d
@@ -0,0 +1,162 @@
/**
* D header file for GNU/Linux
*
* $(LINK2 http://sourceware.org/git/?p=glibc.git;a=blob;f=dlfcn/dlfcn.h, glibc dlfcn/dlfcn.h)
*/
module core.sys.linux.dlfcn;

version (linux):
extern (C):
nothrow:

public import core.sys.posix.dlfcn;
import core.sys.linux.config;

// <bits/dlfcn.h>
version (X86)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
// enum RTLD_LAZY = 0x00001; // POSIX
// enum RTLD_NOW = 0x00002; // POSIX
enum RTLD_BINDING_MASK = 0x3;
enum RTLD_NOLOAD = 0x00004;
enum RTLD_DEEPBIND = 0x00008;

// enum RTLD_GLOBAL = 0x00100; // POSIX
// enum RTLD_LOCAL = 0; // POSIX
enum RTLD_NODELETE = 0x01000;

static if (__USE_GNU)
{
RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
{
_dl_mcount_wrapper_check(cast(void*)fctp);
return fctp(args);
}

void _dl_mcount_wrapper_check(void* __selfpc);
}
}
else version (X86_64)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
// enum RTLD_LAZY = 0x00001; // POSIX
// enum RTLD_NOW = 0x00002; // POSIX
enum RTLD_BINDING_MASK = 0x3;
enum RTLD_NOLOAD = 0x00004;
enum RTLD_DEEPBIND = 0x00008;

// enum RTLD_GLOBAL = 0x00100; // POSIX
// enum RTLD_LOCAL = 0; // POSIX
enum RTLD_NODELETE = 0x01000;

static if (__USE_GNU)
{
RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
{
_dl_mcount_wrapper_check(cast(void*)fctp);
return fctp(args);
}

void _dl_mcount_wrapper_check(void* __selfpc);
}
}
else version (MIPS32)
{
// http://sourceware.org/git/?p=glibc.git;a=blob;f=ports/sysdeps/mips/bits/dlfcn.h
// enum RTLD_LAZY = 0x0001; // POSIX
// enum RTLD_NOW = 0x0002; // POSIX
enum RTLD_BINDING_MASK = 0x3;
enum RTLD_NOLOAD = 0x00008;
enum RTLD_DEEPBIND = 0x00010;

// enum RTLD_GLOBAL = 0x0004; // POSIX
// enum RTLD_LOCAL = 0; // POSIX
enum RTLD_NODELETE = 0x01000;

static if (__USE_GNU)
{
RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
{
_dl_mcount_wrapper_check(cast(void*)fctp);
return fctp(args);
}

void _dl_mcount_wrapper_check(void* __selfpc);
}
}
else
static assert(0, "unimplemented");

// <bits/dlfcn.h>

static if (__USE_GNU)
{
enum RTLD_NEXT = cast(void *)-1L;
enum RTLD_DEFAULT = cast(void *)0;
alias c_long Lmid_t;
enum LM_ID_BASE = 0;
enum LM_ID_NEWLM = -1;
}

// void* dlopen(in char* __file, int __mode); // POSIX
// int dlclose(void* __handle); // POSIX
// void* dlsym(void* __handle, in char* __name); // POSIX

static if (__USE_GNU)
{
void* dlmopen(Lmid_t __nsid, in char* __file, int __mode);
void* dlvsym(void* __handle, in char* __name, in char* __version);
}

// char* dlerror(); // POSIX

static if (__USE_GNU)
{
struct Dl_info
{
const(char)* dli_fname;
void* dli_fbase;
const(char)* dli_sname;
void* dli_saddr;
}

int dladdr(void* __address, Dl_info* __info);
int dladdr1(void* __address, Dl_info* __info, void** __extra_info, int __flags);

enum
{
RTLD_DL_SYMENT = 1,
RTLD_DL_LINKMAP = 2,
}

int dlinfo(void* __handle, int __request, void* __arg);

enum
{
RTLD_DI_LMID = 1,
RTLD_DI_LINKMAP = 2,
RTLD_DI_CONFIGADDR = 3,
RTLD_DI_SERINFO = 4,
RTLD_DI_SERINFOSIZE = 5,
RTLD_DI_ORIGIN = 6,
RTLD_DI_PROFILENAME = 7,
RTLD_DI_PROFILEOUT = 8,
RTLD_DI_TLS_MODID = 9,
RTLD_DI_TLS_DATA = 10,
RTLD_DI_MAX = 10,
}

struct Dl_serpath
{
char* dls_name;
uint dls_flags;
}

struct Dl_serinfo
{
size_t dls_size;
uint dls_cnt;
Dl_serpath[1] dls_serpath;
}
}
45 changes: 34 additions & 11 deletions src/core/sys/posix/dlfcn.d
Expand Up @@ -36,24 +36,47 @@ void* dlsym(void*, in char*);

version( linux )
{
enum RTLD_LAZY = 0x00001;
enum RTLD_NOW = 0x00002;
enum RTLD_GLOBAL = 0x00100;
enum RTLD_LOCAL = 0x00000;
version (X86)
{
enum RTLD_LAZY = 0x00001;
enum RTLD_NOW = 0x00002;
enum RTLD_GLOBAL = 0x00100;
enum RTLD_LOCAL = 0x00000;
}
else version (X86_64)
{
enum RTLD_LAZY = 0x00001;
enum RTLD_NOW = 0x00002;
enum RTLD_GLOBAL = 0x00100;
enum RTLD_LOCAL = 0x00000;
}
else version (MIPS32)
{
enum RTLD_LAZY = 0x0001;
enum RTLD_NOW = 0x0002;
enum RTLD_GLOBAL = 0x0004;
enum RTLD_LOCAL = 0;
}
else
static assert(0, "unimplemented");

int dlclose(void*);
char* dlerror();
void* dlopen(in char*, int);
void* dlsym(void*, in char*);
int dladdr(void* addr, Dl_info* info);
void* dlvsym(void* handle, in char* symbol, in char* version_);

struct Dl_info
deprecated("Please use core.sys.linux.dlfcn for non-POSIX extensions")
{
const(char)* dli_fname;
void* dli_fbase;
const(char)* dli_sname;
void* dli_saddr;
int dladdr(void* addr, Dl_info* info);
void* dlvsym(void* handle, in char* symbol, in char* version_);

struct Dl_info
{
const(char)* dli_fname;
void* dli_fbase;
const(char)* dli_sname;
void* dli_saddr;
}
}
}
else version( OSX )
Expand Down
3 changes: 3 additions & 0 deletions win32.mak
Expand Up @@ -256,6 +256,9 @@ $(IMPDIR)\core\sys\freebsd\sys\event.d : src\core\sys\freebsd\sys\event.d
$(IMPDIR)\core\sys\linux\config.d : src\core\sys\linux\config.d
copy $** $@

$(IMPDIR)\core\sys\linux\dlfcn.d : src\core\sys\linux\dlfcn.d
copy $** $@

$(IMPDIR)\core\sys\linux\elf.d : src\core\sys\linux\elf.d
copy $** $@

Expand Down
3 changes: 3 additions & 0 deletions win64.mak
Expand Up @@ -263,6 +263,9 @@ $(IMPDIR)\core\sys\freebsd\sys\event.d : src\core\sys\freebsd\sys\event.d
$(IMPDIR)\core\sys\linux\config.d : src\core\sys\linux\config.d
copy $** $@

$(IMPDIR)\core\sys\linux\dlfcn.d : src\core\sys\linux\dlfcn.d
copy $** $@

$(IMPDIR)\core\sys\linux\elf.d : src\core\sys\linux\elf.d
copy $** $@

Expand Down

0 comments on commit 4482b95

Please sign in to comment.