/[cmucl]/src/lisp/FreeBSD-os.c
ViewVC logotype

Diff of /src/lisp/FreeBSD-os.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by gerd, Sun Mar 23 21:23:41 2003 UTC revision 1.10.12.1 by rtoy, Mon Dec 19 01:10:11 2005 UTC
# Line 47  int errno; Line 47  int errno;
47  #endif  #endif
48    
49  vm_size_t os_vm_page_size;  vm_size_t os_vm_page_size;
   
50    
51    
52  void  void
53  os_init (void)  os_init(void)
54  {  {
55    os_vm_page_size = getpagesize ();      os_vm_page_size = getpagesize();
56  }  }
57    
58  int  int
59  sc_reg (struct sigcontext *c, int offset)  sc_reg(struct sigcontext *c, int offset)
60  {  {
61    switch(offset)      switch (offset) {
62      {        case 0:
63      case  0: return c->sc_eax;            return c->sc_eax;
64      case  2: return c->sc_ecx;        case 2:
65      case  4: return c->sc_edx;            return c->sc_ecx;
66      case  6: return c->sc_ebx;        case 4:
67      case  8: return c->sc_esp;            return c->sc_edx;
68      case 10: return c->sc_ebp;        case 6:
69      case 12: return c->sc_esi;            return c->sc_ebx;
70      case 14: return c->sc_edi;        case 8:
71              return c->sc_esp;
72          case 10:
73              return c->sc_ebp;
74          case 12:
75              return c->sc_esi;
76          case 14:
77              return c->sc_edi;
78      }      }
79    
80    return 0;      return 0;
81  }  }
82    
83  void  void
84  os_save_context (void)  os_save_context(void)
85  {  {
86    /* Called from interrupt handlers so C stuff knows things set in      /* Called from interrupt handlers so C stuff knows things set in
87       Lisp.  */         Lisp.  */
88  }  }
89    
90  void  void
91  os_set_context (void)  os_set_context(void)
92  {  {
93  }  }
94    
95  os_vm_address_t  os_vm_address_t os_validate(os_vm_address_t addr, os_vm_size_t len)
 os_validate (os_vm_address_t addr, os_vm_size_t len)  
96  {  {
97    int flags = MAP_PRIVATE | MAP_ANONYMOUS;      int flags = MAP_PRIVATE | MAP_ANONYMOUS;
98    
99    if (addr)      if (addr)
100      flags |= MAP_FIXED;          flags |= MAP_FIXED;
101    else      else
102      flags |= MAP_VARIABLE;          flags |= MAP_VARIABLE;
103    
104    addr = mmap (addr, len, OS_VM_PROT_ALL, flags, -1, 0);      addr = mmap(addr, len, OS_VM_PROT_ALL, flags, -1, 0);
105    
106    if (addr == (os_vm_address_t) -1)      if (addr == (os_vm_address_t) - 1) {
107      {          perror("mmap");
108        perror ("mmap");          return NULL;
       return NULL;  
109      }      }
110    
111    return addr;      return addr;
112  }  }
113    
114  void  void
115  os_invalidate (os_vm_address_t addr, os_vm_size_t len)  os_invalidate(os_vm_address_t addr, os_vm_size_t len)
116  {  {
117    if (munmap (addr, len) == -1)      if (munmap(addr, len) == -1)
118      perror ("munmap");          perror("munmap");
119  }  }
120    
121  os_vm_address_t  os_vm_address_t
122  os_map (int fd, int offset, os_vm_address_t addr,  os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len)
         os_vm_size_t len)  
123  {  {
124    addr = mmap (addr, len, OS_VM_PROT_ALL,      addr = mmap(addr, len, OS_VM_PROT_ALL,
125                 MAP_PRIVATE | MAP_FILE | MAP_FIXED,                  MAP_PRIVATE | MAP_FILE | MAP_FIXED, fd, (off_t) offset);
                fd, (off_t) offset);  
126    
127    if (addr == (os_vm_address_t) -1)      if (addr == (os_vm_address_t) - 1)
128      perror ("mmap");          perror("mmap");
129    
130    return addr;      return addr;
131  }  }
132    
133  void  void
134  os_flush_icache (os_vm_address_t address, os_vm_size_t length)  os_flush_icache(os_vm_address_t address, os_vm_size_t length)
135  {  {
136  }  }
137    
138  void  void
139  os_protect (os_vm_address_t address, os_vm_size_t length,  os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot)
             os_vm_prot_t prot)  
140  {  {
141    if (mprotect (address, length, prot) == -1)      if (mprotect(address, length, prot) == -1)
142      perror ("mprotect");          perror("mprotect");
143  }  }
   
144    
145    
146    
147  static boolean  static boolean
148  in_range_p (os_vm_address_t a, lispobj sbeg, size_t slen)  in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen)
149  {  {
150    char *beg = (char *) sbeg;      char *beg = (char *) sbeg;
151    char *end = (char *) sbeg + slen;      char *end = (char *) sbeg + slen;
152    char *adr = (char *) a;      char *adr = (char *) a;
153    return adr >= beg && adr < end;  
154        return adr >= beg && adr < end;
155  }  }
156    
157  boolean  boolean valid_addr(os_vm_address_t addr)
 valid_addr (os_vm_address_t addr)  
