Changeset 15473


Ignore:
Timestamp:
Oct 2, 2012, 1:51:48 AM (7 years ago)
Author:
gb
Message:

Ensure that darwin_sigreturn() is prototyped on platforms where it's
used.

Remove some remaining Mach-isms (notably the paging info stuff used
by GC-VERBOSE; just use getrusage()).

Make sure that the right headers are included in threads.h, to support
the remaining Mach-ism (use of Mach semaphores. Apple still doesn't
implement POSIX semaphores, though the functions have been prototyped
for several years now.)

This builds without warnings or errors on 10.8.1 with Xcode 4.4's
toolchain. It -may- address the problems described in ticket:1019.

Location:
trunk/source/lisp-kernel
Files:
8 edited

Legend:

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

    r14516 r15473  
    1919#ifdef LINUX
    2020#define __USE_GNU 1
     21#endif
     22
     23#ifndef WINDOWS
    2124#include <dlfcn.h>
    2225#endif
    23 
    24 #ifdef DARWIN
    25 #if 0
    26 #undef undefined
    27 #include <stdint.h>
    28 #include <mach-o/dyld.h>
    29 #include <mach-o/nlist.h>
    30 
    31 typedef struct dl_info {
    32   const char      *dli_fname;     /* Pathname of shared object */
    33   void            *dli_fbase;     /* Base address of shared object */
    34   const char      *dli_sname;     /* Name of nearest symbol */
    35   void            *dli_saddr;     /* Address of nearest symbol */
    36 } Dl_info;
    37 
    38 int
    39 darwin_dladdr(void *p, Dl_info *info)
    40 {
    41   unsigned long i;
    42   unsigned long j;
    43   uint32_t count = _dyld_image_count();
    44   struct mach_header *mh = 0;
    45   struct load_command *lc = 0;
    46   unsigned long addr = 0;
    47   unsigned long table_off = (unsigned long)0;
    48   int found = 0;
    49 
    50   if (!info)
    51     return 0;
    52   info->dli_fname = 0;
    53   info->dli_fbase = 0;
    54   info->dli_sname = 0;
    55   info->dli_saddr = 0;
    56   /* Some of this was swiped from code posted by Douglas Davidson
    57    * <ddavidso AT apple DOT com> to darwin-development AT lists DOT
    58    * apple DOT com and slightly modified
    59    */
    60   for (i = 0; i < count; i++) {
    61     addr = (unsigned long)p - _dyld_get_image_vmaddr_slide(i);
    62     mh = (struct mach_header *)_dyld_get_image_header(i);
    63     if (mh) {
    64       lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
    65       for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize)) {
    66         if (LC_SEGMENT == lc->cmd &&
    67             addr >= ((struct segment_command *)lc)->vmaddr &&
    68             addr <
    69             ((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize) {
    70           info->dli_fname = _dyld_get_image_name(i);
    71           info->dli_fbase = (void *)mh;
    72           found = 1;
    73           break;
    74         }
    75       }
    76       if (found) {
    77             break;
    78       }
    79     }
    80   }
    81   if (!found) {
    82     return 0;
    83   }
    84   lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
    85   for (j = 0;
    86        j < mh->ncmds;
    87        j++, lc = (struct load_command *)((char *)lc + lc->cmdsize)) {
    88     if (LC_SEGMENT == lc->cmd) {
    89       if (!strcmp(((struct segment_command *)lc)->segname, "__LINKEDIT"))
    90         break;
    91     }
    92   }
    93   table_off =
    94     ((unsigned long)((struct segment_command *)lc)->vmaddr) -
    95     ((unsigned long)((struct segment_command *)lc)->fileoff) + _dyld_get_image_vmaddr_slide(i);
    96  
    97   lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
    98   for (j = 0;
    99        j < mh->ncmds;
    100        j++, lc = (struct load_command *)((char *)lc + lc->cmdsize)) {
    101     if (LC_SYMTAB == lc->cmd) {
    102       struct nlist *symtable = (struct nlist *)(((struct symtab_command *)lc)->symoff + table_off);
    103       unsigned long numsyms = ((struct symtab_command *)lc)->nsyms;
    104       struct nlist *nearest = NULL;
    105       unsigned long diff = 0xffffffff;
    106       unsigned long strtable = (unsigned long)(((struct symtab_command *)lc)->stroff + table_off);
    107       for (i = 0; i < numsyms; i++) {
    108         /* fprintf(dbgout,"%s : 0x%08x, 0x%x\n",(char *)(strtable + symtable->n_un.n_strx) ,symtable->n_value, symtable->n_type); */
    109         /* Ignore the following kinds of Symbols */
    110         if ((!symtable->n_value)        /* Undefined */
    111             || (symtable->n_type & N_STAB)      /* Debug symbol */
    112             || ((symtable->n_type & N_TYPE) != N_SECT)  /* Absolute, indirect, ... */
    113             ) {
    114           symtable++;
    115           continue;
    116         }
    117         if ((addr >= symtable->n_value) &&
    118             (diff >= addr - (symtable->n_value ))) {
    119           diff = addr- (unsigned long)symtable->n_value;
    120           nearest = symtable;
    121         }
    122         symtable++;
    123       }
    124       if (nearest) {
    125         info->dli_saddr = nearest->n_value + ((void *)p - addr);
    126         info->dli_sname = (char *)(strtable + nearest->n_un.n_strx);
    127       }
    128     }
    129   }
    130   return 1;
    131 }
    132 
    133 #define dladdr darwin_dladdr
    134 #else
    135 #include <dlfcn.h>
    136 #endif
    137 #endif
    138 
    13926
    14027
  • trunk/source/lisp-kernel/gc.h

    r15429 r15473  
    122122#endif
    123123
    124 #ifdef DARWIN
    125 #include <mach/task_info.h>
    126 typedef struct task_events_info paging_info;
    127 #else
    128124#ifndef WINDOWS
    129125#include <sys/resource.h>
     
    131127#else
    132128typedef natural paging_info;
    133 #endif
    134129#endif
    135130
  • trunk/source/lisp-kernel/platform-darwinx8632.h

    r15470 r15473  
    5050#define REG_EIP 10
    5151
     52extern void darwin_sigreturn(ExceptionInformation *,unsigned);
    5253
    5354/* xp accessors, sigreturn stuff */
  • trunk/source/lisp-kernel/platform-darwinx8664.h

    r15470 r15473  
    5757#define REG_RFL 17
    5858
     59extern void darwin_sigreturn(ExceptionInformation *,unsigned);
     60
    5961/* xp accessors, sigreturn stuff */
    6062#define DarwinSigReturn(context) do {\
  • trunk/source/lisp-kernel/plbt.c

    r13067 r15473  
    1919#ifdef LINUX
    2020#define __USE_GNU 1
     21#endif
     22
     23#ifndef WINDOWS
    2124#include <dlfcn.h>
    2225#endif
    23 
    24 #ifdef DARWIN
    25 #if 0
    26 #undef undefined
    27 #include <stdint.h>
    28 #include <mach-o/dyld.h>
    29 #include <mach-o/nlist.h>
    30 
    31 typedef struct dl_info {
    32   const char      *dli_fname;     /* Pathname of shared object */
    33   void            *dli_fbase;     /* Base address of shared object */
    34   const char      *dli_sname;     /* Name of nearest symbol */
    35   void            *dli_saddr;     /* Address of nearest symbol */
    36 } Dl_info;
    37 
    38 int
    39 darwin_dladdr(void *p, Dl_info *info)
    40 {
    41   unsigned long i;
    42   unsigned long j;
    43   uint32_t count = _dyld_image_count();
    44   struct mach_header *mh = 0;
    45   struct load_command *lc = 0;
    46   unsigned long addr = 0;
    47   unsigned long table_off = (unsigned long)0;
    48   int found = 0;
    49 
    50   if (!info)
    51     return 0;
    52   info->dli_fname = 0;
    53   info->dli_fbase = 0;
    54   info->dli_sname = 0;
    55   info->dli_saddr = 0;
    56   /* Some of this was swiped from code posted by Douglas Davidson
    57    * <ddavidso AT apple DOT com> to darwin-development AT lists DOT
    58    * apple DOT com and slightly modified
    59    */
    60   for (i = 0; i < count; i++) {
    61     addr = (unsigned long)p - _dyld_get_image_vmaddr_slide(i);
    62     mh = (struct mach_header *)_dyld_get_image_header(i);
    63     if (mh) {
    64       lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
    65       for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize)) {
    66         if (LC_SEGMENT == lc->cmd &&
    67             addr >= ((struct segment_command *)lc)->vmaddr &&
    68             addr <
    69             ((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize) {
    70           info->dli_fname = _dyld_get_image_name(i);
    71           info->dli_fbase = (void *)mh;
    72           found = 1;
    73           break;
    74         }
    75       }
    76       if (found) {
    77             break;
    78       }
    79     }
    80   }
    81   if (!found) {
    82     return 0;
    83   }
    84   lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
    85   for (j = 0;
    86        j < mh->ncmds;
    87        j++, lc = (struct load_command *)((char *)lc + lc->cmdsize)) {
    88     if (LC_SEGMENT == lc->cmd) {
    89       if (!strcmp(((struct segment_command *)lc)->segname, "__LINKEDIT"))
    90         break;
    91     }
    92   }
    93   table_off =
    94     ((unsigned long)((struct segment_command *)lc)->vmaddr) -
    95     ((unsigned long)((struct segment_command *)lc)->fileoff) + _dyld_get_image_vmaddr_slide(i);
    96  
    97   lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
    98   for (j = 0;
    99        j < mh->ncmds;
    100        j++, lc = (struct load_command *)((char *)lc + lc->cmdsize)) {
    101     if (LC_SYMTAB == lc->cmd) {
    102       struct nlist *symtable = (struct nlist *)(((struct symtab_command *)lc)->symoff + table_off);
    103       unsigned long numsyms = ((struct symtab_command *)lc)->nsyms;
    104       struct nlist *nearest = NULL;
    105       unsigned long diff = 0xffffffff;
    106       unsigned long strtable = (unsigned long)(((struct symtab_command *)lc)->stroff + table_off);
    107       for (i = 0; i < numsyms; i++) {
    108         /* fprintf(dbgout,"%s : 0x%08x, 0x%x\n",(char *)(strtable + symtable->n_un.n_strx) ,symtable->n_value, symtable->n_type); */
    109         /* Ignore the following kinds of Symbols */
    110         if ((!symtable->n_value)        /* Undefined */
    111             || (symtable->n_type & N_STAB)      /* Debug symbol */
    112             || ((symtable->n_type & N_TYPE) != N_SECT)  /* Absolute, indirect, ... */
    113             ) {
    114           symtable++;
    115           continue;
    116         }
    117         if ((addr >= symtable->n_value) &&
    118             (diff >= addr - (symtable->n_value ))) {
    119           diff = addr- (unsigned long)symtable->n_value;
    120           nearest = symtable;
    121         }
    122         symtable++;
    123       }
    124       if (nearest) {
    125         info->dli_saddr = nearest->n_value + ((void *)p - addr);
    126         info->dli_sname = (char *)(strtable + nearest->n_un.n_strx);
    127       }
    128     }
    129   }
    130   return 1;
    131 }
    132 
    133 #define dladdr darwin_dladdr
    134 #else
    135 #include <dlfcn.h>
    136 #endif
    137 #endif
    138 
    13926
    14027
  • trunk/source/lisp-kernel/pmcl-kernel.c

    r15470 r15473  
    24722472#endif
    24732473
    2474 #ifdef DARWIN
    2475 void
    2476 sample_paging_info(paging_info *stats)
    2477 {
    2478   mach_msg_type_number_t count = TASK_EVENTS_INFO_COUNT;
    2479 
    2480   task_info(mach_task_self(),
    2481             TASK_EVENTS_INFO,
    2482             (task_info_t)stats,
    2483             &count);
    2484 }
    2485 
    2486 void
    2487 report_paging_info_delta(FILE *out, paging_info *start, paging_info *stop)
    2488 {
    2489   fprintf(out,";;; %d soft faults, %d faults, %d pageins\n\n",
    2490           stop->cow_faults-start->cow_faults,
    2491           stop->faults-start->faults,
    2492           stop->pageins-start->pageins);
    2493 }
    2494 
    2495 #else
    24962474#ifdef WINDOWS
    24972475void
     
    25202498}
    25212499
    2522 #endif
    25232500#endif
    25242501
  • trunk/source/lisp-kernel/thread_manager.c

    r15470 r15473  
    27012701
    27022702
    2703 #ifdef DARWIN
    2704 /* For debugging. */
    2705 int
    2706 mach_port_send_refs(mach_port_t port)
    2707 {
    2708   mach_port_urefs_t nrefs;
    2709   ipc_space_t task = mach_task_self();
    2710  
    2711   if (mach_port_get_refs(task,port,MACH_PORT_RIGHT_SEND,&nrefs) == KERN_SUCCESS) {
    2712     return nrefs;
    2713   }
    2714   return -1;
    2715 }
    2716 #endif
    2717 
     2703
  • trunk/source/lisp-kernel/threads.h

    r14930 r15473  
    6868/* We have to use Mach semaphores, even if we're otherwise
    6969   using POSIX signals, etc. */
     70#include <mach/mach_init.h>
    7071#include <mach/task.h>
    7172#include <mach/semaphore.h>
Note: See TracChangeset for help on using the changeset viewer.