[BACK]Return to setjmp_t.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gc

Annotation of OpenXM_contrib/gc/setjmp_t.c, Revision 1.1.1.1

1.1       maekawa     1: /*
                      2:  * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
                      3:  *
                      4:  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
                      5:  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
                      6:  *
                      7:  * Permission is hereby granted to use or copy this program
                      8:  * for any purpose,  provided the above notices are retained on all copies.
                      9:  * Permission to modify the code and to distribute modified code is granted,
                     10:  * provided the above notices are retained, and a notice that the code was
                     11:  * modified is included with the above copyright notice.
                     12:  */
                     13: /* Boehm, September 21, 1995 5:39 pm PDT */
                     14:
                     15: /* Check whether setjmp actually saves registers in jmp_buf. */
                     16: /* If it doesn't, the generic mark_regs code won't work.     */
                     17: /* Compilers vary as to whether they will put x in a        */
                     18: /* (callee-save) register without -O.  The code is          */
                     19: /* contrived such that any decent compiler should put x in   */
                     20: /* a callee-save register with -O.  Thus it is is           */
                     21: /* recommended that this be run optimized.  (If the machine  */
                     22: /* has no callee-save registers, then the generic code is    */
                     23: /* safe, but this will not be noticed by this piece of       */
                     24: /* code.)                                                   */
                     25: #include <stdio.h>
                     26: #include <setjmp.h>
                     27: #include <string.h>
                     28: #include "gcconfig.h"
                     29:
                     30: #ifdef OS2
                     31: /* GETPAGESIZE() is set to getpagesize() by default, but that  */
                     32: /* doesn't really exist, and the collector doesn't need it.    */
                     33: #define INCL_DOSFILEMGR
                     34: #define INCL_DOSMISC
                     35: #define INCL_DOSERRORS
                     36: #include <os2.h>
                     37:
                     38: int
                     39: getpagesize()
                     40: {
                     41:     ULONG result[1];
                     42:
                     43:     if (DosQuerySysInfo(QSV_PAGE_SIZE, QSV_PAGE_SIZE,
                     44:                        (void *)result, sizeof(ULONG)) != NO_ERROR) {
                     45:        fprintf(stderr, "DosQuerySysInfo failed\n");
                     46:        result[0] = 4096;
                     47:     }
                     48:     return((int)(result[0]));
                     49: }
                     50: #endif
                     51:
                     52: struct {char a_a; char * a_b;} a;
                     53:
                     54: int * nested_sp()
                     55: {
                     56:     int dummy;
                     57:
                     58:     return(&dummy);
                     59: }
                     60:
                     61: main()
                     62: {
                     63:        int dummy;
                     64:        long ps = GETPAGESIZE();
                     65:        jmp_buf b;
                     66:        register int x = (int)strlen("a");  /* 1, slightly disguised */
                     67:        static int y = 0;
                     68:
                     69:        printf("This appears to be a %s running %s\n", MACH_TYPE, OS_TYPE);
                     70:        if (nested_sp() < &dummy) {
                     71:          printf("Stack appears to grow down, which is the default.\n");
                     72:          printf("A good guess for STACKBOTTOM on this machine is 0x%lx.\n",
                     73:                 ((unsigned long)(&dummy) + ps) & ~(ps-1));
                     74:        } else {
                     75:          printf("Stack appears to grow up.\n");
                     76:          printf("Define STACK_GROWS_UP in gc_private.h\n");
                     77:          printf("A good guess for STACKBOTTOM on this machine is 0x%lx.\n",
                     78:                 ((unsigned long)(&dummy) + ps) & ~(ps-1));
                     79:        }
                     80:        printf("Note that this may vary between machines of ostensibly\n");
                     81:        printf("the same architecture (e.g. Sun 3/50s and 3/80s).\n");
                     82:        printf("On many machines the value is not fixed.\n");
                     83:        printf("A good guess for ALIGNMENT on this machine is %ld.\n",
                     84:               (unsigned long)(&(a.a_b))-(unsigned long)(&a));
                     85:
                     86:        /* Encourage the compiler to keep x in a callee-save register */
                     87:        x = 2*x-1;
                     88:        printf("");
                     89:        x = 2*x-1;
                     90:        setjmp(b);
                     91:        if (y == 1) {
                     92:            if (x == 2) {
                     93:                printf("Generic mark_regs code probably wont work\n");
                     94: #              if defined(SPARC) || defined(RS6000) || defined(VAX) || defined(MIPS) || defined(M68K) || defined(I386) || defined(NS32K) || defined(RT)
                     95:                    printf("Assembly code supplied\n");
                     96: #              else
                     97:                    printf("Need assembly code\n");
                     98: #              endif
                     99:            } else if (x == 1) {
                    100:                printf("Generic mark_regs code may work\n");
                    101:            } else {
                    102:                printf("Very strange setjmp implementation\n");
                    103:            }
                    104:        }
                    105:        y++;
                    106:        x = 2;
                    107:        if (y == 1) longjmp(b,1);
                    108:        return(0);
                    109: }
                    110:
                    111: int g(x)
                    112: int x;
                    113: {
                    114:        return(x);
                    115: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>