[NTOSKRNL][PSEH3]

- 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
This commit is contained in:
Dmitry Gorbachev 2014-08-06 23:10:08 +00:00
parent 9b201b7180
commit ddf5ed131e
5 changed files with 55 additions and 62 deletions

View 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 */ /* This attribute allows automatic cleanup of the registered frames */
#define _SEH3$_AUTO_CLEANUP __attribute__((cleanup(_SEH3$_AutoCleanup))) #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! */ /* CLANG specific definitions! */
#ifdef __clang__ #ifdef __clang__
@ -122,14 +138,6 @@ void * __cdecl __attribute__((error("Can only be used inside an exception filter
/* CLANG doesn't have asm goto! */ /* CLANG doesn't have asm goto! */
#define _SEH3$_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) \ #define _SEH3$_RegisterFrame_(_TrylevelFrame, _DataTable) \
do { \ do { \
int result = _SEH3$_RegisterFrameWithNonVolatiles(_TrylevelFrame, _DataTable, __builtin_alloca(0)); \ int result = _SEH3$_RegisterFrameWithNonVolatiles(_TrylevelFrame, _DataTable, __builtin_alloca(0)); \
@ -141,14 +149,6 @@ _SEH3$_RegisterFrameWithNonVolatiles(
} \ } \
} while(0) } 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) \ #define _SEH3$_RegisterTryLevel_(_TrylevelFrame, _DataTable) \
do { \ do { \
int result = _SEH3$_RegisterTryLevelWithNonVolatiles(_TrylevelFrame, _DataTable, __builtin_alloca(0)); \ int result = _SEH3$_RegisterTryLevelWithNonVolatiles(_TrylevelFrame, _DataTable, __builtin_alloca(0)); \
@ -171,21 +171,21 @@ _SEH3$_RegisterTryLevelWithNonVolatiles(
#ifdef __cplusplus #ifdef __cplusplus
#define _SEH3$_CALL_WRAPPER(_Function, _TrylevelFrame, _DataTable) \ #define _SEH3$_CALL_WRAPPER(_Function, _TrylevelFrame, _DataTable) \
asm goto ("leal %0, %%eax\n" \ asm goto ("leal %0, %%eax\n\t" \
"leal %1, %%edx\n" \ "leal %1, %%edx\n\t" \
"call " #_Function "WithStackLayout\n" \ "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" \ : "eax", "edx", "memory" \
: _SEH3$_l_BeforeTry, _SEH3$_l_HandlerTarget, _SEH3$_l_OnException, _SEH3$_l_BeforeFilterOrFinally, _SEH3$_l_FilterOrFinally) : _SEH3$_l_BeforeTry, _SEH3$_l_HandlerTarget, _SEH3$_l_OnException, _SEH3$_l_BeforeFilterOrFinally, _SEH3$_l_FilterOrFinally)
#else #else
#define _SEH3$_CALL_WRAPPER(_Function, _TrylevelFrame, _DataTable) \ #define _SEH3$_CALL_WRAPPER(_Function, _TrylevelFrame, _DataTable) \
asm goto ("leal %0, %%eax\n" \ asm goto ("leal %0, %%eax\n\t" \
"leal %1, %%edx\n" \ "leal %1, %%edx\n\t" \
"call " #_Function "\n" \ "call " #_Function \
: \ : \
: "m" (*(_TrylevelFrame)), "m" (*(_DataTable)) \ : "m" (*(_TrylevelFrame)), "m" (*(_DataTable)), "p" (_SEH3$_RegisterFrameWithNonVolatiles) \
: "eax", "edx", "ecx", "memory" \ : "eax", "edx", "ecx", "memory" \
: _SEH3$_l_BeforeTry, _SEH3$_l_HandlerTarget, _SEH3$_l_OnException, _SEH3$_l_BeforeFilterOrFinally, _SEH3$_l_FilterOrFinally) : _SEH3$_l_BeforeTry, _SEH3$_l_HandlerTarget, _SEH3$_l_OnException, _SEH3$_l_BeforeFilterOrFinally, _SEH3$_l_FilterOrFinally)
#endif #endif
@ -227,8 +227,8 @@ _SEH3$_AutoCleanup(
/* On invocation, the AllocaFrame field is loaded with the return esp value */ /* On invocation, the AllocaFrame field is loaded with the return esp value */
#define _SEH3$_NESTED_FUNC_RETURN(_Result) \ #define _SEH3$_NESTED_FUNC_RETURN(_Result) \
/* Restore esp and return to the caller */ \ /* Restore esp and return to the caller */ \
asm volatile ("movl %[FixedEsp], %%esp\nret\n" \ asm volatile ("movl %[FixedEsp], %%esp\n\tret" \
: : "a"(_Result), [FixedEsp]"m"(_SEH3$_TrylevelFrame.AllocaFrame) : "ebx", "ecx", "edx", "esi", "edi", "flags", "memory") : : "a" (_Result), [FixedEsp] "m" (_SEH3$_TrylevelFrame.AllocaFrame) : "ebx", "ecx", "edx", "esi", "edi", "flags", "memory")
/* The filter "function" */ /* The filter "function" */
#define _SEH3$_DEFINE_FILTER_FUNC(_Name, expression) \ #define _SEH3$_DEFINE_FILTER_FUNC(_Name, expression) \

View file

@ -82,8 +82,8 @@ _SEH3$_InvokeNestedFunctionFilter(
/* Second call to get the filter result */ /* Second call to get the filter result */
"mov $1, %%ecx\n\t" "mov $1, %%ecx\n\t"
"call *%[Filter]\n\t" "call *%[Filter]"
: "=a"(FilterResult) : "=a" (FilterResult)
: [RegistrationFrame] "m" (RegistrationFrame), [Filter] "m" (Filter) : [RegistrationFrame] "m" (RegistrationFrame), [Filter] "m" (Filter)
: "ecx", "edx"); : "ecx", "edx");
@ -197,14 +197,14 @@ _SEH3$_JumpToTarget(
{ {
asm volatile ( asm volatile (
/* Load the registers */ /* Load the registers */
"movl 20(%%ecx), %%esp\n" "movl 20(%%ecx), %%esp\n\t"
"movl 24(%%ecx), %%ebp\n" "movl 24(%%ecx), %%ebp\n\t"
/* Stack pointer is 4 off from the call to __SEH3$_RegisterFrame */ /* 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 */ /* Jump into the exception handler */
"jmp *%[Target]\n" "jmp *%[Target]"
: : : :
"c" (RegistrationFrame), "c" (RegistrationFrame),
"a" (RegistrationFrame->ScopeTable), "a" (RegistrationFrame->ScopeTable),
@ -215,14 +215,14 @@ _SEH3$_JumpToTarget(
{ {
asm volatile ( asm volatile (
/* Load the registers */ /* Load the registers */
"movl 20(%%ecx), %%esp\n" "movl 20(%%ecx), %%esp\n\t"
"movl 24(%%ecx), %%ebp\n" "movl 24(%%ecx), %%ebp\n\t"
/* Stack pointer is 4 off from the call to __SEH3$_RegisterFrame */ /* 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 */ /* Jump into the exception handler */
"jmp *%[Target]\n" "jmp *%[Target]"
: : : :
"c" (RegistrationFrame), "c" (RegistrationFrame),
"a" (RegistrationFrame->ScopeTable), "a" (RegistrationFrame->ScopeTable),
@ -253,7 +253,7 @@ _SEH3$_except_handler(
LONG FilterResult; LONG FilterResult;
/* Clear the direction flag. */ /* Clear the direction flag. */
asm volatile ("cld\n" : : : "memory"); asm volatile ("cld" : : : "memory");
/* Save the exception pointers on the stack */ /* Save the exception pointers on the stack */
ExceptionPointers.ExceptionRecord = ExceptionRecord; ExceptionPointers.ExceptionRecord = ExceptionRecord;

View file

@ -33,11 +33,6 @@ else()
set_image_base(ntoskrnl 0x80800000) set_image_base(ntoskrnl 0x80800000)
endif() endif()
# Linker bug
if(NOT MSVC AND LTCG)
add_target_link_flags(ntoskrnl "-shared")
endif()
target_link_libraries(ntoskrnl target_link_libraries(ntoskrnl
cportlib cportlib
csq csq

View file

@ -687,13 +687,13 @@ KiSystemCallTrampoline(IN PVOID Handler,
__asm__ __volatile__ __asm__ __volatile__
( (
"subl %1, %%esp\n" "subl %1, %%esp\n\t"
"movl %%esp, %%edi\n" "movl %%esp, %%edi\n\t"
"movl %2, %%esi\n" "movl %2, %%esi\n\t"
"shrl $2, %1\n" "shrl $2, %1\n\t"
"rep movsd\n" "rep movsd\n\t"
"call *%3\n" "call *%3\n\t"
"movl %%eax, %0\n" "movl %%eax, %0"
: "=r"(Result) : "=r"(Result)
: "c"(StackBytes), : "c"(StackBytes),
"d"(Arguments), "d"(Arguments),
@ -772,6 +772,7 @@ FORCEINLINE
NTSTATUS NTSTATUS
KiConvertToGuiThread(VOID) KiConvertToGuiThread(VOID)
{ {
NTSTATUS NTAPI PsConvertToGuiThread(VOID);
NTSTATUS Result; NTSTATUS Result;
PVOID StackFrame; PVOID StackFrame;
@ -799,7 +800,7 @@ KiConvertToGuiThread(VOID)
"addl %%esp, %1\n\t" "addl %%esp, %1\n\t"
"movl %1, %%ebp" "movl %1, %%ebp"
: "=a"(Result), "=r"(StackFrame) : "=a"(Result), "=r"(StackFrame)
: : "p"(PsConvertToGuiThread)
: "%esp", "%ecx", "%edx", "memory" : "%esp", "%ecx", "%edx", "memory"
); );
return Result; return Result;
@ -819,22 +820,24 @@ FORCEINLINE
VOID VOID
KiSwitchToBootStack(IN ULONG_PTR InitialStack) KiSwitchToBootStack(IN ULONG_PTR InitialStack)
{ {
VOID NTAPI KiSystemStartupBootStack(VOID);
/* We have to switch to a new stack before continuing kernel initialization */ /* We have to switch to a new stack before continuing kernel initialization */
#ifdef __GNUC__ #ifdef __GNUC__
__asm__ __asm__
( (
"movl %0, %%esp\n" "movl %0, %%esp\n\t"
"subl %1, %%esp\n" "subl %1, %%esp\n\t"
"pushl %2\n" "pushl %2\n\t"
"jmp _KiSystemStartupBootStack@0\n" "jmp _KiSystemStartupBootStack@0"
: :
: "c"(InitialStack), : "c"(InitialStack),
"i"(NPX_FRAME_LENGTH + KTRAP_FRAME_ALIGN + KTRAP_FRAME_LENGTH), "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" : "%esp"
); );
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
VOID NTAPI KiSystemStartupBootStack(VOID);
__asm __asm
{ {
mov esp, InitialStack mov esp, InitialStack
@ -858,7 +861,7 @@ KiIret(VOID)
#if defined(__GNUC__) #if defined(__GNUC__)
__asm__ __volatile__ __asm__ __volatile__
( (
"iret\n" "iret"
); );
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
__asm __asm

View file

@ -30,11 +30,6 @@ else()
set_image_base(ntkrnlmp 0x80800000) set_image_base(ntkrnlmp 0x80800000)
endif() endif()
# Linker bug
if(NOT MSVC AND LTCG)
add_target_link_flags(ntkrnlmp "-shared")
endif()
target_link_libraries(ntkrnlmp target_link_libraries(ntkrnlmp
cportlib cportlib
csq csq