Changeset 14572
- Timestamp:
- Jan 10, 2011, 12:12:15 AM (14 years ago)
- File:
-
- 1 edited
-
trunk/source/lisp-kernel/pmcl-kernel.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/lisp-kernel/pmcl-kernel.c
r14529 r14572 44 44 #include <sys/time.h> 45 45 #include <sys/resource.h> 46 #ifdef ANDROID 47 #ifdef ARM 48 #define ANDROID_ARM_LINKER 1 49 #endif 50 #include <linker.h> 51 #else 46 52 #include <link.h> 53 #endif 54 #ifndef ANDROID 47 55 #include <elf.h> 56 #endif 48 57 49 58 /* … … 1656 1665 1657 1666 int 1658 main(int argc, char *argv[] 1667 #ifdef CCLSHARED 1668 cclmain 1669 #else 1670 main 1671 #endif 1672 (int argc, char *argv[] 1659 1673 #if defined(PPC) && defined(LINUX) 1660 1674 , char *envp[], void *aux … … 2201 2215 #endif 2202 2216 } 2217 #if defined(LINUX) || defined(FREEBSD) || defined(SOLARIS) 2218 #if WORD_SIZE == 64 2219 typedef Elf64_Dyn Elf_Dyn; 2220 typedef Elf64_Ehdr Elf_Ehdr; 2221 typedef Elf64_Shdr Elf_Shdr; 2222 #else 2223 typedef Elf32_Dyn Elf_Dyn; 2224 typedef Elf32_Ehdr Elf_Ehdr; 2225 typedef Elf32_Shdr Elf_Shdr; 2226 #endif 2227 2228 Elf32_Dyn * 2229 get_executable_dynamic_entries() 2230 { 2231 #ifndef CCLSHARED 2232 extern Elf_Dyn _DYNAMIC[]; 2233 return _DYNAMIC; 2234 #else 2235 #ifdef ANDROID 2236 /* Deep, dark secret: the "handle" returned by dlopen() is 2237 a pointer to an soinfo structure, as defined in linker.h. 2238 We can get the link map from there ... 2239 */ 2240 2241 2242 2243 /* Woe unto us - and lots of it - if the executable is mapped 2244 at an address other than 0x8000. Todo: parse /proc/self/maps. */ 2245 char *p; 2246 Elf_Ehdr *elf_header; 2247 Elf_Shdr *section_header; 2248 int i,fd; 2249 struct stat _stat; 2250 Elf_Dyn *result = NULL; 2251 2252 fd = open("/proc/self/exe",O_RDONLY); 2253 if (fd >= 0) { 2254 if (fstat(fd,&_stat) == 0) { 2255 p = (char *)mmap(NULL,_stat.st_size,PROT_READ,MAP_PRIVATE,fd,0); 2256 if (p != MAP_FAILED) { 2257 elf_header = (Elf_Ehdr *)p; 2258 for (section_header = (Elf_Shdr *)(p+elf_header->e_shoff), 2259 i = 0; 2260 i < elf_header->e_shnum; 2261 i++,section_header++) { 2262 if (section_header->sh_type == SHT_DYNAMIC) { 2263 result = (Elf_Dyn *)section_header->sh_addr; 2264 break; 2265 } 2266 } 2267 munmap(p,_stat.st_size); 2268 } 2269 } 2270 close(fd); 2271 } 2272 return result; 2273 #else 2274 #error need implementation for get_executable_dynamic_entries from dso 2275 #endif 2276 #endif 2277 } 2278 2279 2280 void *cached_r_debug = NULL; 2203 2281 2204 2282 void * 2205 2283 get_r_debug() 2206 2284 { 2207 #if defined(LINUX) || defined(FREEBSD) || defined(SOLARIS)2208 #if WORD_SIZE == 642209 extern Elf64_Dyn _DYNAMIC[];2210 Elf64_Dyn *dp;2211 #else2212 extern Elf32_Dyn _DYNAMIC[];2213 Elf32_Dyn *dp;2214 #endif2215 2285 int tag; 2216 2217 for (dp = _DYNAMIC; (tag = dp->d_tag) != 0; dp++) { 2218 if (tag == DT_DEBUG) { 2219 return (void *)(dp->d_un.d_ptr); 2220 } 2221 } 2222 #endif 2286 Elf_Dyn *dp; 2287 2288 if (cached_r_debug == NULL) { 2289 for (dp = get_executable_dynamic_entries(); (tag = dp->d_tag) != 0; dp++) { 2290 if (tag == DT_DEBUG) { 2291 cached_r_debug = (void *)(dp->d_un.d_ptr); 2292 break; 2293 } 2294 } 2295 } 2296 return cached_r_debug; 2297 } 2298 2299 #else 2300 void * 2301 get_r_debug() 2302 { 2223 2303 return NULL; 2224 2304 } 2225 2305 #endif 2226 2306 2227 2307 #ifdef DARWIN
Note:
See TracChangeset
for help on using the changeset viewer.
