switch_x86_msvc.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * this is the internal transfer function.
  3. *
  4. * HISTORY
  5. * 24-Nov-02 Christian Tismer <tismer@tismer.com>
  6. * needed to add another magic constant to insure
  7. * that f in slp_eval_frame(PyFrameObject *f)
  8. * STACK_REFPLUS will probably be 1 in most cases.
  9. * gets included into the saved stack area.
  10. * 26-Sep-02 Christian Tismer <tismer@tismer.com>
  11. * again as a result of virtualized stack access,
  12. * the compiler used less registers. Needed to
  13. * explicit mention registers in order to get them saved.
  14. * Thanks to Jeff Senn for pointing this out and help.
  15. * 17-Sep-02 Christian Tismer <tismer@tismer.com>
  16. * after virtualizing stack save/restore, the
  17. * stack size shrunk a bit. Needed to introduce
  18. * an adjustment STACK_MAGIC per platform.
  19. * 15-Sep-02 Gerd Woetzel <gerd.woetzel@GMD.DE>
  20. * slightly changed framework for sparc
  21. * 01-Mar-02 Christian Tismer <tismer@tismer.com>
  22. * Initial final version after lots of iterations for i386.
  23. */
  24. #define alloca _alloca
  25. #define STACK_REFPLUS 1
  26. #ifdef SLP_EVAL
  27. #define STACK_MAGIC 0
  28. /* Some magic to quell warnings and keep slp_switch() from crashing when built
  29. with VC90. Disable global optimizations, and the warning: frame pointer
  30. register 'ebp' modified by inline assembly code */
  31. #pragma optimize("g", off)
  32. #pragma warning(disable:4731)
  33. static int
  34. slp_switch(void)
  35. {
  36. void* seh;
  37. register int *stackref, stsizediff;
  38. __asm mov eax, fs:[0]
  39. __asm mov [seh], eax
  40. __asm mov stackref, esp;
  41. /* modify EBX, ESI and EDI in order to get them preserved */
  42. __asm mov ebx, ebx;
  43. __asm xchg esi, edi;
  44. {
  45. SLP_SAVE_STATE(stackref, stsizediff);
  46. __asm {
  47. mov eax, stsizediff
  48. add esp, eax
  49. add ebp, eax
  50. }
  51. SLP_RESTORE_STATE();
  52. }
  53. __asm mov eax, [seh]
  54. __asm mov fs:[0], eax
  55. return 0;
  56. }
  57. /* re-enable ebp warning and global optimizations. */
  58. #pragma optimize("g", on)
  59. #pragma warning(default:4731)
  60. #endif
  61. /*
  62. * further self-processing support
  63. */
  64. /* we have IsBadReadPtr available, so we can peek at objects */
  65. #define STACKLESS_SPY
  66. #ifdef IMPLEMENT_STACKLESSMODULE
  67. #include "Windows.h"
  68. #define CANNOT_READ_MEM(p, bytes) IsBadReadPtr(p, bytes)
  69. static int IS_ON_STACK(void*p)
  70. {
  71. int stackref;
  72. int stackbase = ((int)&stackref) & 0xfffff000;
  73. return (int)p >= stackbase && (int)p < stackbase + 0x00100000;
  74. }
  75. #endif