home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sa104os2.zip / SATHR104.ZIP / SATHER / SYSTEM / GC / SETJMP_T.C < prev    next >
C/C++ Source or Header  |  1994-09-12  |  4KB  |  146 lines

  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 12, 1994 3: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 "config.h"
  28.  
  29. #ifdef __hpux
  30. #include <unistd.h>
  31. int
  32. getpagesize()
  33. {
  34.     return sysconf(_SC_PAGE_SIZE);
  35. }
  36. #endif
  37.  
  38. #if defined(SUNOS5) || defined(DRSNX)
  39. #include <unistd.h>
  40. int
  41. getpagesize()
  42. {
  43.     return sysconf(_SC_PAGESIZE);
  44. }
  45. #endif
  46.  
  47. #ifdef _AUX_SOURCE
  48. #include <sys/mmu.h>
  49. int
  50. getpagesize()
  51. {
  52.    return PAGESIZE;
  53. }
  54. #endif
  55.  
  56. #if defined(AMIGA) || defined(MACOS)
  57. int
  58. getpagesize()
  59. {
  60.     return(4096);
  61. }
  62. #endif
  63.  
  64. #ifdef OS2
  65. #define INCL_DOSFILEMGR
  66. #define INCL_DOSMISC
  67. #define INCL_DOSERRORS
  68. #include <os2.h>
  69.  
  70. int
  71. getpagesize()
  72. {
  73.     ULONG result[1];
  74.     
  75.     if (DosQuerySysInfo(QSV_PAGE_SIZE, QSV_PAGE_SIZE,
  76.                     (void *)result, sizeof(ULONG)) != NO_ERROR) {
  77.         fprintf(stderr, "DosQuerySysInfo failed\n");
  78.         result[0] = 4096;
  79.     }
  80.     return((int)(result[0]));
  81. }
  82. #endif
  83.  
  84. struct {char a_a; char * a_b;} a;
  85.  
  86. int * nested_sp()
  87. {
  88.     int dummy;
  89.     
  90.     return(&dummy);
  91. }
  92.  
  93. main()
  94. {
  95.     int dummy;
  96.     long ps = getpagesize();
  97.     jmp_buf b;
  98.     register int x = strlen("a");  /* 1, slightly disguised */
  99.     static int y = 0;
  100.  
  101.     if (nested_sp() < &dummy) {
  102.       printf("Stack appears to grow down, which is the default.\n");
  103.       printf("A good guess for STACKBOTTOM on this machine is 0x%X.\n",
  104.              ((long)(&dummy) + ps) & ~(ps-1));
  105.     } else {
  106.       printf("Stack appears to grow up.\n");
  107.       printf("Define STACK_GROWS_UP in gc_private.h\n");
  108.       printf("A good guess for STACKBOTTOM on this machine is 0x%X.\n",
  109.              ((long)(&dummy) + ps) & ~(ps-1));
  110.     }
  111.     printf("Note that this may vary between machines of ostensibly\n");
  112.     printf("the same architecture (e.g. Sun 3/50s and 3/80s).\n");
  113.     printf("A good guess for ALIGNMENT on this machine is %d.\n",
  114.            (unsigned long)(&(a.a_b))-(unsigned long)(&a));
  115.     
  116.     /* Encourage the compiler to keep x in a callee-save register */
  117.     x = 2*x-1;
  118.     printf("");
  119.     x = 2*x-1;
  120.     setjmp(b);
  121.     if (y == 1) {
  122.         if (x == 2) {
  123.         printf("Generic mark_regs code probably wont work\n");
  124. #        if defined(SPARC) || defined(RS6000) || defined(VAX) || defined(MIPS) || defined(M68K) || defined(I386) || defined(NS32K) || defined(RT)
  125.             printf("Assembly code supplied\n");
  126. #        else
  127.             printf("Need assembly code\n");
  128. #        endif
  129.         } else if (x == 1) {
  130.         printf("Generic mark_regs code may work\n");
  131.         } else {
  132.         printf("Very strange setjmp implementation\n");
  133.         }
  134.     }
  135.     y++;
  136.     x = 2;
  137.     if (y == 1) longjmp(b,1);
  138.     return(0);
  139. }
  140.  
  141. int g(x)
  142. int x;
  143. {
  144.     return(x);
  145. }
  146.