Commit ba81942d authored by Marc Vef's avatar Marc Vef
Browse files

Merge branch 'rnou/arm_master' into 'master'

Arm Support

This adds ARM support.

It adds a new profile to download the syscall_intercept that supports ARM (fork).
The modifications doesn't use ARM define, as it is not needed, we only need to check if a syscall exists or not.

Closes #244 
We can close !127 also, I think that this merge updates and solves some issues.

Closes #244

See merge request !160
parents 8930cfc7 52650a44
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
  existing file descriptor ([!133](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/133)).
- Added `FLOCK` and `fcntl` functions for locks to interception albeit not supported by GekkoFS and returning the
  corresponding error code ([!133](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/133)).
- Added ARM64 support ([!160](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/160)).
- Added support for [CMake presets](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html) to simplify build 
  configurations ([!163](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/163#note_8179)).
- Several improvements to CMake scripts ([!143](https://storage.bsc.es/gitlab/hpc/gekkofs/-/merge_requests/143))):
+158 −0
Original line number Diff line number Diff line
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 13fcdb9..11b621a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -220,14 +220,14 @@ install(TARGETS syscall_intercept_shared
 	LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
 	ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
 
-if (NOT SUBMOUDLE_BUILD)
-	install(TARGETS syscall_intercept_static
-		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
-		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
-	install(PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
-	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libsyscall_intercept.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
-	add_subdirectory(doc)
-endif()
+# if (NOT SUBMOUDLE_BUILD)
+# 	install(TARGETS syscall_intercept_static
+# 		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+# 		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+# 	install(PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+# 	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libsyscall_intercept.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
+# 	add_subdirectory(doc)
+# endif()
 
 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
 	"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
diff --git a/arch/aarch64/include/libsyscall_intercept_hook_point.h b/arch/aarch64/include/libsyscall_intercept_hook_point.h
index 2fe7d57..46f7eff 100644
--- a/arch/aarch64/include/libsyscall_intercept_hook_point.h
+++ b/arch/aarch64/include/libsyscall_intercept_hook_point.h
@@ -57,8 +57,21 @@ extern int (*intercept_hook_point)(long syscall_number,
 			long arg4, long arg5,
 			long *result);
 
-extern void (*intercept_hook_point_clone_child)(void);
-extern void (*intercept_hook_point_clone_parent)(long pid);
+
+extern void (*intercept_hook_point_clone_child)(
+			unsigned long flags, void *child_stack,
+			int *ptid, int *ctid, long newtls);
+
+extern void (*intercept_hook_point_clone_parent)(
+			unsigned long flags, void *child_stack,
+			int *ptid, int *ctid, long newtls,
+			long returned_pid);
+
+extern void (*intercept_hook_point_post_kernel)(long syscall_number,
+			long arg0, long arg1,
+			long arg2, long arg3,
+			long arg4, long arg5,
+			long result);
 
 /*
  * syscall_no_intercept - syscall without interception
diff --git a/arch/aarch64/src/intercept.c b/arch/aarch64/src/intercept.c
index a15aa97..72e4b7a 100644
--- a/arch/aarch64/src/intercept.c
+++ b/arch/aarch64/src/intercept.c
@@ -68,11 +68,24 @@ int (*intercept_hook_point)(long syscall_number,
 			long *result)
 	__attribute__((visibility("default")));
 
-void (*intercept_hook_point_clone_child)(void)
-	__attribute__((visibility("default")));
-void (*intercept_hook_point_clone_parent)(long)
-	__attribute__((visibility("default")));
-
+void (*intercept_hook_point_clone_child)(
+		unsigned long flags, void *child_stack,
+		int *ptid, int *ctid,
+		long newtls)
+__attribute__((visibility("default")));
+
+void (*intercept_hook_point_clone_parent)(
+		unsigned long flags, void *child_stack,
+		int *ptid, int *ctid,
+		long newtls, long returned_pid)
+__attribute__((visibility("default")));
+
+void (*intercept_hook_point_post_kernel)(long syscall_number,
+		long arg0, long arg1,
+		long arg2, long arg3,
+		long arg4, long arg5,
+		long result)
+__attribute__((visibility("default")));
 bool debug_dumps_on;
 
 void
@@ -630,7 +643,15 @@ intercept_routine(struct context *context)
 
 	if (handle_magic_syscalls(&desc, &result) == 0)
 		return (struct wrapper_ret){.x0 = result, .x1 = 1 };
-
+	if (intercept_hook_point_post_kernel != NULL)
+		intercept_hook_point_post_kernel(desc.nr,
+				desc.args[0],
+				desc.args[1],
+				desc.args[2],
+				desc.args[3],
+				desc.args[4],
+				desc.args[5],
+				result);
 	intercept_log_syscall(patch, &desc, UNKNOWN, 0);
 
 	if (intercept_hook_point != NULL)
@@ -693,12 +714,25 @@ intercept_routine(struct context *context)
 struct wrapper_ret
 intercept_routine_post_clone(struct context *context)
 {
+	struct syscall_desc desc;
+	get_syscall_in_context(context, &desc);
 	if (context->x0 == 0) {
 		if (intercept_hook_point_clone_child != NULL)
-			intercept_hook_point_clone_child();
+			intercept_hook_point_clone_child(
+				(unsigned long)desc.args[0],
+				(void *)desc.args[1],
+				(int *)desc.args[2],
+				(int *)desc.args[3],
+				desc.args[4]);
 	} else {
 		if (intercept_hook_point_clone_parent != NULL)
-			intercept_hook_point_clone_parent(context->x0);
+			intercept_hook_point_clone_parent(
+					(unsigned long)desc.args[0],
+					(void *)desc.args[1],
+					(int *)desc.args[2],
+					(int *)desc.args[3],
+					desc.args[4],
+					context->x0);
 	}
 
 	return (struct wrapper_ret){.x0 = context->x0, .x1 = 1 };
diff --git a/arch/aarch64/src/intercept.h b/arch/aarch64/src/intercept.h
index be593a5..7408f10 100644
--- a/arch/aarch64/src/intercept.h
+++ b/arch/aarch64/src/intercept.h
@@ -202,6 +202,6 @@ bool is_overwritable_nop(const struct intercept_disasm_result *ins);
 
 unsigned char *create_jump(unsigned char *from, void *to);
 
-const char *cmdline;
+extern const char *cmdline;
 extern size_t page_size;
 #endif
diff --git a/src/intercept.h b/src/intercept.h
index 3c40795..d04629c 100644
--- a/src/intercept.h
+++ b/src/intercept.h
@@ -229,6 +229,6 @@ bool is_overwritable_nop(const struct intercept_disasm_result *ins);
 
 void create_jump(unsigned char opcode, unsigned char *from, void *to);
 
-const char *cmdline;
+extern const char *cmdline;
 
 #endif
+83 −0
Original line number Diff line number Diff line
################################################################################
# Copyright 2018-2021, Barcelona Supercomputing Center (BSC), Spain            #
# Copyright 2015-2021, Johannes Gutenberg Universitaet Mainz, Germany          #
#                                                                              #
# This software was partially supported by the                                 #
# EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).    #
#                                                                              #
# This software was partially supported by the                                 #
# ADA-FS project under the SPPEXA project funded by the DFG.                   #
#                                                                              #
# This file is part of GekkoFS.                                                #
#                                                                              #
# GekkoFS is free software: you can redistribute it and/or modify              #
# it under the terms of the GNU General Public License as published by         #
# the Free Software Foundation, either version 3 of the License, or            #
# (at your option) any later version.                                          #
#                                                                              #
# GekkoFS is distributed in the hope that it will be useful,                   #
# but WITHOUT ANY WARRANTY; without even the implied warranty of               #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
# GNU General Public License for more details.                                 #
#                                                                              #
# You should have received a copy of the GNU General Public License            #
# along with GekkoFS.  If not, see <https://www.gnu.org/licenses/>.            #
#                                                                              #
# SPDX-License-Identifier: GPL-3.0-or-later                                    #
################################################################################

# vi: ft=bash

# Variables to be imported into the scripts
declare -A wgetdeps clonedeps clonedeps_args clonedeps_patches extra_install_args
declare -a order

# Comment that should be displayed when printing the profile
comment="Dependencies for PowerPC supercomputer"

# Dependencies that must be downloaded directly
wgetdeps=(
    ["lz4"]="1.9.3"
    ["capstone"]="4.0.2"
    ["argobots"]="1.1"
    ["rocksdb"]="6.26.1"
    ["psm2"]="11.2.185"
    ["json-c"]="0.15-20200726"
)

# Dependencies that must be cloned
clonedeps=(
    ["libfabric"]="HEAD@v1.13.2"
    ["mercury"]="v2.1.0"
    ["margo"]="v0.9.6"
    ["syscall_intercept"]="fb73c3924b502e2840a5dc8a18746e395b06a8a6"
    ["date"]="e7e1482087f58913b80a20b04d5c58d9d6d90155"
)

# Extra arguments for git clone
clonedeps_args=(
    ["mercury"]="--recurse-submodules"
)

# Patches that should be applied post-clone
clonedeps_patches=(
    ["syscall_intercept"]="syscall_intercept.patch.arm64"
)

# Ordering that MUST be followed when downloading
order=(
    "lz4" "capstone" "json-c" "psm2" "libfabric" "mercury" "argobots" "margo" "rocksdb" "syscall_intercept" "date" 
)

# Extra arguments passed to the installation script. As such, they can
# reference the following variables:
#  - CMAKE: a variable that expands to the cmake binary
#  - SOURCE_DIR: the directory where the sources for the package were
#               downloaded
#  - INSTALL_DIR: the directory where the package should be installed
#  - CORES: the number of cores to use when building
#  - PERFORM_TEST: whether tests for the package should be executed
extra_install_args=(
    ["libfabric"]="--enable-psm2=no --enable-sockets=yes"
    ["syscall_intercept"]="ARM64"
)
+11 −1
Original line number Diff line number Diff line
@@ -46,14 +46,24 @@
pkg_install() {
    ID="syscall_intercept"
    CURR="${SOURCE_DIR}/${ID}"
    EXTRA_INSTALL_ARGS="${PROFILE_EXTRA_INSTALL_ARGS[${ID}]}"
    prepare_build_dir "${CURR}"
    if [[ ${EXTRA_INSTALL_ARGS} == "ARM64" ]]; then
        cd "${CURR}"/arch/aarch64/
        mkdir -p build
        cd build
    else    
        cd "${CURR}"/build
    fi
    $CMAKE -DCMAKE_PREFIX_PATH="${INSTALL_DIR}" \
    -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
    -DCMAKE_BUILD_TYPE:STRING=Debug \
    -DBUILD_EXAMPLES:BOOL=OFF \
    -DBUILD_TESTS:BOOK=OFF ..
    make -j"${CORES}" install
    if [[ ${EXTRA_INSTALL_ARGS} == "ARM64" ]]; then
        cp "${CURR}"/arch/aarch64/include/libsyscall_intercept_hook_point.h ${INSTALL_DIR}/include
    fi
}

pkg_check() {
+10 −5
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ hook_close(int fd) {

    return syscall_no_intercept_wrapper(SYS_close, fd);
}

#ifdef SYS_stat
int
hook_stat(const char* path, struct stat* buf) {

@@ -119,6 +119,7 @@ hook_stat(const char* path, struct stat* buf) {

    return syscall_no_intercept_wrapper(SYS_stat, rel_path.c_str(), buf);
}
#endif

#ifdef STATX_TYPE

@@ -158,6 +159,7 @@ hook_statx(int dirfd, const char* path, int flags, unsigned int mask,

#endif

#ifdef SYS_lstat
int
hook_lstat(const char* path, struct stat* buf) {

@@ -170,6 +172,7 @@ hook_lstat(const char* path, struct stat* buf) {
    }
    return syscall_no_intercept_wrapper(SYS_lstat, rel_path.c_str(), buf);
}
#endif

int
hook_fstat(unsigned int fd, struct stat* buf) {
@@ -414,6 +417,7 @@ hook_flock(unsigned long fd, int flags) {
        return -EBADF;
}

#ifdef SYS_access
int
hook_access(const char* path, int mask) {

@@ -429,6 +433,7 @@ hook_access(const char* path, int mask) {
    }
    return syscall_no_intercept_wrapper(SYS_access, rel_path.c_str(), mask);
}
#endif

int
hook_faccessat(int dirfd, const char* cpath, int mode) {
@@ -547,7 +552,7 @@ hook_dup(unsigned int fd) {
    }
    return syscall_no_intercept_wrapper(SYS_dup, fd);
}

#ifdef SYS_dup2
int
hook_dup2(unsigned int oldfd, unsigned int newfd) {

@@ -558,7 +563,7 @@ hook_dup2(unsigned int oldfd, unsigned int newfd) {
    }
    return syscall_no_intercept_wrapper(SYS_dup2, oldfd, newfd);
}

#endif
int
hook_dup3(unsigned int oldfd, unsigned int newfd, int flags) {

@@ -573,7 +578,7 @@ hook_dup3(unsigned int oldfd, unsigned int newfd, int flags) {
    }
    return syscall_no_intercept_wrapper(SYS_dup3, oldfd, newfd, flags);
}

#ifdef SYS_getdents
int
hook_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count) {

@@ -585,7 +590,7 @@ hook_getdents(unsigned int fd, struct linux_dirent* dirp, unsigned int count) {
    }
    return syscall_no_intercept_wrapper(SYS_getdents, fd, dirp, count);
}

#endif

int
hook_getdents64(unsigned int fd, struct linux_dirent64* dirp,
Loading