From ce86f5b57626201b17413ac8820fa386d6beb82c Mon Sep 17 00:00:00 2001 From: "KJK::Hyperion" Date: Thu, 3 Jun 2004 02:23:34 +0000 Subject: [PATCH] Final touches to the SEH library: now comes with a very basic setjmp/longjmp implementation for when the compiler's native one can't be used svn path=/trunk/; revision=9598 --- reactos/include/pseh/framebased.h | 10 ++++- reactos/include/pseh/setjmp.h | 44 +++++++++++++++++++++ reactos/lib/pseh/i386/setjmp.asm | 65 +++++++++++++++++++++++++++++++ reactos/lib/pseh/makefile.i386 | 4 +- 4 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 reactos/include/pseh/setjmp.h create mode 100644 reactos/lib/pseh/i386/setjmp.asm diff --git a/reactos/include/pseh/framebased.h b/reactos/include/pseh/framebased.h index 7d76aa21d0b..085550bfc4c 100644 --- a/reactos/include/pseh/framebased.h +++ b/reactos/include/pseh/framebased.h @@ -24,9 +24,17 @@ #define KJK_PSEH_FRAMEBASED_H_ #include +#include + +#ifdef _SEH_NO_NATIVE_NLG #include #include -#include +#else +#include +#define longjmp _SEHLongJmp +#define setjmp _SEHSetJmp +#define jmp_buf _SEHJmpBuf_t +#endif typedef struct __SEHFrame { diff --git a/reactos/include/pseh/setjmp.h b/reactos/include/pseh/setjmp.h new file mode 100644 index 00000000000..ef17bc68599 --- /dev/null +++ b/reactos/include/pseh/setjmp.h @@ -0,0 +1,44 @@ +/* + Copyright (c) 2004 KJK::Hyperion + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#ifndef KJK_PSEH_SETJMP_H_ +#define KJK_PSEH_SETJMP_H_ + +#ifdef _M_IX86 +typedef struct __SEHJmpBuf +{ + unsigned long JB_Ebp; + unsigned long JB_Esp; + unsigned long JB_Eip; + unsigned long JB_Ebx; + unsigned long JB_Esi; + unsigned long JB_Edi; +} +_SEHJmpBuf_t[1]; +#endif + +extern __declspec(noreturn) void __stdcall _SEHLongJmp(_SEHJmpBuf_t, int); +extern int __stdcall _SEHSetJmp(_SEHJmpBuf_t); + +#endif + +/* EOF */ diff --git a/reactos/lib/pseh/i386/setjmp.asm b/reactos/lib/pseh/i386/setjmp.asm new file mode 100644 index 00000000000..43431bac412 --- /dev/null +++ b/reactos/lib/pseh/i386/setjmp.asm @@ -0,0 +1,65 @@ +; Copyright (c) 2004 KJK::Hyperion + +; Permission is hereby granted, free of charge, to any person obtaining a copy +; of this software and associated documentation files (the "Software"), to deal +; in the Software without restriction, including without limitation the rights +; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +; copies of the Software, and to permit persons to whom the Software is +; furnished to dos so, subject to the following conditions: + +; The above copyright notice and this permission notice shall be included in all +; copies or substantial portions of the Software. + +; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +; SOFTWARE. + +cpu 486 +segment .text use32 + +global SEHSetJmp +global __SEHSetJmp +SEHSetJmp: +__SEHSetJmp@8: + ; jump buffer + mov eax, [esp+4] + + ; program counter + mov ecx, [esp+0] + + ; stack pointer + lea edx, [esp+4] + + ; fill the jump buffer + mov [eax+0], ebp + mov [eax+4], edx + mov [eax+8], ecx + mov [eax+12], ebx + mov [eax+16], esi + mov [eax+20], edi + ret 4 + +global SEHLongJmp +global __SEHLongJmp@8 +SEHLongJmp: +__SEHLongJmp@8: + ; return value + mov eax, [esp+8] + + ; jump buffer + mov ecx, [esp+4] + + ; restore the saved context + mov ebp, [ecx+0] + mov esp, [ecx+4] + mov edx, [ecx+8] + mov ebx, [ecx+12] + mov esi, [ecx+16] + mov edi, [ecx+20] + jmp edx + +; EOF diff --git a/reactos/lib/pseh/makefile.i386 b/reactos/lib/pseh/makefile.i386 index 1fde404d8d8..09e802f0e3d 100644 --- a/reactos/lib/pseh/makefile.i386 +++ b/reactos/lib/pseh/makefile.i386 @@ -1,5 +1,5 @@ -# $Id: makefile.i386,v 1.1 2004/06/02 18:36:55 hyperion Exp $ +# $Id: makefile.i386,v 1.2 2004/06/03 02:23:34 hyperion Exp $ -TARGET_ARCH_OBJECTS = $(ARCH)/framebased.o +TARGET_ARCH_OBJECTS = $(ARCH)/framebased.o $(ARCH)/setjmp.o # EOF