Back to index

plt-scheme  4.2.1
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  
00014 /* Check whether setjmp actually saves registers in jmp_buf. */
00015 /* If it doesn't, the generic mark_regs code won't work.     */
00016 /* Compilers vary as to whether they will put x in a         */
00017 /* (callee-save) register without -O.  The code is           */
00018 /* contrived such that any decent compiler should put x in   */
00019 /* a callee-save register with -O.  Thus it is is            */
00020 /* recommended that this be run optimized.  (If the machine  */
00021 /* has no callee-save registers, then the generic code is    */
00022 /* safe, but this will not be noticed by this piece of       */
00023 /* code.)  This test appears to be far from perfect.         */
00024 #include <stdio.h>
00025 #include <setjmp.h>
00026 #include <string.h>
00027 #include "private/gcconfig.h"
00028 
00029 #ifdef OS2
00030 /* GETPAGESIZE() is set to getpagesize() by default, but that  */
00031 /* doesn't really exist, and the collector doesn't need it.    */
00032 #define INCL_DOSFILEMGR
00033 #define INCL_DOSMISC
00034 #define INCL_DOSERRORS
00035 #include <os2.h>
00036 
00037 int
00038 getpagesize()
00039 {
00040     ULONG result[1];
00041     
00042     if (DosQuerySysInfo(QSV_PAGE_SIZE, QSV_PAGE_SIZE,
00043                       (void *)result, sizeof(ULONG)) != NO_ERROR) {
00044        fprintf(stderr, "DosQuerySysInfo failed\n");
00045        result[0] = 4096;
00046     }
00047     return((int)(result[0]));
00048 }
00049 #endif
00050 
00051 struct {char a_a; char * a_b;} a;
00052 
00053 int * nested_sp()
00054 {
00055     int dummy;
00056     
00057     return(&dummy);
00058 }
00059 
00060 main()
00061 {
00062        int dummy;
00063        long ps = GETPAGESIZE();
00064        jmp_buf b;
00065        register int x = (int)strlen("a");  /* 1, slightly disguised */
00066        static int y = 0;
00067 
00068        printf("This appears to be a %s running %s\n", MACH_TYPE, OS_TYPE);
00069        if (nested_sp() < &dummy) {
00070          printf("Stack appears to grow down, which is the default.\n");
00071          printf("A good guess for STACKBOTTOM on this machine is 0x%lx.\n",
00072                 ((unsigned long)(&dummy) + ps) & ~(ps-1));
00073        } else {
00074          printf("Stack appears to grow up.\n");
00075          printf("Define STACK_GROWS_UP in gc_private.h\n");
00076          printf("A good guess for STACKBOTTOM on this machine is 0x%lx.\n",
00077                 ((unsigned long)(&dummy) + ps) & ~(ps-1));
00078        }
00079        printf("Note that this may vary between machines of ostensibly\n");
00080        printf("the same architecture (e.g. Sun 3/50s and 3/80s).\n");
00081        printf("On many machines the value is not fixed.\n");
00082        printf("A good guess for ALIGNMENT on this machine is %ld.\n",
00083               (unsigned long)(&(a.a_b))-(unsigned long)(&a));
00084        
00085        /* Encourage the compiler to keep x in a callee-save register */
00086        x = 2*x-1;
00087        printf("");
00088        x = 2*x-1;
00089        setjmp(b);
00090        if (y == 1) {
00091            if (x == 2) {
00092               printf("Generic mark_regs code probably wont work\n");
00093 #             if defined(SPARC) || defined(RS6000) || defined(VAX) || defined(MIPS) || defined(M68K) || defined(I386) || defined(NS32K) || defined(RT)
00094                   printf("Assembly code supplied\n");
00095 #             else
00096                   printf("Need assembly code\n");
00097 #             endif
00098            } else if (x == 1) {
00099               printf("Generic mark_regs code may work\n");
00100            } else {
00101               printf("Very strange setjmp implementation\n");
00102            }
00103        }
00104        y++;
00105        x = 2;
00106        if (y == 1) longjmp(b,1);
00107        return(0);
00108 }
00109 
00110 int g(x)
00111 int x;
00112 {
00113        return(x);
00114 }