158  {  {
159    int ret;      int ret;
160    os_vm_address_t newaddr;      os_vm_address_t newaddr;
   newaddr = os_trunc_to_page (addr);  
161    
162    if (in_range_p (addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE)      newaddr = os_trunc_to_page(addr);
163        || in_range_p (addr, STATIC_SPACE_START , STATIC_SPACE_SIZE)  
164        || in_range_p (addr, DYNAMIC_0_SPACE_START, dynamic_space_size)      if (in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE)
165            || in_range_p(addr, STATIC_SPACE_START, STATIC_SPACE_SIZE)
166            || in_range_p(addr, DYNAMIC_0_SPACE_START, dynamic_space_size)
167  #ifndef GENCGC  #ifndef GENCGC
168        || in_range_p (addr, DYNAMIC_1_SPACE_START, dynamic_space_size)          || in_range_p(addr, DYNAMIC_1_SPACE_START, dynamic_space_size)
169  #endif  #endif
170        || in_range_p (addr, CONTROL_STACK_START, CONTROL_STACK_SIZE)          || in_range_p(addr, CONTROL_STACK_START, CONTROL_STACK_SIZE)
171        || in_range_p (addr, BINDING_STACK_START, BINDING_STACK_SIZE))          || in_range_p(addr, BINDING_STACK_START, BINDING_STACK_SIZE))
172      return TRUE;          return TRUE;
173    return FALSE;      return FALSE;
174  }  }
   
175    
176    
177  static void  static void
178  sigbus_handler (int signal, int code, struct sigcontext *context,  sigbus_handler(int signal, int code, struct sigcontext *context,
179                  void *fault_addr)                 void *fault_addr)
180  {  {
181    int page_index;      int page_index;
182    
183  #ifdef RED_ZONE_HIT  #ifdef RED_ZONE_HIT
184    if (os_control_stack_overflow (fault_addr, context))      if (os_control_stack_overflow(fault_addr, context))
185      return;          return;
186  #endif  #endif
187    
188  #if defined GENCGC  #if defined GENCGC
189    page_index = find_page_index(fault_addr);      page_index = find_page_index(fault_addr);
190    
191    /* Check if the fault is within the dynamic space. */      /* Check if the fault is within the dynamic space. */
192    if (page_index != -1)      if (page_index != -1) {
193      {          /* Un-protect the page */
194        /* Un-protect the page */  
195            /* The page should have been marked write protected */
196        /* The page should have been marked write protected */          if (!PAGE_WRITE_PROTECTED(page_index))
197        if (!PAGE_WRITE_PROTECTED (page_index))              fprintf(stderr,
198          fprintf (stderr, "*** Sigbus in page not marked as write protected\n");                      "*** Sigbus in page not marked as write protected\n");
199    
200        os_protect (page_address (page_index), 4096, OS_VM_PROT_ALL);          os_protect(page_address(page_index), 4096, OS_VM_PROT_ALL);
201        page_table[page_index].flags &= ~PAGE_WRITE_PROTECTED_MASK;          page_table[page_index].flags &= ~PAGE_WRITE_PROTECTED_MASK;
202        page_table[page_index].flags |= PAGE_WRITE_PROTECT_CLEARED_MASK;          page_table[page_index].flags |= PAGE_WRITE_PROTECT_CLEARED_MASK;
203    
204        return;          return;
205      }      }
206  #endif /* GENCGC */  #endif /* GENCGC */
207    
208    interrupt_handle_now (signal, code, context);      interrupt_handle_now(signal, code, context);
209  }  }
210    
211  static void  static void
212  sigsegv_handler (int signal, int code, struct sigcontext *context)  sigsegv_handler(int signal, int code, struct sigcontext *context)
213  {  {
214    interrupt_handle_now (signal, code, context);      interrupt_handle_now(signal, code, context);
215  }  }
216    
217  void  void
218  os_install_interrupt_handlers (void)  os_install_interrupt_handlers(void)
219  {  {
220    interrupt_install_low_level_handler      interrupt_install_low_level_handler
221      (SIGSEGV, (void (*) (HANDLER_ARGS)) sigsegv_handler);          (SIGSEGV, (void (*)(HANDLER_ARGS)) sigsegv_handler);
222    interrupt_install_low_level_handler      interrupt_install_low_level_handler
223      (SIGBUS, (void (*) (HANDLER_ARGS)) sigbus_handler);          (SIGBUS, (void (*)(HANDLER_ARGS)) sigbus_handler);
224  }  }
225    
226  void *  void *
227  os_dlsym (const char *sym_name, lispobj lib_list)  os_dlsym(const char *sym_name, lispobj lib_list)
228  {  {
229    if (lib_list != NIL)      if (lib_list != NIL) {
230      {          lispobj lib_list_head;
231        lispobj lib_list_head;  
232            for (lib_list_head = lib_list;
233        for (lib_list_head = lib_list;               lib_list_head != NIL; lib_list_head = CONS(lib_list_head)->cdr) {
234             lib_list_head != NIL;              struct cons *lib_cons = CONS(CONS(lib_list_head)->car);
235             lib_list_head = CONS (lib_list_head)->cdr)              struct sap *dlhandle = (struct sap *) PTR(lib_cons->car);
236          {              void *sym_addr = dlsym((void *) dlhandle->pointer, sym_name);
           struct cons *lib_cons = CONS (CONS (lib_list_head)->car);  
           struct sap *dlhandle = (struct sap *) PTR (lib_cons->car);  
           void *sym_addr = dlsym ((void *) dlhandle->pointer, sym_name);  
237    
238            if (sym_addr)              if (sym_addr)
239              return sym_addr;                  return sym_addr;
240          }          }
241      }      }
242    
243    return dlsym (RTLD_DEFAULT, sym_name);      return dlsym(RTLD_DEFAULT, sym_name);
244  }  }

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.10.12.1

  ViewVC Help
Powered by ViewVC 1.1.5