include/mock.h: prevent expension of syscall name
If a platform defines a syscall using a macro (e.g. #define open _open) then wrapping it fails because DEFINE_RETURN_MOCK and MOCK_GET will use the definition to name the ut_ variables, but DEFINE_WRAPPER will use the original name. This result in an undefined reference when linking. Prevent macro expansion of the syscall name by avoiding nested macro calls in DEFINE_WRAPPER. Include the contents of DEFINE_RETURN_MOCK and MOCK_GET directly in DEFINE_WRAPPER. Signed-off-by: Nick Connolly <nick.connolly@mayadata.io> Change-Id: I452857ec7df43f7a1a5f093439c7d5cf4683f8ee Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9618 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
7a5bc4905b
commit
1cfdbd429f
@ -72,15 +72,19 @@
|
||||
extern ret ut_ ## fn; \
|
||||
ret __wrap_ ## fn args; ret __real_ ## fn args
|
||||
|
||||
/* for defining the implmentation of wrappers for syscalls */
|
||||
/*
|
||||
* For defining the implementation of wrappers for syscalls.
|
||||
* Avoid nested macro calls to prevent macro expansion of fn.
|
||||
*/
|
||||
#define DEFINE_WRAPPER(fn, ret, dargs, pargs) \
|
||||
DEFINE_RETURN_MOCK(fn, ret); \
|
||||
bool ut_ ## fn ## _mocked = false; \
|
||||
ret ut_ ## fn; \
|
||||
__attribute__((used)) ret __wrap_ ## fn dargs \
|
||||
{ \
|
||||
if (!ut_ ## fn ## _mocked) { \
|
||||
return __real_ ## fn pargs; \
|
||||
} else { \
|
||||
return MOCK_GET(fn); \
|
||||
return ut_ ## fn; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user