setjmp_t.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /* Check whether setjmp actually saves registers in jmp_buf. */
  14. /* If it doesn't, the generic mark_regs code won't work. */
  15. /* Compilers vary as to whether they will put x in a */
  16. /* (callee-save) register without -O. The code is */
  17. /* contrived such that any decent compiler should put x in */
  18. /* a callee-save register with -O. Thus it is is */
  19. /* recommended that this be run optimized. (If the machine */
  20. /* has no callee-save registers, then the generic code is */
  21. /* safe, but this will not be noticed by this piece of */
  22. /* code.) This test appears to be far from perfect. */
  23. #include <stdio.h>
  24. #include <setjmp.h>
  25. #include <string.h>
  26. #include "private/gcconfig.h"
  27. #ifdef OS2
  28. /* GETPAGESIZE() is set to getpagesize() by default, but that */
  29. /* doesn't really exist, and the collector doesn't need it. */
  30. #define INCL_DOSFILEMGR
  31. #define INCL_DOSMISC
  32. #define INCL_DOSERRORS
  33. #include <os2.h>
  34. int
  35. getpagesize()
  36. {
  37. ULONG result[1];
  38. if (DosQuerySysInfo(QSV_PAGE_SIZE, QSV_PAGE_SIZE,
  39. (void *)result, sizeof(ULONG)) != NO_ERROR) {
  40. fprintf(stderr, "DosQuerySysInfo failed\n");
  41. result[0] = 4096;
  42. }
  43. return((int)(result[0]));
  44. }
  45. #endif
  46. struct {char a_a; char * a_b;} a;
  47. int * nested_sp()
  48. {
  49. int dummy;
  50. return(&dummy);
  51. }
  52. main()
  53. {
  54. int dummy;
  55. long ps = GETPAGESIZE();
  56. jmp_buf b;
  57. register int x = (int)strlen("a"); /* 1, slightly disguised */
  58. static int y = 0;
  59. printf("This appears to be a %s running %s\n", MACH_TYPE, OS_TYPE);
  60. if (nested_sp() < &dummy) {
  61. printf("Stack appears to grow down, which is the default.\n");
  62. printf("A good guess for STACKBOTTOM on this machine is 0x%lx.\n",
  63. ((unsigned long)(&dummy) + ps) & ~(ps-1));
  64. } else {
  65. printf("Stack appears to grow up.\n");
  66. printf("Define STACK_GROWS_UP in gc_private.h\n");
  67. printf("A good guess for STACKBOTTOM on this machine is 0x%lx.\n",
  68. ((unsigned long)(&dummy) + ps) & ~(ps-1));
  69. }
  70. printf("Note that this may vary between machines of ostensibly\n");
  71. printf("the same architecture (e.g. Sun 3/50s and 3/80s).\n");
  72. printf("On many machines the value is not fixed.\n");
  73. printf("A good guess for ALIGNMENT on this machine is %ld.\n",
  74. (unsigned long)(&(a.a_b))-(unsigned long)(&a));
  75. /* Encourage the compiler to keep x in a callee-save register */
  76. x = 2*x-1;
  77. printf("");
  78. x = 2*x-1;
  79. setjmp(b);
  80. if (y == 1) {
  81. if (x == 2) {
  82. printf("Generic mark_regs code probably wont work\n");
  83. # if defined(SPARC) || defined(RS6000) || defined(VAX) || defined(MIPS) || defined(M68K) || defined(I386) || defined(NS32K) || defined(RT)
  84. printf("Assembly code supplied\n");
  85. # else
  86. printf("Need assembly code\n");
  87. # endif
  88. } else if (x == 1) {
  89. printf("Generic mark_regs code may work\n");
  90. } else {
  91. printf("Very strange setjmp implementation\n");
  92. }
  93. }
  94. y++;
  95. x = 2;
  96. if (y == 1) longjmp(b,1);
  97. return(0);
  98. }
  99. int g(x)
  100. int x;
  101. {
  102. return(x);
  103. }