/[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.4 by dtc, Wed Aug 25 14:25:06 1999 UTC revision 1.5 by dtc, Mon Nov 29 17:04:07 1999 UTC
# Line 34  Line 34 
34  #include <sys/proc.h>  #include <sys/proc.h>
35  #include "validate.h"  #include "validate.h"
36  vm_size_t os_vm_page_size;  vm_size_t os_vm_page_size;
 #define DPRINTF(t,a) {if(t)fprintf a;}  
37    
38  #define HAVE_SIGVEC             /* defined  - now obsolete */  #define DPRINTF(t,a) {if (t) fprintf a;}
 #define HAVE_SIGACTION          /* replacement for SIGVEC          */  
 /* SIGSTKSZ == 40Kb */  
 #define SIG_STACK_SIZE (SIGSTKSZ/sizeof(double))  
 /* make sure the stack is 8 byte aligned */  
 #if defined USE_SIG_STACK  
 static double estack_buf[SIG_STACK_SIZE];  
 #endif  
39    
40  #if defined GENCGC  #if defined GENCGC
41  #include "gencgc.h"  #include "gencgc.h"
42  #endif  #endif
43    
44    
45  void  void os_init(void)
 os_init()  
46  {  {
47      os_vm_page_size = OS_VM_DEFAULT_PAGESIZE;
 #if defined USE_SIG_STACK  
   static struct sigaltstack estack;  
   estack.ss_base = (char*)estack_buf; /* this should be ss_sp */  
   estack.ss_size = SIGSTKSZ;  
   estack.ss_flags = 0;  
   if (sigaltstack(&estack, 0) < 0)  
     perror("sigaltstack");  
 #endif  
   os_vm_page_size=OS_VM_DEFAULT_PAGESIZE;  
48  }  }
49    
50  int  int sc_reg(struct sigcontext *c, int offset)
 sc_reg(struct sigcontext *c, int offset)  
51  {  {
52    switch(offset)    switch(offset)
53      {      {
# Line 81  sc_reg(struct sigcontext *c, int offset) Line 62  sc_reg(struct sigcontext *c, int offset)
62      }      }
63    return 0;    return 0;
64  }  }
65  void  
66  os_save_context()  void os_save_context(void)
67  {  {
68    /* Called from interrupt handlers so C stuff knows things set in Lisp    /*
69       * Called from interrupt handlers so C stuff knows things set in Lisp.
70     */     */
71  }  }
72  void  
73  os_set_context()  void os_set_context(void)
74  {  {
75  }  }
76    
77  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)  
78  {  {
79    int flags = MAP_PRIVATE|MAP_ANONYMOUS;    int flags = MAP_PRIVATE | MAP_ANONYMOUS;
80    
81      if (addr)
82        flags |= MAP_FIXED;
83      else
84        flags |= MAP_VARIABLE;
85    
86    if(addr) flags|=MAP_FIXED;    DPRINTF(0, (stderr, "os_validate %x %d => ", addr, len));
   else flags|=MAP_VARIABLE;  
87    
88    DPRINTF(0,(stderr,"os_validate %x %d => ",addr,len));    addr = mmap(addr, len, OS_VM_PROT_ALL, flags, -1, 0);
89    if((addr=mmap(addr,len,OS_VM_PROT_ALL,flags,-1,0)) == (os_vm_address_t) -1)  
90      if (addr == (os_vm_address_t) -1)
91      {      {
92        perror("mmap");        perror("mmap");
93        return NULL;        return NULL;
94      }      }
95    DPRINTF(0,(stderr,"%x\n",addr));  
96      DPRINTF(0, (stderr, "%x\n", addr));
97    
98    return addr;    return addr;
99  }  }
100    
101  void  void os_invalidate(os_vm_address_t addr, os_vm_size_t len)
 os_invalidate(os_vm_address_t addr, os_vm_size_t len)  
