summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNigel Croxon <nigel.croxon@hp.com>2013-06-12 09:47:16 -0400
committerNigel Croxon <nigel.croxon@hp.com>2013-06-12 09:47:16 -0400
commit6e8db879958d52c2474db0300c8b36a7146ecc51 (patch)
tree7b88f78af370dc6becc7109dd44d7d12a6799c72
parentc0b8d974a6cb6ad6e562ebb972ae32d21671e605 (diff)
downloadgnu-efi-3.0-6e8db879958d52c2474db0300c8b36a7146ecc51.tar.gz
gnu-efi-3.0-6e8db879958d52c2474db0300c8b36a7146ecc51.tar.xz
gnu-efi-3.0-6e8db879958d52c2474db0300c8b36a7146ecc51.zip
automatically determine number of uefi_call_wrapper() args on x86_64
Instead of asking developers to explicitly pass the number of parameters to the functions that get called, we determine them automatically at preprocessing time. This should result in more robust code. Argument va_num is now ignored in x86_64 code, both with and without HAVE_USE_MS_ABI. Credits to the macro magic given in the comments. Signed-off-by: David Decotigny <decot@googlers.com>
-rw-r--r--gnu-efi-3.0/inc/x86_64/efibind.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/gnu-efi-3.0/inc/x86_64/efibind.h b/gnu-efi-3.0/inc/x86_64/efibind.h
index d322b6c..065a965 100644
--- a/gnu-efi-3.0/inc/x86_64/efibind.h
+++ b/gnu-efi-3.0/inc/x86_64/efibind.h
@@ -290,6 +290,27 @@ typedef uint64_t UINTN;
#if defined(HAVE_USE_MS_ABI)
#define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
#else
+/*
+ Credits for macro-magic:
+ https://groups.google.com/forum/?fromgroups#!topic/comp.std.c/d-6Mj5Lko_s
+ http://efesx.com/2010/08/31/overloading-macros/
+*/
+#define __VA_NARG__(...) \
+ __VA_NARG_(_0, ## __VA_ARGS__, __RSEQ_N())
+#define __VA_NARG_(...) \
+ __VA_ARG_N(__VA_ARGS__)
+#define __VA_ARG_N( \
+ _0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,N,...) N
+#define __RSEQ_N() \
+ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
+
+#define __VA_ARG_NSUFFIX__(prefix,...) \
+ __VA_ARG_NSUFFIX_N(prefix, __VA_NARG__(__VA_ARGS__))
+#define __VA_ARG_NSUFFIX_N(prefix,nargs) \
+ __VA_ARG_NSUFFIX_N_(prefix, nargs)
+#define __VA_ARG_NSUFFIX_N_(prefix,nargs) \
+ prefix ## nargs
+
/* Prototypes of EFI cdecl -> stdcall trampolines */
UINT64 efi_call0(void *func);
UINT64 efi_call1(void *func, UINT64 arg1);
@@ -345,8 +366,9 @@ UINT64 efi_call10(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3,
(UINT64)(a5), (UINT64)(a6), (UINT64)(a7), (UINT64)(a8), \
(UINT64)(a9), (UINT64)(a10))
+/* main wrapper (va_num ignored) */
#define uefi_call_wrapper(func,va_num,...) \
- _cast64_efi_call ## va_num (func , ##__VA_ARGS__)
+ __VA_ARG_NSUFFIX__(_cast64_efi_call, __VA_ARGS__) (func, __VA_ARGS__)
#endif
#define EFI_FUNCTION __attribute__((ms_abi))