pro.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* pro.c Copyright (C) 1989-2002 Codemist Ltd */
  2. /* Watcom C stack checking code */
  3. /*
  4. * This code may be used and modified, and redistributed in binary
  5. * or source form, subject to the "CCL Public License", which should
  6. * accompany it. This license is a variant on the BSD license, and thus
  7. * permits use of code derived from this in either open and commercial
  8. * projects: but it does require that updates to this code be made
  9. * available back to the originators of the package.
  10. * Before merging other code in with this or linking this code
  11. * with other packages or libraries please check that the license terms
  12. * of the other material are compatible with those of this.
  13. */
  14. /* Signature: 7c40872e 08-Apr-2002 */
  15. #include <stdarg.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18. #include "machine.h"
  19. #include "tags.h"
  20. #include "externs.h"
  21. #include "arith.h"
  22. #include "read.h"
  23. #include "stream.h"
  24. #include "entries.h"
  25. #include "version.h"
  26. #include "cslerror.h"
  27. static int spset = 0;
  28. static int32 spbase = 0, spmin;
  29. static FILE *stack_log = NULL;
  30. #pragma aux __PRO modify [];
  31. #pragma aux __PRO "__PRO";
  32. extern int pusha(void);
  33. #pragma aux pusha = "push eax" "push ecx" "push edx" value [eax] modify [];
  34. extern int popa(void);
  35. #pragma aux popa = "pop edx" "pop ecx" "pop eax" value [eax] modify [eax ecx edx];
  36. void __PRO()
  37. {
  38. int32 temp;
  39. pusha();
  40. temp = (int32)&temp;
  41. if (!spset)
  42. { spbase = spmin = temp;
  43. spset = 1;
  44. }
  45. if (stack_log == NULL) stack_log = fopen("stack.log", "w");
  46. if (temp <= spmin-64) /* Only check at granularity of 64 bytes */
  47. {
  48. fprintf(stack_log, "Stack depth %d\n", spbase-temp);
  49. spmin = temp;
  50. }
  51. popa();
  52. return;
  53. }
  54. /* End of pro.c */