2
0

jump_i386_ms_pe_masm.asm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ; Copyright Oliver Kowalke 2009.
  2. ; Distributed under the Boost Software License, Version 1.0.
  3. ; (See accompanying file LICENSE_1_0.txt or copy at
  4. ; http://www.boost.org/LICENSE_1_0.txt)
  5. ; ---------------------------------------------------------------------------------
  6. ; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
  7. ; ---------------------------------------------------------------------------------
  8. ; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch |
  9. ; ---------------------------------------------------------------------------------
  10. ; | fc_strg |fc_deallo| limit | base | fc_seh | EDI | ESI | EBX |
  11. ; ---------------------------------------------------------------------------------
  12. ; ---------------------------------------------------------------------------------
  13. ; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
  14. ; ---------------------------------------------------------------------------------
  15. ; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch |
  16. ; ---------------------------------------------------------------------------------
  17. ; | EBP | EIP | to | data | | EH NXT |SEH HNDLR| |
  18. ; ---------------------------------------------------------------------------------
  19. .386
  20. .XMM
  21. .model flat, c
  22. .code
  23. jump_fcontext PROC BOOST_CONTEXT_EXPORT
  24. push ebp ; save EBP
  25. push ebx ; save EBX
  26. push esi ; save ESI
  27. push edi ; save EDI
  28. assume fs:nothing
  29. ; load NT_TIB into ECX
  30. mov edx, fs:[018h]
  31. assume fs:error
  32. ; load current SEH exception list
  33. mov eax, [edx]
  34. push eax
  35. ; load current stack base
  36. mov eax, [edx+04h]
  37. push eax
  38. ; load current stack limit
  39. mov eax, [edx+08h]
  40. push eax
  41. ; load current deallocation stack
  42. mov eax, [edx+0e0ch]
  43. push eax
  44. ; load fiber local storage
  45. mov eax, [edx+010h]
  46. push eax
  47. ; store ESP (pointing to context-data) in EAX
  48. mov eax, esp
  49. ; firstarg of jump_fcontext() == fcontext to jump to
  50. mov ecx, [esp+028h]
  51. ; restore ESP (pointing to context-data) from EAX
  52. mov esp, ecx
  53. assume fs:nothing
  54. ; load NT_TIB into EDX
  55. mov edx, fs:[018h]
  56. assume fs:error
  57. ; restore fiber local storage
  58. pop ecx
  59. mov [edx+010h], ecx
  60. ; restore current deallocation stack
  61. pop ecx
  62. mov [edx+0e0ch], ecx
  63. ; restore current stack limit
  64. pop ecx
  65. mov [edx+08h], ecx
  66. ; restore current stack base
  67. pop ecx
  68. mov [edx+04h], ecx
  69. ; restore current SEH exception list
  70. pop ecx
  71. mov [edx], ecx
  72. pop edi ; save EDI
  73. pop esi ; save ESI
  74. pop ebx ; save EBX
  75. pop ebp ; save EBP
  76. ; return transfer_t
  77. ; FCTX == EAX, DATA == EDX
  78. mov edx, [eax+02ch]
  79. ; jump to context
  80. ret
  81. jump_fcontext ENDP
  82. END