[NTOSKRNL][PSEH3]
authorDmitry Gorbachev <gorbachev@reactos.org>
Wed, 6 Aug 2014 23:10:08 +0000 (23:10 +0000)
committerDmitry Gorbachev <gorbachev@reactos.org>
Wed, 6 Aug 2014 23:10:08 +0000 (23:10 +0000)
- Add inline asm dependencies to fix undefined reference errors when
building with link-time optimization.
- Improve formatting.
- No functional changes.

svn path=/trunk/; revision=63823

reactos/include/reactos/libs/pseh/pseh3.h
reactos/lib/pseh/i386/pseh3.c
reactos/ntoskrnl/CMakeLists.txt
reactos/ntoskrnl/include/internal/i386/ke.h
reactos/ntoskrnl/ntkrnlmp/CMakeLists.txt

index 8337b41..fee3b63 100644 (file)
@@ -113,6 +113,22 @@ void * __cdecl __attribute__((error("Can only be used inside an exception filter
 /* This attribute allows automatic cleanup of the registered frames */
 #define _SEH3$_AUTO_CLEANUP __attribute__((cleanup(_SEH3$_AutoCleanup)))
 
+int
+__attribute__((regparm(3)))
+__attribute__((returns_twice))
+_SEH3$_RegisterFrameWithNonVolatiles(
+    volatile SEH3$_REGISTRATION_FRAME* RegistrationFrame,
+    const SEH3$_SCOPE_TABLE* ScopeTable,
+    void* AllocaFrame);
+
+int
+__attribute__((regparm(3)))
+__attribute__((returns_twice))
+_SEH3$_RegisterTryLevelWithNonVolatiles(
+    volatile SEH3$_REGISTRATION_FRAME* RegistrationFrame,
+    const SEH3$_SCOPE_TABLE* ScopeTable,
+    void* AllocaFrame);
+
 /* CLANG specific definitions! */
 #ifdef __clang__
 
@@ -122,14 +138,6 @@ void * __cdecl __attribute__((error("Can only be used inside an exception filter
 /* CLANG doesn't have asm goto! */
 #define _SEH3$_ASM_GOTO(...)
 
-int
-__attribute__((regparm(3)))
-__attribute__((returns_twice))
-_SEH3$_RegisterFrameWithNonVolatiles(
-    volatile SEH3$_REGISTRATION_FRAME* RegistrationFrame,
-    const SEH3$_SCOPE_TABLE* ScopeTable,
-    void* AllocaFrame);
-
 #define _SEH3$_RegisterFrame_(_TrylevelFrame, _DataTable) \
     do { \
         int result = _SEH3$_RegisterFrameWithNonVolatiles(_TrylevelFrame, _DataTable, __builtin_alloca(0)); \
@@ -141,14 +149,6 @@ _SEH3$_RegisterFrameWithNonVolatiles(
         } \
     } while(0)
 
-int
-__attribute__((regparm(3)))
-__attribute__((returns_twice))
-_SEH3$_RegisterTryLevelWithNonVolatiles(
-    volatile SEH3$_REGISTRATION_FRAME* RegistrationFrame,
-    const SEH3$_SCOPE_TABLE* ScopeTable,
-    void* AllocaFrame);
-
 #define _SEH3$_RegisterTryLevel_(_TrylevelFrame, _DataTable) \
     do { \
         int result = _SEH3$_RegisterTryLevelWithNonVolatiles(_TrylevelFrame, _DataTable, __builtin_alloca(0)); \
@@ -171,21 +171,21 @@ _SEH3$_RegisterTryLevelWithNonVolatiles(
 
 #ifdef __cplusplus
 #define _SEH3$_CALL_WRAPPER(_Function, _TrylevelFrame, _DataTable) \
-    asm goto ("leal %0, %%eax\n" \
-              "leal %1, %%edx\n" \
-              "call " #_Function "WithStackLayout\n" \
+    asm goto ("leal %0, %%eax\n\t" \
+              "leal %1, %%edx\n\t" \
+              "call " #_Function "WithStackLayout" \
               : \
-              : "m" (*(_TrylevelFrame)), "m" (*(_DataTable)), "c"(__builtin_alloca(0)) \
+              : "m" (*(_TrylevelFrame)), "m" (*(_DataTable)), "c" (__builtin_alloca(0)), "p" (_SEH3$_RegisterFrameWithNonVolatiles) \
               : "eax", "edx", "memory" \
               : _SEH3$_l_BeforeTry, _SEH3$_l_HandlerTarget, _SEH3$_l_OnException, _SEH3$_l_BeforeFilterOrFinally, _SEH3$_l_FilterOrFinally)
 
 #else
 #define _SEH3$_CALL_WRAPPER(_Function, _TrylevelFrame, _DataTable) \
-    asm goto ("leal %0, %%eax\n" \
-              "leal %1, %%edx\n" \
-              "call " #_Function "\n" \
+    asm goto ("leal %0, %%eax\n\t" \
+              "leal %1, %%edx\n\t" \
+              "call " #_Function \
               : \
-              : "m" (*(_TrylevelFrame)), "m" (*(_DataTable)) \
+              : "m" (*(_TrylevelFrame)), "m" (*(_DataTable)), "p" (_SEH3$_RegisterFrameWithNonVolatiles) \
               : "eax", "edx", "ecx", "memory" \
               : _SEH3$_l_BeforeTry, _SEH3$_l_HandlerTarget, _SEH3$_l_OnException, _SEH3$_l_BeforeFilterOrFinally, _SEH3$_l_FilterOrFinally)
 #endif
@@ -227,8 +227,8 @@ _SEH3$_AutoCleanup(
 /* On invocation, the AllocaFrame field is loaded with the return esp value */
 #define _SEH3$_NESTED_FUNC_RETURN(_Result) \
         /* Restore esp and return to the caller */ \
-        asm volatile ("movl %[FixedEsp], %%esp\nret\n" \
-            : : "a"(_Result), [FixedEsp]"m"(_SEH3$_TrylevelFrame.AllocaFrame) : "ebx", "ecx", "edx", "esi", "edi", "flags", "memory")
+        asm volatile ("movl %[FixedEsp], %%esp\n\tret" \
+            : : "a" (_Result), [FixedEsp] "m" (_SEH3$_TrylevelFrame.AllocaFrame) : "ebx", "ecx", "edx", "esi", "edi", "flags", "memory")
 
 /* The filter "function" */
 #define _SEH3$_DEFINE_FILTER_FUNC(_Name, expression) \
index b485617..9f20415 100644 (file)
@@ -82,8 +82,8 @@ _SEH3$_InvokeNestedFunctionFilter(
 
         /* Second call to get the filter result */
         "mov $1, %%ecx\n\t"
-        "call *%[Filter]\n\t"
-        : "=a"(FilterResult)
+        "call *%[Filter]"
+        : "=a" (FilterResult)
         : [RegistrationFrame] "m" (RegistrationFrame), [Filter] "m" (Filter)
         : "ecx", "edx");
 
@@ -197,14 +197,14 @@ _SEH3$_JumpToTarget(
     {
         asm volatile (
             /* Load the registers */
-            "movl 20(%%ecx), %%esp\n"
-            "movl 24(%%ecx), %%ebp\n"
+            "movl 20(%%ecx), %%esp\n\t"
+            "movl 24(%%ecx), %%ebp\n\t"
 
             /* Stack pointer is 4 off from the call to __SEH3$_RegisterFrame */
-            "addl $4, %%esp\n"
+            "addl $4, %%esp\n\t"
 
             /* Jump into the exception handler */
-            "jmp *%[Target]\n"
+            "jmp *%[Target]"
             : :
             "c" (RegistrationFrame),
             "a" (RegistrationFrame->ScopeTable),
@@ -215,14 +215,14 @@ _SEH3$_JumpToTarget(
     {
         asm volatile (
             /* Load the registers */
-            "movl 20(%%ecx), %%esp\n"
-            "movl 24(%%ecx), %%ebp\n"
+            "movl 20(%%ecx), %%esp\n\t"
+            "movl 24(%%ecx), %%ebp\n\t"
 
             /* Stack pointer is 4 off from the call to __SEH3$_RegisterFrame */
-            "addl $4, %%esp\n"
+            "addl $4, %%esp\n\t"
 
             /* Jump into the exception handler */
-            "jmp *%[Target]\n"
+            "jmp *%[Target]"
             : :
             "c" (RegistrationFrame),
             "a" (RegistrationFrame->ScopeTable),
@@ -253,7 +253,7 @@ _SEH3$_except_handler(
     LONG FilterResult;
 
     /* Clear the direction flag. */
-    asm volatile ("cld\n" : : : "memory");
+    asm volatile ("cld" : : : "memory");
 
     /* Save the exception pointers on the stack */
     ExceptionPointers.ExceptionRecord = ExceptionRecord;
index 5d3432d..4d4f3fe 100644 (file)
@@ -33,11 +33,6 @@ else()
     set_image_base(ntoskrnl 0x80800000)
 endif()
 
-# Linker bug
-if(NOT MSVC AND LTCG)
-    add_target_link_flags(ntoskrnl "-shared")
-endif()
-
 target_link_libraries(ntoskrnl
     cportlib
     csq
index d6d3906..64d876d 100644 (file)
@@ -687,13 +687,13 @@ KiSystemCallTrampoline(IN PVOID Handler,
 
     __asm__ __volatile__
     (
-        "subl %1, %%esp\n"
-        "movl %%esp, %%edi\n"
-        "movl %2, %%esi\n"
-        "shrl $2, %1\n"
-        "rep movsd\n"
-        "call *%3\n"
-        "movl %%eax, %0\n"
+        "subl %1, %%esp\n\t"
+        "movl %%esp, %%edi\n\t"
+        "movl %2, %%esi\n\t"
+        "shrl $2, %1\n\t"
+        "rep movsd\n\t"
+        "call *%3\n\t"
+        "movl %%eax, %0"
         : "=r"(Result)
         : "c"(StackBytes),
           "d"(Arguments),
@@ -772,6 +772,7 @@ FORCEINLINE
 NTSTATUS
 KiConvertToGuiThread(VOID)
 {
+    NTSTATUS NTAPI PsConvertToGuiThread(VOID);
     NTSTATUS Result;
     PVOID StackFrame;
 
@@ -799,7 +800,7 @@ KiConvertToGuiThread(VOID)
         "addl %%esp, %1\n\t"
         "movl %1, %%ebp"
         : "=a"(Result), "=r"(StackFrame)
-        :
+        : "p"(PsConvertToGuiThread)
         : "%esp", "%ecx", "%edx", "memory"
     );
     return Result;
@@ -819,22 +820,24 @@ FORCEINLINE
 VOID
 KiSwitchToBootStack(IN ULONG_PTR InitialStack)
 {
+    VOID NTAPI KiSystemStartupBootStack(VOID);
+
     /* We have to switch to a new stack before continuing kernel initialization */
 #ifdef __GNUC__
     __asm__
     (
-        "movl %0, %%esp\n"
-        "subl %1, %%esp\n"
-        "pushl %2\n"
-        "jmp _KiSystemStartupBootStack@0\n"
+        "movl %0, %%esp\n\t"
+        "subl %1, %%esp\n\t"
+        "pushl %2\n\t"
+        "jmp _KiSystemStartupBootStack@0"
         :
         : "c"(InitialStack),
           "i"(NPX_FRAME_LENGTH + KTRAP_FRAME_ALIGN + KTRAP_FRAME_LENGTH),
-          "i"(CR0_EM | CR0_TS | CR0_MP)
+          "i"(CR0_EM | CR0_TS | CR0_MP),
+          "p"(KiSystemStartupBootStack)
         : "%esp"
     );
 #elif defined(_MSC_VER)
-    VOID NTAPI KiSystemStartupBootStack(VOID);
     __asm
     {
         mov esp, InitialStack
@@ -858,7 +861,7 @@ KiIret(VOID)
 #if defined(__GNUC__)
     __asm__ __volatile__
     (
-        "iret\n"
+        "iret"
     );
 #elif defined(_MSC_VER)
     __asm
index f162c6f..f70ea2e 100644 (file)
@@ -30,11 +30,6 @@ else()
     set_image_base(ntkrnlmp 0x80800000)
 endif()
 
-# Linker bug
-if(NOT MSVC AND LTCG)
-    add_target_link_flags(ntkrnlmp "-shared")
-endif()
-
 target_link_libraries(ntkrnlmp
     cportlib
     csq