1 /**
2  * D header file for GNU/Linux
3  *
4  * $(LINK2 http://sourceware.org/git/?p=glibc.git;a=blob;f=elf/link.h, glibc elf/link.h)
5  */
6 module sys.linux.link;
7 
8 version (linux):
9 extern (C):
10 // nothrow:
11 
12 import core.stdc.stdint /+ : uintptr_t, uint32_t +/;
13 import sys.linux.config /+ : __WORDSIZE +/;
14 // import sys.linux.dlfcn /+ : Lmid_t +/;
15 alias Lmid_t = long;
16 import sys.linux.elf;
17 
18 // <bits/elfclass.h>
19 version (X86) {
20 	// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
21 	alias __ELF_NATIVE_CLASS = __WORDSIZE;
22 	alias Elf_Symndx = uint32_t;
23 } else version (X86_64) {
24 	// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
25 	alias __ELF_NATIVE_CLASS = __WORDSIZE;
26 	alias Elf_Symndx = uint32_t;
27 } else version (MIPS32) {
28 	// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
29 	alias __ELF_NATIVE_CLASS = __WORDSIZE;
30 	alias Elf_Symndx = uint32_t;
31 } else version (MIPS64) {
32 	// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
33 	alias __ELF_NATIVE_CLASS = __WORDSIZE;
34 	alias Elf_Symndx = uint32_t;
35 } else version (PPC) {
36 	// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
37 	alias __ELF_NATIVE_CLASS = __WORDSIZE;
38 	alias Elf_Symndx = uint32_t;
39 } else version (PPC64) {
40 	// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
41 	alias __ELF_NATIVE_CLASS = __WORDSIZE;
42 	alias Elf_Symndx = uint32_t;
43 } else version (ARM) {
44 	// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
45 	alias __ELF_NATIVE_CLASS = __WORDSIZE;
46 	alias Elf_Symndx = uint32_t;
47 } else version (AArch64) {
48 	// http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/elfclass.h
49 	alias __ELF_NATIVE_CLASS = __WORDSIZE;
50 	alias Elf_Symndx = uint32_t;
51 } else {
52 	static assert(0, "unimplemented");
53 }
54 // <bits/elfclass.h>
55 
56 template ElfW(string Type) {
57 	// mixin("alias Elf"~__ELF_NATIVE_CLASS.stringof~"_"~type~" ElfW;");
58 	
59 	// stringof not implemented, hardcode 64 in there.
60 	mixin("alias ElfW = Elf64_" ~ Type ~ ";");
61 }
62 
63 enum {
64 	RT_CONSISTENT,
65 	RT_ADD,
66 	RT_DELETE,
67 }
68 
69 struct r_debug {
70 	int r_version;
71 	link_map* r_map;
72 	ElfW!"Addr" r_brk;
73 	typeof(RT_CONSISTENT) r_state;
74 	ElfW!"Addr" r_ldbase;
75 }
76 
77 // extern r_debug _r_debug;
78 // extern ElfW!"Dyn"* _DYNAMIC;
79 
80 struct link_map {
81 	ElfW!"Addr" l_addr;
82 	char* l_name;
83 	ElfW!"Dyn"* l_ld;
84 	link_map* l_next, l_prev;
85 }
86 
87 enum {
88 	LA_ACT_CONSISTENT,
89 	LA_ACT_ADD,
90 	LA_ACT_DELETE,
91 }
92 
93 enum {
94 	LA_SER_ORIG = 0x01,
95 	LA_SER_LIBPATH = 0x02,
96 	LA_SER_RUNPATH = 0x04,
97 	LA_SER_CONFIG = 0x08,
98 	LA_SER_DEFAULT = 0x40,
99 	LA_SER_SECURE = 0x80,
100 }
101 
102 enum {
103 	LA_FLG_BINDTO = 0x01,
104 	LA_FLG_BINDFROM = 0x02,
105 }
106 
107 enum {
108 	LA_SYMB_NOPLTENTER = 0x01,
109 	LA_SYMB_NOPLTEXIT = 0x02,
110 	LA_SYMB_STRUCTCALL = 0x04,
111 	LA_SYMB_DLSYM = 0x08,
112 	LA_SYMB_ALTVALUE = 0x10,
113 }
114 
115 struct dl_phdr_info {
116 	ElfW!"Addr" dlpi_addr;
117 	const(char)* dlpi_name;
118 	const(ElfW!"Phdr")* dlpi_phdr;
119 	ElfW!"Half" dlpi_phnum;
120 	
121 	// check the SIZE argument of the dl_iterate_phdr callback whether
122 	// the following members are available
123 	ulong dlpi_adds;
124 	ulong dlpi_subs;
125 	
126 	size_t dlpi_tls_modid;
127 	void *dlpi_tls_data;
128 }
129 
130 private alias __Callback = /+ extern(C) +/ int function(dl_phdr_info*, size_t, void *);
131 /+ extern +/ int dl_iterate_phdr(__Callback __callback, void*__data);
132 
133 
134 // ld.so auditing interfaces prototypes have to be defined by the auditing DSO.
135 /+ extern +/ uint la_version(uint __version);
136 /+ extern +/ void la_activity(uintptr_t *__cookie, uint __flag);
137 /+ extern +/ char* la_objsearch(const(char)* __name, uintptr_t* __cookie,
138                           uint __flag);
139 /+ extern +/ uint la_objopen(link_map* __map, Lmid_t __lmid,
140                        uintptr_t* __cookie);
141 /+ extern +/ void la_preinit(uintptr_t* __cookie);
142 /+ extern +/ uintptr_t la_symbind32(Elf32_Sym* __sym, uint __ndx,
143                               uintptr_t* __refcook, uintptr_t* __defcook,
144                               uint *__flags, const(char)* __symname);
145 /+ extern +/ uintptr_t la_symbind64(Elf64_Sym* __sym, uint __ndx,
146                               uintptr_t* __refcook, uintptr_t* __defcook,
147                               uint* __flags, const(char)* __symname);
148 /+ extern +/ uint la_objclose(uintptr_t *__cookie);