/[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.1 by ram, Tue Jan 21 00:28:13 1997 UTC revision 1.2 by dtc, Tue Nov 25 17:59:16 1997 UTC
# Line 10  Line 10 
10   *   *
11   * This is the OSF1 version.  By Sean Hallgren.   * This is the OSF1 version.  By Sean Hallgren.
12   * Much hacked by Paul Werkowski   * Much hacked by Paul Werkowski
13     * GENCGC support by Douglas Crosher, 1996, 1997.
14     *
15     * $Header$
16   *   *
17   */   */
18    
19  #include <stdio.h>  #include <stdio.h>
 #include <unistd.h>  
 #include <sys/types.h>  
 #include <sys/param.h>  
 #include <signal.h>  
 #include <sys/user.h>  
 #include <sys/ptrace.h>  
 #include <sys/wait.h>  
20  #include <sys/param.h>  #include <sys/param.h>
21  #include <sys/file.h>  #include <sys/file.h>
 #include <sys/proc.h>  
22  #include <errno.h>  #include <errno.h>
23  #include "./signal.h"  #include "./signal.h"
24  #include "os.h"  #include "os.h"
# Line 33  Line 28 
28  #include "lispregs.h"  #include "lispregs.h"
29  #include "internals.h"  #include "internals.h"
30    
31    #include <sys/types.h>
32    #include <signal.h>
33    /* #include <sys/sysinfo.h> */
34    #include <sys/proc.h>
35  #include "x86-validate.h"  #include "x86-validate.h"
36  vm_size_t os_vm_page_size;  vm_size_t os_vm_page_size;
37  #define DPRINTF(t,a) {if(t)fprintf a;}  #define DPRINTF(t,a) {if(t)fprintf a;}
# Line 45  vm_size_t os_vm_page_size; Line 44  vm_size_t os_vm_page_size;
44  #if defined USE_SIG_STACK  #if defined USE_SIG_STACK
45  static double estack_buf[SIG_STACK_SIZE];  static double estack_buf[SIG_STACK_SIZE];
46  #endif  #endif
47    
48    #if defined GENCGC
49    #include "gencgc.h"
50    #endif
51    
52    
53  void  void
54  os_init()  os_init()
# Line 111  void Line 115  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    DPRINTF(0,(stderr,"os_invalidate %x %d\n",addr,len));    DPRINTF(0,(stderr,"os_invalidate %x %d\n",addr,len));
118    if(munmap(addr,len) == -1)    if(munmap(addr,len) == -1) {
119        fprintf(stderr,"munmap(0x%x,%d)==-1\n",addr,len);
120      perror("munmap");      perror("munmap");
121      }
122  }  }
123    
124  os_vm_address_t  os_vm_address_t
# Line 164  valid_addr(os_vm_address_t addr) Line 170  valid_addr(os_vm_address_t addr)
170    
171    
172  static void  static void
173  sigbus_handler(int signal, int code, struct sigcontext *context)  sigbus_handler(int signal, int code, struct sigcontext *context,
174                   void *fault_addr)
175  {  {
176    DPRINTF(0,(stderr,"sigbus:\n"));  #if defined GENCGC
177  #if defined NOTYET    int  page_index = find_page_index(fault_addr);
178    if(!interrupt_maybe_gc(signal, code, context))  
179    #if SIGBUS_VERBOSE
180      fprintf(stderr,"Signal %d, fault_addr=%x, page_index=%d:\n",
181              signal,fault_addr,page_index);
182    #endif
183    
184      /* Check if the fault is within the dynamic space. */
185      if (page_index != -1) {
186          /* Un-protect the page */
187    
188          /* The page should have been marked write_protected */
189          if (page_table[page_index].write_protected != 1)
190            fprintf(stderr,"*** Sigbus in page not marked as write protected");
191    
192          os_protect(page_address(page_index), 4096, OS_VM_PROT_ALL);
193          page_table[page_index].write_protected = 0;
194          page_table[page_index].write_protected_cleared = 1;
195    
196    #if SIGBUS_VERBOSE
197          fprintf(stderr,"* page: gen=%d bytes_used=%d first_object_offset=%d dont_move=%d\n",
198                  page_table[page_index].gen,
199                  page_table[page_index].bytes_used,
200                  page_table[page_index].first_object_offset,
201                  page_table[page_index].dont_move);
202          fprintf(stderr,"* data: %x %x %x %x\n",
203                  *(((long *)fault_addr)-1),
204                  *(((long *)fault_addr)-0),
205                  *(((long *)fault_addr)+1),
206                  *(((long *)fault_addr)+2));
207          {
208            int  pi2 = find_page_index(*(((long *)fault_addr)-0));
209    
210            if ( pi2!=-1 )
211              fprintf(stderr,"* pi2: gen=%d bytes_used=%d first_object_offset=%d dont_move=%d\n",
212                      page_table[pi2].gen,
213                      page_table[pi2].bytes_used,
214                      page_table[pi2].first_object_offset,
215                      page_table[pi2].dont_move);
216          }
217  #endif  #endif
218      interrupt_handle_now(signal, code, context);  
219          return;
220        }
221    #endif
222    
223      DPRINTF(0,(stderr,"sigbus:\n"));
224      interrupt_handle_now(signal, code, context);
225  }  }
226  static void  static void
227  sigsegv_handler(int signal, int code, struct sigcontext *context)  sigsegv_handler(int signal, int code, struct sigcontext *context)
228  {  {
229    DPRINTF(0,(stderr,"os_sigsegv\n"));    DPRINTF(0,(stderr,"os_sigsegv\n"));
230  #if defined NOTYET    interrupt_handle_now(signal, code, context);
   if(!interrupt_maybe_gc(signal, code, context))  
 #endif  
     interrupt_handle_now(signal, code, context);  
231  }  }
232    
233  void  void
# Line 188  os_install_interrupt_handlers(void) Line 236  os_install_interrupt_handlers(void)
236    interrupt_install_low_level_handler(SIGSEGV,sigsegv_handler);    interrupt_install_low_level_handler(SIGSEGV,sigsegv_handler);
237    interrupt_install_low_level_handler(SIGBUS,sigbus_handler);    interrupt_install_low_level_handler(SIGBUS,sigbus_handler);
238  }  }
   
   
 /* All this is needed to get the floating-point status register  
  * that was stuffed in process context on a SIGFPE. We need it  
  * to determine what kind of condition occured. This code also  
  * sets up the possibility of defining some local structs to  
  * make up for lack of sigcontext registers and have a low level  
  * SIGFPE handler dummy something up.  
  */  
 #ifdef not_now_maybe_not_ever  
 struct user u;  
 unsigned int  
 BSD_get_fp_modes()  
 {  
   /* All this is highly dependent on FreeBSD internals. Watch Out! */  
   /* offset to where NPX state is saved in a process */  
   unsigned int fpoff = (char*)&u.u_pcb.pcb_savefpu - (char*)&u;  
   unsigned int fplen = sizeof u.u_pcb.pcb_savefpu / sizeof(int);  
   /* offset to the last exception status word */  
   unsigned int swoff = (char*)&u.u_pcb.pcb_savefpu.sv_ex_sw - (char*)&u;  
   pid_t pid;  
   /* fork to capture NPX state in another process */  
   pid =  fork();  
   if(pid)  
     {  
       u_long ex_sw, ex_cw;  
       int status;  
       printf("p: wait1\n"); fflush(stdout);  
       wait4(pid, &status, WUNTRACED, NULL);  
       printf("P: wait over\n"); fflush(stdout);  
       ex_sw = ptrace(PT_READ_U, pid, (caddr_t)swoff, 0);  
       if(ex_sw == -1)  
         perror("ptrace");  
       {  
         /* Might as well get the rest  of the saved state. */  
         int i, *ip = (int*)&u.u_pcb.pcb_savefpu;  
         unsigned int*uaddr = (unsigned int*)fpoff;  
         for(i=0; i<fplen; i++, uaddr++)  
           *ip++ = ptrace(PT_READ_U, pid, (caddr_t)uaddr, 0);  
         ex_cw = u.u_pcb.pcb_savefpu.sv_env.en_cw & 0xffff;  
       }  
       printf("sw %x cw %x\n",ex_sw,ex_cw); fflush(stdout);  
       printf("p: Kill\n"); fflush(stdout);  
       ptrace(PT_CONTINUE, pid, NULL, 0);  
       printf("p: wait2\n"); fflush(stdout);  
       wait4(pid, &status, 0, NULL);  
       printf("p: wait over\n"); fflush(stdout);  
       ex_sw &= 0xffff;  
       ex_cw &= 0xffff;  
       ex_cw ^= 0x3f;  
       return (ex_sw << 16) | ex_cw ;  
     }  
   else  
     {  
       /* As child, notify OS to allow ptrace calls */  
       int status = ptrace(PT_TRACE_ME, getpid(), NULL, 0);  
       if(status == -1)  
         perror("kid");  
       printf("c:\n"); fflush(stdout);  
       /* Go idle so parent can poke at process contents. */  
       raise(SIGSTOP);  
       printf("c: stopped?\n");  
       while(0)  
         { sigsuspend(0); printf("c:\n"); fflush(stdout); }  
       exit(1);  
     }  
 }  
 #endif  
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.5