audk/MdePkg/Library
M1cha 2117989c26 MdePkg/BaseLib: add attribute 'RETURNS_TWICE' to SetJump
When compiling with any ARM toolchain and Os, registers can get
trashed when returning for the second time from SetJump because GCC
only handles this correctly when using standard names like 'setjmp' or
'getcontext'. When different names are used you have to use the
attribute 'returns_twice' to tell gcc to be extra careful.

example:
extern int  FN_NAME(void*);

void jmp_buf_set(void *jmpb, void (*f)(void))
{
  if (!FN_NAME(jmpb))
    f();
}

this code produces this wrong code with Os:
00000000 <jmp_buf_set>:
   0: e92d4010 push {r4, lr}
   4: e1a04001 mov r4, r1
   8: ebfffffe bl 0 <nonstandard_setjmp>
   c: e3500000 cmp r0, #0
  10: 01a03004 moveq r3, r4
  14: 08bd4010 popeq {r4, lr}
  18: 012fff13 bxeq r3
  1c: e8bd4010 pop {r4, lr}
  20: e12fff1e bx lr

The generated code pushes backups of r4 and lr to the stack and then
saves all registers using nonstandard_setjmp.
Then it pops the stack and jumps to the function in r3 which is the
main problem because now the function can overwrite our register
backups on the stack.
When we return a second time from the call to nonstandard_setjmp, the
stack pointer has it's original(pushed) position and when the code
pops r4 and lr from the stack the values are not guaranteed to be the
same.

When using a standard name like setjmp or getcontext or adding
'__attribute__((returns_twice))' to nonstandard_setjmp's declaration
the code looks different:

