${SWRAP_REQUIRED_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT})
+add_library(swrap_fake_uid_wrapper SHARED swrap_fake_uid_wrapper.c)
+target_compile_options(swrap_fake_uid_wrapper
+ PRIVATE
+ ${DEFAULT_C_COMPILE_FLAGS}
+ -D_GNU_SOURCE)
+#target_include_directories(swrap_fake_uid_wrapper
+# PRIVATE ${CMAKE_BINARY_DIR} ${CMOCKA_INCLUDE_DIR})
+set(SWRAP_FAKE_UID_WRAPPER_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swrap_fake_uid_wrapper${CMAKE_SHARED_LIBRARY_SUFFIX}")
+
set(SWRAP_THREADED_TESTS
test_thread_sockets
test_thread_echo_tcp_connect
test_public_functions
test_close_failure
test_tcp_socket_overwrite
+ test_syscall_uwrap
${SWRAP_THREADED_TESTS})
if (HAVE_STRUCT_MSGHDR_MSG_CONTROL)
if (ASAN_LIBRARY)
list(APPEND PRELOAD_LIBRARIES ${ASAN_LIBRARY})
endif()
+ list(APPEND PRELOAD_LIBRARIES ${SWRAP_FAKE_UID_WRAPPER_LOCATION})
list(APPEND PRELOAD_LIBRARIES ${SOCKET_WRAPPER_LOCATION})
if (OSX)
--- /dev/null
+#include "config.h"
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <stdbool.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+
+#ifdef HAVE_SYS_SYSCALL_H
+#include <sys/syscall.h>
+#endif
+#ifdef HAVE_SYSCALL_H
+#include <syscall.h>
+#endif
+
+#include "swrap_fake_uid_wrapper.h"
+
+/* simulate uid_wrapper hooks */
+bool uid_wrapper_syscall_valid(long int sysno)
+{
+ if (sysno == __FAKE_UID_WRAPPER_SYSCALL_NO) {
+ return true;
+ }
+
+ return false;
+}
+
+long int uid_wrapper_syscall_va(long int sysno, va_list va)
+{
+ (void) va; /* unused */
+
+ if (sysno == __FAKE_UID_WRAPPER_SYSCALL_NO) {
+ errno = 0;
+ return __FAKE_UID_WRAPPER_SYSCALL_RC;
+ }
+
+ errno = ENOSYS;
+ return -1;
+}
--- /dev/null
+#include <stdbool.h>
+
+/* simulate socket_wrapper hooks */
+#define __FAKE_UID_WRAPPER_SYSCALL_NO 123456789
+#define __FAKE_UID_WRAPPER_SYSCALL_RC 987654321
+bool uid_wrapper_syscall_valid(long int sysno);
+long int uid_wrapper_syscall_va(long int sysno, va_list va);
--- /dev/null
+#include "config.h"
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <stdbool.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <signal.h>
+
+#ifdef HAVE_SYS_SYSCALL_H
+#include <sys/syscall.h>
+#endif
+#ifdef HAVE_SYSCALL_H
+#include <syscall.h>
+#endif
+
+#include "swrap_fake_uid_wrapper.h"
+
+static void test_swrap_syscall_uwrap(void **state)
+{
+ long int rc;
+
+ (void)state; /* unused */
+
+ rc = syscall(__FAKE_UID_WRAPPER_SYSCALL_NO);
+ assert_int_equal(rc, __FAKE_UID_WRAPPER_SYSCALL_RC);
+
+ /*
+ * FreeBSD raises also a signal SIGSYS, so ignore it or the cmocka
+ * exception handler will catch it.
+ */
+ signal(SIGSYS, SIG_IGN);
+ rc = syscall(__FAKE_UID_WRAPPER_SYSCALL_NO+1);
+ signal(SIGSYS, SIG_DFL);
+ assert_int_equal(rc, -1);
+ assert_int_equal(errno, ENOSYS);
+}
+
+int main(void) {
+ int rc;
+
+ const struct CMUnitTest swrap_tests[] = {
+ cmocka_unit_test(test_swrap_syscall_uwrap),
+ };
+
+ rc = cmocka_run_group_tests(swrap_tests, NULL, NULL);
+
+ return rc;
+}