Skip to content

Commit

Permalink
patches: Use unikraft syscall in cxa_guard
Browse files Browse the repository at this point in the history
This patch replaces calls to libc syscall() with short-circuited
unikraft-specific static implementations of these syscalls.

Co-authored-by: Marco Schlumpp <marco@unikraft.io>
Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #4
  • Loading branch information
2 people authored and unikraft-bot committed Jun 1, 2023
1 parent 6546a39 commit 17ce85c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile.uk
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ LIBCXXABI_VERSION=14.0.6
LIBCXXABI_URL=https://github.com/llvm/llvm-project/releases/download/llvmorg-$(LIBCXXABI_VERSION)/libcxxabi-$(LIBCXXABI_VERSION).src.tar.xz
LIBCXXABI_PATCHDIR=$(LIBCXXABI_BASE)/patches
$(eval $(call fetch,libcxxabi,$(LIBCXXABI_URL)))
$(eval $(call patch,libcxxabi,$(LIBCXXABI_PATCHDIR),libcxxabi-$(LIBCXXABI_VERSION).src))

################################################################################
# Helpers
Expand Down
37 changes: 37 additions & 0 deletions patches/0001-cxa_guard_impl_syscall.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
diff --git a/libcxxabi/src/cxa_guard_impl.h b/libcxxabi/src/cxa_guard_impl.h
index 72940cc7e..822765d89 100644
--- a/src/cxa_guard_impl.h
+++ b/src/cxa_guard_impl.h
@@ -56,6 +56,7 @@

#include <limits.h>
#include <stdlib.h>
+#include <uk/syscall.h>
#include <__threading_support>
#ifndef _LIBCXXABI_HAS_NO_THREADS
# if defined(__ELF__) && defined(_LIBCXXABI_LINK_PTHREAD_LIB)
@@ -157,7 +158,7 @@ uint32_t PlatformThreadID() {
#elif defined(SYS_gettid) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
uint32_t PlatformThreadID() {
static_assert(sizeof(pid_t) == sizeof(uint32_t), "");
- return static_cast<uint32_t>(syscall(SYS_gettid));
+ return static_cast<uint32_t>(uk_syscall_static(SYS_gettid));
}
#else
constexpr uint32_t (*PlatformThreadID)() = nullptr;
@@ -410,13 +411,13 @@ private:
#if defined(SYS_futex)
void PlatformFutexWait(int* addr, int expect) {
constexpr int WAIT = 0;
- syscall(SYS_futex, addr, WAIT, expect, 0);
+ uk_syscall_static(SYS_futex, addr, WAIT, expect, 0);
__tsan_acquire(addr);
}
void PlatformFutexWake(int* addr) {
constexpr int WAKE = 1;
__tsan_release(addr);
- syscall(SYS_futex, addr, WAKE, INT_MAX);
+ uk_syscall_static(SYS_futex, addr, WAKE, INT_MAX);
}
#else
constexpr void (*PlatformFutexWait)(int*, int) = nullptr;

0 comments on commit 17ce85c

Please sign in to comment.