audk/MdePkg/Include/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
..
BaseLib.h MdePkg/BaseLib: add attribute 'RETURNS_TWICE' to SetJump 2018-01-10 11:42:17 +08:00
BaseMemoryLib.h MdePkg BaseMemoryLib: Add C implementation of API IsZeroBuffer() 2016-08-22 18:54:30 +08:00
CacheMaintenanceLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
CpuLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
DebugLib.h MdePkg/DebugLib.h: add ASSERT_RETURN_ERROR() 2016-10-25 10:46:07 +02:00
DebugPrintErrorLevelLib.h MdePkg: Fix some typing errors in the header files 2016-10-07 18:09:09 -07:00
DevicePathLib.h Add 4 APIs to DevicePathLib: ConvertDeviceNodeToText, ConvertDevicePathToText, ConvertTextToDeviceNode and ConvertTextToDevicePath. 2013-07-26 03:00:21 +00:00
DxeCoreEntryPoint.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
DxeServicesLib.h MdePkg: Add a new DxeServicesLib GetFileDevicePathFromAnyFv () function 2015-10-23 05:53:08 +00:00
DxeServicesTableLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
ExtendedSalLib.h Add ESAL support libraries to MdePkg 2011-06-10 18:58:08 +00:00
ExtractGuidedSectionLib.h Add API to ExtractGuidedSectionLib.h to retrieve the set of registered handlers. 2010-11-04 05:51:32 +00:00
FileHandleLib.h MdePkg/Include: Add include file to FileHandleLib.h 2017-01-10 12:31:28 -08:00
HobLib.h MdePkg HobLib: Add BuildFv3Hob API 2017-10-10 20:54:32 +08:00
HstiLib.h Add HSTI support. 2015-01-19 06:08:23 +00:00
IoLib.h MdePkg: Expand BaseIoLibIntrinsic (IoLib class) library 2017-01-17 10:09:50 +08:00
MemoryAllocationLib.h Update MemoryAllocationLib.AllocateAlignedPages API comments for memory overflow ASSERT case. 2013-12-31 07:19:09 +00:00
OrderedCollectionLib.h MdePkg: introduce OrderedCollectionLib library class 2014-08-12 07:28:52 +00:00
PalLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
PcdLib.h MdePkg: Correct comments of macros FixedPcdGetX/PatchPcdXXX in PcdLib.h 2017-01-18 15:23:08 +08:00
PciCf8Lib.h Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
PciExpressLib.h MdePkg/PciExpressLib.h: Add missing include of PciExpress21.h 2018-01-09 13:18:20 +08:00
PciLib.h Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
PciSegmentInfoLib.h MdePkg/PciSegmentInfoLib: Add PciSegmentInfoLib class and instance. 2017-08-28 16:47:04 +08:00
PciSegmentLib.h MdePkg/PciSegmentLib: Fix typo in function header comments 2017-08-28 16:47:03 +08:00
PeCoffExtraActionLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
PeCoffGetEntryPointLib.h PeCoffGetEntryPointLib: Fix spelling issue 2017-04-26 08:58:18 +08:00
PeCoffLib.h MdePkg: Fix some typing errors in the header files 2016-10-07 18:09:09 -07:00
PeiCoreEntryPoint.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
PeiServicesLib.h MdePkg PeiServicesLib: Add PeiServicesFreePages 2017-09-04 13:45:46 +08:00
PeiServicesTablePointerLib.h Add VOID MigratePeiServicesTablePointer() to fix'Deprecated declaration'. 2014-01-17 06:06:30 +00:00
PeimEntryPoint.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
PerformanceLib.h MdePkg: Update PerformanceLib comments not to check Identifier. 2016-04-11 16:20:28 +08:00
PostCodeLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
PrintLib.h MdePkg/BasePrintLib: Refine the comment for AsciiValueToStringS API 2017-03-13 11:09:23 +08:00
ReportStatusCodeLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
ResourcePublicationLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
RngLib.h MdePkg: Create GetRandomNumber128 in RngLib 2015-10-09 06:03:17 +00:00
S3BootScriptLib.h MdePkg, MdeModulePkg: S3BootScriptSaveMemPoll(): accept 64-bit LoopTimes 2017-01-03 12:22:47 +01:00
S3IoLib.h Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
S3PciLib.h Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
S3PciSegmentLib.h MdePkg/S3PciSegmentLib: Add S3PciSegmentLib class and instance. 2017-08-28 16:47:05 +08:00
S3SmbusLib.h MdePkg: Add S3 library interfaces and base implementations 2011-08-29 22:16:28 +00:00
S3StallLib.h MdePkg: Add S3 library interfaces and base implementations 2011-08-29 22:16:28 +00:00
SalLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
SerialPortLib.h MdePkg SerialPortLib: Upstream Get(Set)Control/SetAttributes interfaces 2015-11-26 08:46:52 +00:00
SmbusLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
SmiHandlerProfileLib.h MdePkg/SmiHandlerProfile: Add Context support in Unregister 2017-03-13 16:04:11 +08:00
SmmIoLib.h MdePkg/SmmIoLib: Add header file. 2017-04-26 09:22:17 +08:00
SmmLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
SmmMemLib.h Add SmmMemLib, which can be used by SMM driver or SMM core to check communication buffer. 2015-02-02 14:40:44 +00:00
SmmPeriodicSmiLib.h MdePkg: Fix typos in comments 2016-10-21 16:40:51 +08:00
SmmServicesTableLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
SynchronizationLib.h MdePkg/Include: Add volatile to SynchronizationLib parameters 2016-11-17 17:08:11 -08:00
TimerLib.h Add new API GetTimeInNanoSecond() to TimerLib to convert elapsed ticks to time in unit of nanoseconds. 2011-08-25 05:59:17 +00:00
UefiApplicationEntryPoint.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
UefiBootServicesTableLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
UefiDecompressLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
UefiDriverEntryPoint.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
UefiLib.h MdePkg UefiLib: Make the event empty function public 2017-01-20 15:51:16 +08:00
UefiRuntimeLib.h MdePkg: update comments in ResetSystem() according to UEFI2.7 2017-06-20 09:29:42 +08:00
UefiRuntimeServicesTableLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00
UefiScsiLib.h MdePkg UefiScsiLib: Add non-blocking support for SCSI Read/Write command 2015-12-11 01:57:41 +00:00
UefiUsbLib.h Update the copyright notice format 2010-04-23 15:46:20 +00:00