Skip to content

Commit

Permalink
working with msvc, to test again on gcc
Browse files Browse the repository at this point in the history
  • Loading branch information
TaylorBeebe committed Nov 3, 2023
1 parent 1704732 commit 9b46cb8
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 88 deletions.
2 changes: 1 addition & 1 deletion BaseTools/Conf/tools_def.template
Original file line number Diff line number Diff line change
Expand Up @@ -2074,7 +2074,7 @@ DEFINE GCC_DEPS_FLAGS = -MMD -MF [email protected]
DEFINE GCC48_ALL_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -ffunction-sections -fdata-sections -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings
DEFINE GCC48_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x20
DEFINE GCC48_IA32_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m32 -march=i586 -malign-double -fno-stack-protector -D EFI32 -fno-asynchronous-unwind-tables -Wno-address -fno-omit-frame-pointer
DEFINE GCC48_X64_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m64 -fno-stack-protector "-DEFIAPI=__attribute__((ms_abi))" -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables -Wno-address -fno-omit-frame-pointer
DEFINE GCC48_X64_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m64 -fstack-protector-strong -mstack-protector-guard=global "-DEFIAPI=__attribute__((ms_abi))" -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables -Wno-address -fno-omit-frame-pointer
DEFINE GCC48_IA32_X64_ASLDLINK_FLAGS = DEF(GCC48_IA32_X64_DLINK_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable
DEFINE GCC48_IA32_X64_DLINK_FLAGS = DEF(GCC48_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive
DEFINE GCC48_IA32_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x220 DEF(GCC_DLINK2_FLAGS_COMMON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ StackCheckFailure (
VOID
)
{
DEBUG ((DEBUG_ERROR, "First Stack Cookie Exception Call!\n"));
return;
}
29 changes: 0 additions & 29 deletions MdePkg/Library/StackCheckLib/IA32/StackCheckFunctionsMsvc.asm

This file was deleted.

50 changes: 50 additions & 0 deletions MdePkg/Library/StackCheckLib/IA32/StackCheckFunctionsMsvc.nasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
;------------------------------------------------------------------------------
; IA32/StackCheckFunctionsMsvc.asm
;------------------------------------------------------------------------------

DEFAULT REL
SECTION .text

extern ASM_PFX(__security_cookie)
extern ASM_PFX(StackCheckFailure)
extern ASM_PFX(CpuDeadLoop)

;------------------------------------------------------------------------------
; VOID
; EFIAPI
; __report_rangecheckfailure (VOID);
;------------------------------------------------------------------------------
global ASM_PFX(__report_rangecheckfailure)
ASM_PFX(__report_rangecheckfailure):
call ASM_PFX(CpuDeadLoop)
ret

;------------------------------------------------------------------------------
; VOID
; EFIAPI
; __GSHandlerCheck (VOID);
;------------------------------------------------------------------------------
global ASM_PFX(__GSHandlerCheck)
ASM_PFX(__GSHandlerCheck):
call ASM_PFX(CpuDeadLoop)
ret

;------------------------------------------------------------------------------
; Checks the stack cookie value against __security_cookie and calls the
; stack cookie failure handler if there is a mismatch.
;------------------------------------------------------------------------------
; VOID
; EFIAPI
; __security_check_cookie (
; IN UINTN CheckValue);
;------------------------------------------------------------------------------
global @__security_check_cookie@4
@__security_check_cookie@4:
cmp ecx, [ASM_PFX(__security_cookie)]
jne security_check_cookie_failure
ret

security_check_cookie_failure:
call ASM_PFX(StackCheckFailure)
int FixedPcdGet8 (PcdStackCookieExceptionVector)
ret
27 changes: 0 additions & 27 deletions MdePkg/Library/StackCheckLib/StackCheckLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,6 @@ UINTN __security_cookie = 0xBEEBE;
#error "Unsupported compiler"
#endif

#ifdef _MSC_VER
/**
Called when a buffer check fails. This functionality is dependent on MSVC
C runtime libraries and so is unsupported in UEFI.
**/
VOID __cdecl
__report_rangecheckfailure (
VOID
)
{
CpuDeadLoop ();
}

/**
The GS handler is for checking the stack cookie during SEH or
EH exceptions and is unsupported in UEFI.
**/
VOID
__GSHandlerCheck (
VOID
)
{
CpuDeadLoop ();
}

#endif

/**
Initialize the security cookie.
**/
Expand Down
5 changes: 3 additions & 2 deletions MdePkg/Library/StackCheckLib/StackCheckLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
StackCheckFunctionsGcc.nasm |GCC

[Sources.IA32]
IA32/StackCheckFunctionsMsvc.asm | MSFT
IA32/StackCheckFunctionsMsvc.nasm | MSFT

[Sources.X64]
X64/StackCheckFunctionsMsvc.asm | MSFT
X64/StackCheckFunctionsMsvc.nasm | MSFT

[Packages]
MdePkg/MdePkg.dec
Expand All @@ -40,3 +40,4 @@

[BuildOptions]
GCC:*_*_*_CC_FLAGS = -fno-lto
MSFT:*_*_*_CC_FLAGS = /GL-
29 changes: 0 additions & 29 deletions MdePkg/Library/StackCheckLib/X64/StackCheckFunctionsMsvc.asm

This file was deleted.

51 changes: 51 additions & 0 deletions MdePkg/Library/StackCheckLib/X64/StackCheckFunctionsMsvc.nasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
;------------------------------------------------------------------------------
; X64/StackCheckFunctionsMsvc.asm
;------------------------------------------------------------------------------

DEFAULT REL
SECTION .text

extern ASM_PFX(StackCheckFailure)
extern ASM_PFX(__security_cookie)
extern ASM_PFX(CpuDeadLoop)

;------------------------------------------------------------------------------
; VOID
; EFIAPI
; __report_rangecheckfailure (VOID);
;------------------------------------------------------------------------------
global ASM_PFX(__report_rangecheckfailure)
ASM_PFX(__report_rangecheckfailure):
call ASM_PFX(CpuDeadLoop)
ret

;------------------------------------------------------------------------------
; VOID
; EFIAPI
; __GSHandlerCheck (VOID);
;------------------------------------------------------------------------------
global ASM_PFX(__GSHandlerCheck)
ASM_PFX(__GSHandlerCheck):
call ASM_PFX(CpuDeadLoop)
ret


;------------------------------------------------------------------------------
; Checks the stack cookie value against __security_cookie and calls the
; stack cookie failure handler if there is a mismatch.
;------------------------------------------------------------------------------
; VOID
; EFIAPI
; __security_check_cookie (
; IN UINTN CheckValue);
;------------------------------------------------------------------------------
global ASM_PFX(__security_check_cookie)
ASM_PFX(__security_check_cookie):
cmp rcx, [ASM_PFX(__security_cookie)]
jne security_check_cookie_failure
ret

security_check_cookie_failure:
call StackCheckFailure
int FixedPcdGet8 (PcdStackCookieExceptionVector)
ret

0 comments on commit 9b46cb8

Please sign in to comment.