#endif\r
#endif\r
\r
+///\r
+/// Tell the code optimizer that the function will return twice.\r
+/// This prevents wrong optimizations which can cause bugs.\r
+///\r
+#ifndef RETURNS_TWICE\r
+ #if defined (__GNUC__) || defined (__clang__)\r
+ ///\r
+ /// Tell the code optimizer that the function will return twice.\r
+ /// This prevents wrong optimizations which can cause bugs.\r
+ ///\r
+ #define RETURNS_TWICE __attribute__((returns_twice))\r
+ #else\r
+ ///\r
+ /// Tell the code optimizer that the function will return twice.\r
+ /// This prevents wrong optimizations which can cause bugs.\r
+ ///\r
+ #define RETURNS_TWICE\r
+ #endif\r
+#endif\r
+\r
//\r
// For symbol name in assembly code, an extra "_" is sometimes necessary\r
//\r
#define MAX_INT64 ((INT64)0x7FFFFFFFFFFFFFFFULL)\r
#define MAX_UINT64 ((UINT64)0xFFFFFFFFFFFFFFFFULL)\r
\r
+///\r
+/// Minimum values for the signed UEFI Data Types\r
+///\r
+#define MIN_INT8 (((INT8) -127) - 1)\r
+#define MIN_INT16 (((INT16) -32767) - 1)\r
+#define MIN_INT32 (((INT32) -2147483647) - 1)\r
+#define MIN_INT64 (((INT64) -9223372036854775807LL) - 1)\r
+\r
#define BIT0 0x00000001\r
#define BIT1 0x00000002\r
#define BIT2 0x00000004\r
#define BASE_8EB 0x8000000000000000ULL\r
\r
//\r
-// Support for variable length argument lists using the ANSI standard.\r
+// Support for variable argument lists in freestanding edk2 modules.\r
//\r
-// Since we are using the ANSI standard we used the standard naming and\r
-// did not follow the coding convention\r
+// For modules that use the ISO C library interfaces for variable\r
+// argument lists, refer to "StdLib/Include/stdarg.h".\r
//\r
// VA_LIST - typedef for argument list.\r
// VA_START (VA_LIST Marker, argument before the ...) - Init Marker for use.\r
// VA_END (VA_LIST Marker) - Clear Marker\r
-// VA_ARG (VA_LIST Marker, var arg size) - Use Marker to get an argument from\r
-// the ... list. You must know the size and pass it in this macro.\r
+// VA_ARG (VA_LIST Marker, var arg type) - Use Marker to get an argument from\r
+// the ... list. You must know the type and pass it in this macro. Type\r
+// must be compatible with the type of the actual next argument (as promoted\r
+// according to the default argument promotions.)\r
// VA_COPY (VA_LIST Dest, VA_LIST Start) - Initialize Dest as a copy of Start.\r
//\r
-// example:\r
+// Example:\r
//\r
// UINTN\r
+// EFIAPI\r
// ExampleVarArg (\r
// IN UINTN NumberOfArgs,\r
// ...\r
// VA_START (Marker, NumberOfArgs);\r
// for (Index = 0, Result = 0; Index < NumberOfArgs; Index++) {\r
// //\r
-// // The ... list is a series of UINTN values, so average them up.\r
+// // The ... list is a series of UINTN values, so sum them up.\r
// //\r
// Result += VA_ARG (Marker, UINTN);\r
// }\r
//\r
// VA_END (Marker);\r
-// return Result\r
+// return Result;\r
// }\r
//\r
+// Notes:\r
+// - Functions that call VA_START() / VA_END() must have a variable\r
+// argument list and must be declared EFIAPI.\r
+// - Functions that call VA_COPY() / VA_END() must be declared EFIAPI.\r
+// - Functions that only use VA_LIST and VA_ARG() need not be EFIAPI.\r
+//\r
\r
/**\r
Return the size of argument that has been aligned to sizeof (UINTN).\r
(SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << 32))\r
\r
#if defined(_MSC_EXTENSIONS) && !defined (__INTEL_COMPILER) && !defined (MDE_CPU_EBC)\r
+ void * _ReturnAddress(void);\r
#pragma intrinsic(_ReturnAddress)\r
/**\r
Get the return address of the calling function.\r