Back to index

lightning-sunbird  0.9+nobinonly
setjmp_t.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
00003  *
00004  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
00005  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
00006  *
00007  * Permission is hereby granted to use or copy this program
00008  * for any purpose,  provided the above notices are retained on all copies.
00009  * Permission to modify the code and to distribute modified code is granted,
00010  * provided the above notices are retained, and a notice that the code was
00011  * modified is included with the above copyright notice.
00012  */
00013 /* Boehm, September 21, 1995 5:39 pm PDT */
00014  
00015 /* Check whether setjmp actually saves registers in jmp_buf. */
00016 /* If it doesn't, the generic mark_regs code won't work.     */
00017 /* Compilers vary as to whether they will put x in a         */
00018 /* (callee-save) register without -O.  The code is           */
00019 /* contrived such that any decent compiler should put x in   */
00020 /* a callee-save register with -O.  Thus it is is            */
00021 /* recommended that this be run optimized.  (If the machine  */
00022 /* has no callee-save registers, then the generic code is    */
00023 /* safe, but this will not be noticed by this piece of       */
00024 /* code.)                                             */
00025 #include <stdio.h>
00026 #include <setjmp.h>
00027 #include <string.h>
00028 #include "gcconfig.h"
00029 
00030 #ifdef OS2
00031 /* GETPAGESIZE() is set to getpagesize() by default, but that  */
00032 /* doesn't really exist, and the collector doesn't need it.    */
00033 #define INCL_DOSFILEMGR
00034 #define INCL_DOSMISC
00035 #define INCL_DOSERRORS
00036 #include <os2.h>
00037 
00038 int
00039 getpagesize()
00040 {
00041     ULONG result[1];
00042     
00043     if (DosQuerySysInfo(QSV_PAGE_SIZE, QSV_PAGE_SIZE,
00044                       (void *)result, sizeof(ULONG)) != NO_ERROR) {
00045        fprintf(stderr, "DosQuerySysInfo failed\n");
00046        result[0] = 4096;
00047     }
00048     return((int)(result[0]));
00049 }
00050 #endif
00051 
00052 struct {char a_a; char * a_b;} a;
00053 
00054 int * nested_sp()
00055 {
00056     int dummy;
00057     
00058     return(&dummy);
00059 }
00060 
00061 main()
00062 {
00063        int dummy;
00064        long ps = GETPAGESIZE();
00065        jmp_buf b;
00066        register int x = (int)strlen("a");  /* 1, slightly disguised */
00067        static int y = 0;
00068 
00069        printf("This appears to be a %s running %s\n", MACH_TYPE, OS_TYPE);
00070        if (nested_sp() < &dummy) {
00071          printf("Stack appears to grow down, which is the default.\n");
00072          printf("A good guess for STACKBOTTOM on this machine is 0x%lx.\n",
00073                 ((unsigned long)(&dummy) + ps) & ~(ps-1));
00074        } else {
00075          printf("Stack appears to grow up.\n");
00076          printf("Define STACK_GROWS_UP in gc_private.h\n");
00077          printf("A good guess for STACKBOTTOM on this machine is 0x%lx.\n",
00078                 ((unsigned long)(&dummy) + ps) & ~(ps-1));
00079        }
00080        printf("Note that this may vary between machines of ostensibly\n");
00081        printf("the same architecture (e.g. Sun 3/50s and 3/80s).\n");
00082        printf("On many machines the value is not fixed.\n");
00083        printf("A good guess for ALIGNMENT on this machine is %ld.\n",
00084               (unsigned long)(&(a.a_b))-(unsigned long)(&a));
00085        
00086        /* Encourage the compiler to keep x in a callee-save register */
00087        x = 2*x-1;
00088        printf("");
00089        x = 2*x-1;
00090        setjmp(b);
00091        if (y == 1) {
00092            if (x == 2) {
00093               printf("Generic mark_regs code probably wont work\n");
00094 #             if defined(SPARC) || defined(RS6000) || defined(VAX) || defined(MIPS) || defined(M68K) || defined(I386) || defined(NS32K) || defined(RT)
00095                   printf("Assembly code supplied\n");
00096 #             else
00097                   printf("Need assembly code\n");
00098 #             endif
00099            } else if (x == 1) {
00100               printf("Generic mark_regs code may work\n");
00101            } else {
00102               printf("Very strange setjmp implementation\n");
00103            }
00104        }
00105        y++;
00106        x = 2;
00107        if (y == 1) longjmp(b,1);
00108        return(0);
00109 }
00110 
00111 int g(x)
00112 int x;
00113 {
00114        return(x);
00115 }