102  {  {
103    DPRINTF(0,(stderr,"os_invalidate %x %d\n",addr,len));    DPRINTF(0, (stderr, "os_invalidate %x %d\n", addr, len));
104    if(munmap(addr,len) == -1) {  
105      fprintf(stderr,"munmap(0x%x,%d)==-1\n",addr,len);    if (munmap(addr, len) == -1)
106      perror("munmap");      perror("munmap");
   }  
107  }  }
108    
109  os_vm_address_t  os_vm_address_t os_map(int fd, int offset, os_vm_address_t addr,
110  os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len)                         os_vm_size_t len)
111  {  {
112    if((addr=mmap(addr,len,OS_VM_PROT_ALL,MAP_PRIVATE|MAP_FILE|MAP_FIXED,fd,    addr = mmap(addr, len,
113                  (off_t) offset)) == (os_vm_address_t) -1)                OS_VM_PROT_ALL,
114                  MAP_PRIVATE | MAP_FILE | MAP_FIXED,
115                  fd, (off_t) offset);
116    
117      if (addr == (os_vm_address_t) -1)
118      perror("mmap");      perror("mmap");
119    
120    return addr;    return addr;
121  }  }
122    
123  void  void 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)  
124  {  {
125  }  }
126    
127  void  void os_protect(os_vm_address_t address, os_vm_size_t length,
128  os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot)                  os_vm_prot_t prot)
129  {  {
130    if(mprotect(address, length, prot) == -1)    if (mprotect(address, length, prot) == -1)
131      perror("mprotect");      perror("mprotect");
132  }  }
133    
134    
135  static boolean  
136  in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen)  static boolean in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen)
137  {  {
138    char* beg = (char*)sbeg;    char* beg = (char*) sbeg;
139    char* end = (char*)sbeg + slen;    char* end = (char*) sbeg + slen;
140    char* adr = (char*)a;    char* adr = (char*) a;
141    return (adr >= beg && adr < end);    return (adr >= beg && adr < end);
142  }  }
143  boolean  
144  valid_addr(os_vm_address_t addr)  boolean valid_addr(os_vm_address_t addr)
145  {  {
146    int ret;    int ret;
147    os_vm_address_t newaddr;    os_vm_address_t newaddr;
148    newaddr=os_trunc_to_page(addr);    newaddr = os_trunc_to_page(addr);
149    
150    if(   in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE)    if (   in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE)
151       || in_range_p(addr, STATIC_SPACE_START   , STATIC_SPACE_SIZE   )        || in_range_p(addr, STATIC_SPACE_START   , STATIC_SPACE_SIZE   )
152       || in_range_p(addr, DYNAMIC_0_SPACE_START, DYNAMIC_SPACE_SIZE  )        || in_range_p(addr, DYNAMIC_0_SPACE_START, DYNAMIC_SPACE_SIZE  )
153       || in_range_p(addr, DYNAMIC_1_SPACE_START, DYNAMIC_SPACE_SIZE  )        || in_range_p(addr, DYNAMIC_1_SPACE_START, DYNAMIC_SPACE_SIZE  )
154       || in_range_p(addr, CONTROL_STACK_START  , CONTROL_STACK_SIZE  )        || in_range_p(addr, CONTROL_STACK_START  , CONTROL_STACK_SIZE  )
155       || in_range_p(addr, BINDING_STACK_START  , BINDING_STACK_SIZE  ))        || in_range_p(addr, BINDING_STACK_START  , BINDING_STACK_SIZE  ))
156      return TRUE;      return TRUE;
157    return FALSE;    return FALSE;
158  }  }
159    
160    
161  static void  static void sigbus_handler(int signal, int code, struct sigcontext *context,
162  sigbus_handler(int signal, int code, struct sigcontext *context,                             void *fault_addr)
                void *fault_addr)  
163  {  {
164  #if defined GENCGC  #if defined GENCGC
165    int  page_index = find_page_index(fault_addr);    int  page_index = find_page_index(fault_addr);
166    
167  #if SIGBUS_VERBOSE  #if SIGBUS_VERBOSE
168    fprintf(stderr,"Signal %d, fault_addr=%x, page_index=%d:\n",    fprintf(stderr,"Signal %d, fault_addr=%x, page_index=%d:\n",
169            signal,fault_addr,page_index);            signal, fault_addr, page_index);
170  #endif  #endif
171    
172    /* Check if the fault is within the dynamic space. */    /* Check if the fault is within the dynamic space. */
173    if (page_index != -1) {    if (page_index != -1) {
174      /* Un-protect the page */      /* Un-protect the page */
175    
176      /* The page should have been marked write_protected */      /* The page should have been marked write protected */
177      if (!PAGE_WRITE_PROTECTED(page_index))      if (!PAGE_WRITE_PROTECTED(page_index))
178        fprintf(stderr,"*** Sigbus in page not marked as write protected");        fprintf(stderr, "*** Sigbus in page not marked as write protected\n");
179    
180      os_protect(page_address(page_index), 4096, OS_VM_PROT_ALL);      os_protect(page_address(page_index), 4096, OS_VM_PROT_ALL);
181      page_table[page_index].flags &= ~PAGE_WRITE_PROTECTED_MASK;      page_table[page_index].flags &= ~PAGE_WRITE_PROTECTED_MASK;
182      page_table[page_index].flags |= PAGE_WRITE_PROTECT_CLEARED_MASK;      page_table[page_index].flags |= PAGE_WRITE_PROTECT_CLEARED_MASK;
183    
184      return;      return;
185      }      }
186  #endif  #endif
187    
188    DPRINTF(0,(stderr,"sigbus:\n"));    DPRINTF(0, (stderr, "sigbus:\n"));
189    interrupt_handle_now(signal, code, context);    interrupt_handle_now(signal, code, context);
190  }  }
191  static void  
192  sigsegv_handler(int signal, int code, struct sigcontext *context)  static void sigsegv_handler(int signal, int code, struct sigcontext *context)
193  {  {
194    DPRINTF(0,(stderr,"os_sigsegv\n"));    DPRINTF(0, (stderr, "os_sigsegv\n"));
195    interrupt_handle_now(signal, code, context);    interrupt_handle_now(signal, code, context);
196  }  }
197    
198  void  void os_install_interrupt_handlers(void)
 os_install_interrupt_handlers(void)  
199  {  {
200    interrupt_install_low_level_handler(SIGSEGV,sigsegv_handler);    interrupt_install_low_level_handler(SIGSEGV, sigsegv_handler);
201    interrupt_install_low_level_handler(SIGBUS,sigbus_handler);    interrupt_install_low_level_handler(SIGBUS, sigbus_handler);
202  }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.5