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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BaseCpuLib MdePkg BaseCpuLib: Convert X64/CpuSleep.asm to NASM 2016-06-28 09:51:45 +08:00
BaseDebugLibNull MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BaseDebugLibSerialPort MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BaseDebugPrintErrorLevelLib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BasePalLibNull MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BasePcdLibNull MdePkg: Follow PI1.4a to fix artificial limitation of SkuId range 2016-05-23 10:48:53 +08:00
BasePciCf8Lib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BasePciExpressLib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BasePciLibCf8 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BasePciLibPciExpress MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BasePostCodeLibDebug MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BasePostCodeLibPort80 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BasePrintLib MdePkg/BasePrintLib: Fix incomplete print output 2018-01-02 16:31:19 +08:00
BaseReportStatusCodeLibNull MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BaseRngLib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BaseS3BootScriptLibNull MdePkg, MdeModulePkg: S3BootScriptSaveMemPoll(): accept 64-bit LoopTimes 2017-01-03 12:22:47 +01:00
BaseS3IoLib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BaseS3StallLib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BaseSerialPortLibNull MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BaseSmbusLibNull MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BaseStackCheckLib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BaseSynchronizationLib MdePkg/BaseSynchronizationLib: Fix function names in function headers 2016-11-17 17:08:26 -08:00
BaseTimerLibNullTemplate MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
BaseUefiDecompressLib MdePkg: Fix Xcode 9 Beta treating 32-bit left shift as undefined 2017-08-11 08:47:00 +08:00
DxeCoreEntryPoint MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
DxeCoreHobLib MdePkg HobLib: Add BuildFv3Hob API 2017-10-10 20:54:32 +08:00
DxeExtendedSalLib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
DxePcdLib MdePkg: Follow PI1.4a to fix artificial limitation of SkuId range 2016-05-23 10:48:53 +08:00
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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
DxeRuntimePciExpressLib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
DxeSalLibEsal MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
DxeServicesLib MdePkg DxeServicesLib: Handle potential NULL FvHandle 2017-05-08 08:57:03 +08:00
DxeServicesTableLib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
DxeSmbusLib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
DxeTimerLibEsal MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
PciSegmentLibSegmentInfo MdePkg/PciSegmentLibSegmentInfo: fix typo in PciSegmentBitFieldAnd*() 2017-09-06 10:43:53 +08:00
PeiCoreEntryPoint MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
PeiPcdLib MdePkg: Follow PI1.4a to fix artificial limitation of SkuId range 2016-05-23 10:48:53 +08:00
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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
PeiServicesLib MdePkg PeiServicesLib: Add PeiServicesFreePages 2017-09-04 13:45:46 +08:00
PeiServicesTablePointerLib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
PeiServicesTablePointerLibIdt MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
PeiServicesTablePointerLibKr7 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
PeiSmbusLibSmbus2Ppi MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
PeimEntryPoint MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
SecPeiDxeTimerLibCpu MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
UefiApplicationEntryPoint MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
UefiBootServicesTableLib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
UefiDebugLibConOut MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
UefiDebugLibDebugPortProtocol MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
UefiDebugLibStdErr MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
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 MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
UefiSalLib MdePkg: Convert all .uni files to utf-8 2015-12-15 04:53:50 +00:00
UefiScsiLib MdePkg UefiScsiLib: Raise the Tpl of async IO callback to TPL_NOTIFY 2015-12-22 13:58:09 +00:00
UefiUsbLib MdePkg: Fix some typing errors 2016-10-07 18:05:37 -07:00