00000000 <jmp_buf_set>:
   0: e92d4007 push {r0, r1, r2, lr}
   4: e58d1004 str r1, [sp, #4]
   8: ebfffffe bl 0 <setjmp>
   c: e3500000 cmp r0, #0
  10: 059d3004 ldreq r3, [sp, #4]
  14: 01a0e00f moveq lr, pc
  18: 012fff13 bxeq r3
  1c: e28dd00c add sp, sp, #12
  20: e49de004 pop {lr} ; (ldr lr, [sp], #4)
  24: e12fff1e bx lr

Here the problem is being solved by restoring r3 from the stack
without popping it.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
2018-01-10 11:42:17 +08:00
..
BaseCacheMaintenanceLib
BaseCpuLib MdePkg BaseCpuLib: Convert X64/CpuSleep.asm to NASM 2016-06-28 09:51:45 +08:00
BaseDebugLibNull
BaseDebugLibSerialPort
BaseDebugPrintErrorLevelLib
BaseExtractGuidedSectionLib MdePkg: Fix some typing errors 2016-10-07 18:05:37 -07:00
BaseIoLibIntrinsic MdePkg/BaseIoLibIntrinsic: fix SEV (=unrolled) variants of IoWriteFifoXX() 2017-09-11 22:28:05 +02:00
BaseLib MdePkg/BaseLib: add attribute 'RETURNS_TWICE' to SetJump 2018-01-10 11:42:17 +08:00
BaseMemoryLib MdePkg/MemoryLib: Refine InternalMemSetMem16|32|64 functions logic 2016-12-22 16:17:16 +08:00
BaseMemoryLibMmx MdePkg/BaseMemoryLib*: check for zero length in ZeroMem () 2016-11-04 09:53:01 +00:00
BaseMemoryLibOptDxe MdePkg/BaseMemoryLib*: check for zero length in ZeroMem () 2016-11-04 09:53:01 +00:00
BaseMemoryLibOptPei MdePkg/BaseMemoryLib*: check for zero length in ZeroMem () 2016-11-04 09:53:01 +00:00
BaseMemoryLibRepStr MdePkg/BaseMemoryLib*: check for zero length in ZeroMem () 2016-11-04 09:53:01 +00:00
BaseMemoryLibSse2 MdePkg/BaseMemoryLib*: check for zero length in ZeroMem () 2016-11-04 09:53:01 +00:00
BaseOrderedCollectionRedBlackTreeLib
BasePalLibNull
BasePcdLibNull
BasePciCf8Lib
BasePciExpressLib
BasePciLibCf8
BasePciLibPciExpress
BasePciSegmentInfoLibNull MdePkg/PciSegmentInfoLib: Add PciSegmentInfoLib class and instance. 2017-08-28 16:47:04 +08:00
BasePciSegmentLibPci MdePkg/PciSegmentLib: Fix typo in function header comments 2017-08-28 16:47:03 +08:00
BasePeCoffExtraActionLibNull
BasePeCoffGetEntryPointLib PeCoffGetEntryPointLib: Fix spelling issue 2017-04-26 08:58:18 +08:00
BasePeCoffLib MdePkg: Refine casting expression result to bigger size 2017-03-06 14:18:45 +08:00
BasePerformanceLibNull
BasePostCodeLibDebug
BasePostCodeLibPort80
BasePrintLib MdePkg/BasePrintLib: Fix incomplete print output 2018-01-02 16:31:19 +08:00
BaseReportStatusCodeLibNull
BaseRngLib
BaseS3BootScriptLibNull MdePkg, MdeModulePkg: S3BootScriptSaveMemPoll(): accept 64-bit LoopTimes 2017-01-03 12:22:47 +01:00
BaseS3IoLib
BaseS3PciLib MdePkg: Refine casting expression result to bigger size 2017-03-06 14:18:45 +08:00
BaseS3PciSegmentLib MdePkg: Correct BaseS3PciSegmentLib module name to match its uni file 2017-10-10 18:10:17 +08:00
BaseS3SmbusLib
BaseS3StallLib
BaseSerialPortLibNull
BaseSmbusLibNull
BaseStackCheckLib
BaseSynchronizationLib MdePkg/BaseSynchronizationLib: Fix function names in function headers 2016-11-17 17:08:26 -08:00
BaseTimerLibNullTemplate
BaseUefiDecompressLib MdePkg: Fix Xcode 9 Beta treating 32-bit left shift as undefined 2017-08-11 08:47:00 +08:00
DxeCoreEntryPoint
DxeCoreHobLib MdePkg HobLib: Add BuildFv3Hob API 2017-10-10 20:54:32 +08:00
DxeExtendedSalLib
DxeExtractGuidedSectionLib MdePkg: Fix MSFT C4255 warning 2017-11-14 18:18:48 +08:00
DxeHobLib MdePkg HobLib: Add BuildFv3Hob API 2017-10-10 20:54:32 +08:00
DxeHstiLib MdePkg DxeHstiLib: Fix memory leak issue 2017-07-18 10:35:36 +08:00
DxeIoLibCpuIo2 MdePkg: Avoid Non-Boolean type used as Boolean 2017-01-20 15:40:59 +08:00
DxeIoLibEsal MdePkg/DxeIoLibEsal: Add new Fifo routines in IoLib class 2017-01-17 10:11:20 +08:00
DxePalLibEsal
DxePcdLib
DxePciLibEsal MdePkg: Fix typos in comments 2016-10-21 16:40:51 +08:00
DxePciSegmentLibEsal MdePkg: Fix typos in comments 2016-10-21 16:40:51 +08:00
DxeRuntimeExtendedSalLib
DxeRuntimePciExpressLib
DxeSalLibEsal
DxeServicesLib MdePkg DxeServicesLib: Handle potential NULL FvHandle 2017-05-08 08:57:03 +08:00
DxeServicesTableLib
DxeSmbusLib
DxeTimerLibEsal
PciSegmentLibSegmentInfo MdePkg/PciSegmentLibSegmentInfo: fix typo in PciSegmentBitFieldAnd*() 2017-09-06 10:43:53 +08:00
PeiCoreEntryPoint
PeiDxePostCodeLibReportStatusCode MdePkg PeiDxePostCodeLibReportStatusCode: Correct files with CRLF line ending 2016-07-29 09:18:12 +08:00
PeiExtractGuidedSectionLib MdePkg: Fix typos in comments 2016-10-21 16:40:51 +08:00
PeiHobLib MdePkg HobLib: Add BuildFv3Hob API 2017-10-10 20:54:32 +08:00
PeiIoLibCpuIo MdePkg/PeiIoLibCpuIo: Add new Fifo routines in IoLib class 2017-01-17 10:11:14 +08:00
PeiMemoryAllocationLib MdePkg PeiMemoryAllocationLib: Update InternalAllocateAlignedPages 2017-09-04 13:45:47 +08:00
PeiMemoryLib MdePkg/MemoryLib: Refine InternalMemSetMem16|32|64 functions logic 2016-12-22 16:17:16 +08:00
PeiPalLib
PeiPcdLib
PeiPciLibPciCfg2 MdePkg: Fix typos in comments 2016-10-21 16:40:51 +08:00
PeiPciSegmentLibPciCfg2 MdePkg/PciSegmentLib: Fix typo in function header comments 2017-08-28 16:47:03 +08:00
PeiResourcePublicationLib
PeiServicesLib MdePkg PeiServicesLib: Add PeiServicesFreePages 2017-09-04 13:45:46 +08:00
PeiServicesTablePointerLib
PeiServicesTablePointerLibIdt
PeiServicesTablePointerLibKr7
PeiSmbusLibSmbus2Ppi
PeimEntryPoint
SecPeiDxeTimerLibCpu
SmiHandlerProfileLibNull MdePkg/SmiHandlerProfile: Add Context support in Unregister 2017-03-13 16:04:11 +08:00
SmmIoLib MdePkg SmmIoLib: Use NULL pointer check instead of useless Status check 2017-06-06 09:07:10 +08:00
SmmIoLibSmmCpuIo2 MdePkg: Avoid Non-Boolean type used as Boolean 2017-01-20 15:40:59 +08:00
SmmLibNull
SmmMemLib MdePkg SmmMemLib: Remove ASSERT in SmmIsBufferOutsideSmmValid 2017-06-06 09:07:09 +08:00
SmmMemoryAllocationLib MdePkg: Refine casting expression result to bigger size 2017-03-06 14:18:45 +08:00
SmmPciExpressLib MdePkg: Add SMM PciExpressLib Instance 2016-09-27 11:01:23 +08:00
SmmPciLibPciRootBridgeIo MdePkg: Fix typos in comments 2016-10-21 16:40:51 +08:00
SmmPeriodicSmiLib MdePkg: Fix typos in comments 2016-10-21 16:40:51 +08:00
SmmServicesTableLib
UefiApplicationEntryPoint
UefiBootServicesTableLib
UefiDebugLibConOut
UefiDebugLibDebugPortProtocol
UefiDebugLibStdErr
UefiDevicePathLib MdePkg/UefiDevicePathLib: Add DevPathFromTextDns and DevPathToTextDns libraries 2017-08-14 13:18:23 +08:00
UefiDevicePathLibDevicePathProtocol MdePkg DevicePathLib: Validate before touch input buffer. 2016-11-09 17:49:15 +08:00
UefiDriverEntryPoint
UefiFileHandleLib MdePkg/UefiFileHandleLib: Refine the check for valid Ascii character 2017-01-12 21:26:26 +08:00
UefiLib MdePkg/UefiLib: Avoid mis-calculate of graphic console size 2017-04-14 13:16:05 +08:00
UefiMemoryAllocationLib MdePkg: Refine casting expression result to bigger size 2017-03-06 14:18:45 +08:00
UefiMemoryLib MdePkg/MemoryLib: Refine InternalMemSetMem16|32|64 functions logic 2016-12-22 16:17:16 +08:00
UefiPalLib
UefiPciLibPciRootBridgeIo MdePkg: Fix typos in comments 2016-10-21 16:40:51 +08:00
UefiPciSegmentLibPciRootBridgeIo MdePkg/PciSegmentLib: Fix typo in function header comments 2017-08-28 16:47:03 +08:00
UefiRuntimeLib MdePkg: Deprecate EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 2017-11-01 22:25:18 +08:00
UefiRuntimeServicesTableLib
UefiSalLib
UefiScsiLib
UefiUsbLib MdePkg: Fix some typing errors 2016-10-07 18:05:37 -07:00