Commit 1cfdbd42 authored by Nick Connolly's avatar Nick Connolly Committed by Jim Harris
Browse files

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: default avatarNick 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: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 7a5bc490
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -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; \
		} \
	}