Changeset 14572


Ignore:
Timestamp:
Jan 10, 2011, 8:12:15 AM (8 years ago)
Author:
gb
Message:

main->cclmain if CCLSHARED is defined.

Hair up get_r_debug() a lot; most of the code has to do with the
difficulty in finding the executable's dynamic section from a
shared lib.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/pmcl-kernel.c

    r14529 r14572  
    4444#include <sys/time.h>
    4545#include <sys/resource.h>
     46#ifdef ANDROID
     47#ifdef ARM
     48#define ANDROID_ARM_LINKER 1
     49#endif
     50#include <linker.h>
     51#else
    4652#include <link.h>
     53#endif
     54#ifndef ANDROID
    4755#include <elf.h>
     56#endif
    4857
    4958/*
     
    16561665
    16571666int
    1658 main(int argc, char *argv[]
     1667#ifdef CCLSHARED
     1668cclmain
     1669#else
     1670main
     1671#endif
     1672(int argc, char *argv[]
    16591673#if defined(PPC) && defined(LINUX)
    16601674, char *envp[], void *aux
     
    22012215#endif
    22022216}
     2217#if defined(LINUX) || defined(FREEBSD) || defined(SOLARIS)
     2218#if WORD_SIZE == 64
     2219typedef Elf64_Dyn Elf_Dyn;
     2220typedef Elf64_Ehdr Elf_Ehdr;
     2221typedef Elf64_Shdr Elf_Shdr;
     2222#else
     2223typedef Elf32_Dyn Elf_Dyn;
     2224typedef Elf32_Ehdr Elf_Ehdr;
     2225typedef Elf32_Shdr Elf_Shdr;
     2226#endif
     2227
     2228Elf32_Dyn *
     2229get_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
     2280void *cached_r_debug = NULL;
    22032281
    22042282void *
    22052283get_r_debug()
    22062284{
    2207 #if defined(LINUX) || defined(FREEBSD) || defined(SOLARIS)
    2208 #if WORD_SIZE == 64
    2209   extern Elf64_Dyn _DYNAMIC[];
    2210   Elf64_Dyn *dp;
    2211 #else
    2212   extern Elf32_Dyn _DYNAMIC[];
    2213   Elf32_Dyn *dp;
    2214 #endif
    22152285  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
     2300void *
     2301get_r_debug()
     2302{
    22232303  return NULL;
    22242304}
    2225 
     2305#endif
    22262306
    22272307#ifdef DARWIN
Note: See TracChangeset for help on using the changeset viewer.