/[gcl]/gcl/o/main.c
ViewVC logotype

Diff of /gcl/o/main.c

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

revision 1.57 by camm, Sat Apr 9 14:00:31 2005 UTC revision 1.58 by camm, Fri Jun 10 15:30:42 2005 UTC
# Line 79  int    initflag          = FALSE;              /* in Line 79  int    initflag          = FALSE;              /* in
79  int    raw_image         = FALSE;               /* raw or saved image */  int    raw_image         = FALSE;               /* raw or saved image */
80    
81  int    stack_multiple    = 1;  int    stack_multiple    = 1;
 unsigned int cssize      = 0;  
82    
83  extern bool saving_system;  extern bool saving_system;
84  extern long real_maxpage;  extern long real_maxpage;
# Line 93  object sSAmultiply_stacksA; Line 92  object sSAmultiply_stacksA;
92    
93  static object stack_space;  static object stack_space;
94    
95    /*FIXME: all ports should be able t use the default sigstack now --
96      some h/ implementations are broken.*/
97  #ifndef SIG_STACK_SIZE  #ifndef SIG_STACK_SIZE
98  #  define SIG_STACK_SIZE 1000  #  define SIG_STACK_SIZE 1000
99  #endif  #endif
100    
101  #ifndef SETUP_SIG_STACK  /* #ifndef SETUP_SIG_STACK */
102  #  if defined(HAVE_SIGACTION) || defined(HAVE_SIGVEC)  /* #  if defined(HAVE_SIGACTION) || defined(HAVE_SIGVEC) */
103        struct sigstack estack;  /*       struct sigstack estack; */
104  #  endif  /* #  endif */
105  #endif  /* #endif */
106    
107  #ifdef NEED_NONRANDOM_SBRK  #ifdef NEED_NONRANDOM_SBRK
108  #include <syscall.h>  #include <syscall.h>
# Line 109  static object stack_space; Line 110  static object stack_space;
110  #include <unistd.h>  #include <unistd.h>
111  #endif  #endif
112    
113    void
114    wipe_stack(VOL void *l) {
115    
116    #if CSTACK_DIRECTION == -1
117       if (l>(void *)&l) bzero((void *)&l,l-(void *)&l);
118    #else
119      l+=sizeof(l);
120      if ((void *)&l>l) bzero((void *)l,(void *)&l-l);
121    #endif
122    
123    }
124    
125    void
126    clear_c_stack(VOL unsigned n) {
127    
128      void *v=OBJNULL;
129      alloca(n);
130      wipe_stack(&v);
131    
132    }
133    
134    unsigned long cssize      = 0;
135    
136  int  int
137  main(int argc, char **argv, char **envp) {  main(int argc, char **argv, char **envp) {
138  #if defined ( BSD ) && defined ( RLIMIT_STACK )  #if defined ( BSD ) && defined ( RLIMIT_STACK )
# Line 221  main(int argc, char **argv, char **envp) Line 245  main(int argc, char **argv, char **envp)
245      ihs_top = ihs_org-1;      ihs_top = ihs_org-1;
246      bds_top = bds_org-1;      bds_top = bds_org-1;
247      frs_top = frs_org-1;      frs_top = frs_org-1;
248      cs_org = &argc;      cs_org = cs_base = &argc;
249    #ifdef __ia64__
250     {
251       extern void * __libc_ia64_register_backing_store_base;
252       cs_org2=cs_base2=__libc_ia64_register_backing_store_base;
253     }
254    #endif
255      /* CSSIZE in bytes, cssize for pointer arithmetic. */      /* CSSIZE in bytes, cssize for pointer arithmetic. */
256      cssize = CSSIZE / sizeof ( void * );      cssize = CSSIZE;
257    
258  #ifdef BSD  #ifdef BSD
259  #  ifdef RLIMIT_STACK  #  ifdef RLIMIT_STACK
260      {      {
261        unsigned long mss;        /* unsigned long mss; */
262        mss=16*sizeof(short)*MAXPAGE; /* i.e. short foo[MAXPAGE] on stack in sgc_start */  /*       mss=16*sizeof(short)*MAXPAGE; */ /* i.e. short foo[MAXPAGE] on stack in sgc_start */
263        if (getrlimit(RLIMIT_STACK, &rl))        if (getrlimit(RLIMIT_STACK, &rl))
264          error("Cannot get stack rlimit\n");          error("Cannot get stack rlimit\n");
265        if (rl.rlim_max != RLIM_INFINITY && rl.rlim_max < mss)        if (rl.rlim_max != RLIM_INFINITY && rl.rlim_max < cssize)
266          mss=rl.rlim_max;          cssize=rl.rlim_max;
267        if (rl.rlim_cur == RLIM_INFINITY ||        if (rl.rlim_cur == RLIM_INFINITY ||
268            rl.rlim_cur != mss) {            rl.rlim_cur != cssize) {
269          rl.rlim_cur=mss;          rl.rlim_cur=cssize;
270          if (setrlimit(RLIMIT_STACK,&rl))          if (setrlimit(RLIMIT_STACK,&rl))
271            error("Cannot set stack rlimit\n");            error("Cannot set stack rlimit\n");
272        }        }
273        cssize = rl.rlim_cur/sizeof(*cs_org) - sizeof(*cs_org)*CSGETA;        cssize = rl.rlim_cur;
274      }      }
275    
276      /* Maybe the soft limit for data segment size is lower than the      /* Maybe the soft limit for data segment size is lower than the
# Line 261  main(int argc, char **argv, char **envp) Line 291  main(int argc, char **argv, char **envp)
291    
292  #ifdef AV  #ifdef AV
293            
294      cs_limit = cs_org - cssize;      cs_limit = cs_base + CSTACK_DIRECTION * cssize/sizeof(*cs_base);
295  #endif  #endif
296    
297    
# Line 272  main(int argc, char **argv, char **envp) Line 302  main(int argc, char **argv, char **envp)
302  #  if defined(HAVE_SIGACTION) || defined(HAVE_SIGVEC)  #  if defined(HAVE_SIGACTION) || defined(HAVE_SIGVEC)
303      {      {
304          /* make sure the stack is 8 byte aligned */          /* make sure the stack is 8 byte aligned */
305  #    ifdef SETJMP_ONE_DIRECTION  /* #    ifdef SETJMP_ONE_DIRECTION */
306          static  /*         static */
307  #    endif /* SETUP_SIG_STACK */  /* #    endif */ /* SETUP_SIG_STACK */
308              double estack_buf[SIG_STACK_SIZE];        static double estack_buf[32*SIGSTKSZ];
309          static struct sigaltstack estack;
310                            
311          bzero(estack_buf,sizeof(estack_buf));        bzero(estack_buf,sizeof(estack_buf));
312          estack.ss_sp = (char *) &estack_buf[SIG_STACK_SIZE-1];        estack.ss_sp = estack_buf;
313          estack.ss_onstack=0;        estack.ss_flags = 0;                                  
314          sigstack(&estack,0);        estack.ss_size = sizeof(estack_buf);                            
315          if (sigaltstack(&estack, 0) < 0)                      
316            error("sigaltstack");                            
317    
318      }      }
319  #  endif /* defined(HAVE_SIGACTION) || defined(HAVE_SIGVEC) */  #  endif /* defined(HAVE_SIGACTION) || defined(HAVE_SIGVEC) */
320    
# Line 390  void install_segmentation_catcher(void) Line 424  void install_segmentation_catcher(void)
424    
425  int catch_fatal=1;  int catch_fatal=1;
426  void  void
427  error(char *s)  error(char *s) {
428  {    if (catch_fatal>0 && interrupt_enable ) {
429          if (catch_fatal>0 && interrupt_enable )      catch_fatal = -1;
             {catch_fatal = -1;  
430  #ifdef SGC  #ifdef SGC
431             if (sgc_enabled)      if (sgc_enabled)
432               { sgc_quit();}        sgc_quit();
433             if (sgc_enabled==0)      if (sgc_enabled==0)
434  #endif  #endif
435               { install_segmentation_catcher() ;}        install_segmentation_catcher();
436             FEerror("Caught fatal error [memory may be damaged]",0); }      {
437          printf("\nUnrecoverable error: %s.\n", s);        struct string st;
438          fflush(stdout);        set_type_of(&st,t_string);
439          st.st_dim=st.st_fillp=s ? strlen(s) : 0;
440          st.st_self=s;
441          FEerror("Caught fatal error [memory may be damaged]: ~a",1,&st);
442        }
443      }
444      printf("\nUnrecoverable error: %s.\n", s);
445      fflush(stdout);
446  #ifdef UNIX  #ifdef UNIX
447      abort();    abort();
448  #endif  #endif
449  }  }
450    
# Line 421  initlisp(void) { Line 461  initlisp(void) {
461    
462          gcl_init_alloc();          gcl_init_alloc();
463    
464          Dotnil_body.t = (short)t_symbol;          Dotnil->c.c_cdr=Dotnil;
465          Dotnil_body.s_dbind = Dotnil;          Dotnil->s.s_dbind = Dotnil;
466          Dotnil_body.s_sfdef = NOT_SPECIAL;          Dotnil->s.s_sfdef = NOT_SPECIAL;
467          Dotnil_body.s_fillp = 6;          Dotnil->s.s_fillp = 6;
468          Dotnil_body.s_self = "DOTNIL";          Dotnil->s.s_self = "DOTNIL";
469          Dotnil_body.s_gfdef = OBJNULL;          Dotnil->s.s_gfdef = OBJNULL;
470          Dotnil_body.s_plist = Cnil;          Dotnil->s.s_plist = Cnil;
471          Dotnil_body.s_hpack = Cnil;          Dotnil->s.s_hpack = Cnil;
472          Dotnil_body.s_stype = (short)stp_constant;          Dotnil->s.s_stype = (short)stp_constant;
473          Dotnil_body.s_mflag = FALSE;          Dotnil->s.s_mflag = FALSE;
474            Dotnil->s.s_hash = ihash_equal1(Dotnil,0);
475                    
476          Cnil_body.t = (short)t_symbol;          Cnil->c.c_cdr=Cnil;
477          Cnil_body.s_dbind = Cnil;          Cnil->s.s_dbind = Cnil;
478          Cnil_body.s_sfdef = NOT_SPECIAL;          Cnil->s.s_sfdef = NOT_SPECIAL;
479          Cnil_body.s_fillp = 3;          Cnil->s.s_fillp = 3;
480          Cnil_body.s_self = "NIL";          Cnil->s.s_self = "NIL";
481          Cnil_body.s_gfdef = OBJNULL;          Cnil->s.s_gfdef = OBJNULL;
482          Cnil_body.s_plist = Cnil;          Cnil->s.s_plist = Cnil;
483          Cnil_body.s_hpack = Cnil;          Cnil->s.s_hpack = Cnil;
484          Cnil_body.s_stype = (short)stp_constant;          Cnil->s.s_stype = (short)stp_constant;
485          Cnil_body.s_mflag = FALSE;          Cnil->s.s_mflag = FALSE;
486            Cnil->s.s_hash = ihash_equal1(Cnil,0);
487                    
488          Ct_body.t = (short)t_symbol;          Ct->c.c_cdr=Ct;
489          Ct_body.s_dbind = Ct;          Ct->s.s_dbind = Ct;
490          Ct_body.s_sfdef = NOT_SPECIAL;          Ct->s.s_sfdef = NOT_SPECIAL;
491          Ct_body.s_fillp = 1;          Ct->s.s_fillp = 1;
492          Ct_body.s_self = "T";          Ct->s.s_self = "T";
493          Ct_body.s_gfdef = OBJNULL;          Ct->s.s_gfdef = OBJNULL;
494          Ct_body.s_plist = Cnil;          Ct->s.s_plist = Cnil;
495          Ct_body.s_hpack = Cnil;          Ct->s.s_hpack = Cnil;
496          Ct_body.s_stype = (short)stp_constant;          Ct->s.s_stype = (short)stp_constant;
497          Ct_body.s_mflag = FALSE;          Ct->s.s_mflag = FALSE;
498            Ct->s.s_hash = ihash_equal1(Ct,0);
499                    
500          gcl_init_symbol();          gcl_init_symbol();
501    
# Line 602  ihs_overflow(void) { Line 645  ihs_overflow(void) {
645  }  }
646    
647  void  void
648  segmentation_catcher(int i) {  segmentation_catcher(int i, long code, void *scp, char *addr) {
649  #ifndef SIG_STACK_SIZE  
650    int x;    void *faddr;
651    if (&x < cs_limit)    faddr=((siginfo_t *)code)->si_addr;
652      cs_overflow();  
653    #if CSTACK_DIRECTION == -1
654      if (faddr < (void *)cs_limit) /*FIXME, perhaps bound by nearest page here.*/
655    #else
656      if (faddr > (void *)cs_limit)
657    #endif
658        FEerror("Control stack overflow.",0); /*FIXME -- provide getrlimit here.*/
659    else    else
660      printf("Segmentation violation: c stack ok:signalling error");      printf("Segmentation violation: c stack ok:signalling error");
661  #endif  
662    error("Segmentation violation.");    error("Segmentation violation.");
663    
664  }  }
665    
666  DEFUNO_NEW("BYE",object,fLbye,LISP  DEFUNO_NEW("BYE",object,fLbye,LISP
# Line 708  FFN(siLcatch_fatal)(int i) { Line 758  FFN(siLcatch_fatal)(int i) {
758    
759  static void  static void
760  reset_cstack_limit(int arg) {  reset_cstack_limit(int arg) {
761  #ifdef AV  #if CSTACK_DIRECTION==-1
762    if ( &arg > cs_org - cssize + 16 )    if (&arg > cs_base - cssize/sizeof(*cs_base) + 16)
763        cs_limit = cs_org - cssize;  #else
764      if (&arg < cs_base + cssize/sizeof(*cs_base) - 16)
765    #endif
766        cs_limit = cs_base + CSTACK_DIRECTION * cssize/sizeof(*cs_base);
767    else    else
768        error ( "can't reset cs_limit" );        error ( "can't reset cs_limit" );
 #endif  
769  }  }
770    
771  LFD(siLreset_stack_limits)(void)  LFD(siLreset_stack_limits)(void)
# Line 741  LFD(siLreset_stack_limits)(void) Line 793  LFD(siLreset_stack_limits)(void)
793      ihs_limit = ihs_org + stack_multiple *  IHSSIZE;      ihs_limit = ihs_org + stack_multiple *  IHSSIZE;
794    else    else
795      error("can't reset ihs_limit");      error("can't reset ihs_limit");
796      if (cs_base==cs_org)
797        cs_org=(void *)&i;
798    #ifdef __ia64__
799     {
800       extern void * GC_save_regs_in_stack();
801       if (cs_base2==cs_org2)
802         cs_org2=GC_save_regs_in_stack();
803     }
804    #endif
805    
806    reset_cstack_limit(i);    reset_cstack_limit(i);
807    vs_base[0] = Cnil;    vs_base[0] = Cnil;
808  }  }

Legend:
Removed from v.1.57  
changed lines
  Added in v.1.58

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26