Unverified Commit 6d49c1c8 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Add patches and update deps scripts

parent 4f4c5b1c
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
#!/bin/bash

mogon1_deps=( 
MOGON1_DEPS=( 
    "zstd" "lz4" "snappy" "bmi" "libfabric" "mercury" "argobots" "margo" 
    "rocksdb" "syscall_intercept date"
)

mogon2_deps=(
MOGON2_DEPS=(
    "zstd" "lz4" "snappy" "bmi" "mercury" "argobots" "margo" "rocksdb" 
    "syscall_intercept date"
)

fh2_deps=(
FH2_DEPS=(
    "zstd" "lz4" "snappy" "bmi" "libfabric" "mercury" "argobots" "margo" 
    "rocksdb" "syscall_intercept date"
)

usage_short() {
	echo "
usage: compile_dep.sh [-h] [-n <NAPLUGIN>] [-c <CLUSTER>] [-d <DEPENDENCY>] [-j <COMPILE_CORES>]
usage: compile_dep.sh [-h] [-l] [-n <NAPLUGIN>] [-c <CLUSTER>] [-d <DEPENDENCY>] [-j <COMPILE_CORES>]
                      source_path install_path
	"
}
@@ -59,21 +59,21 @@ list_dependencies() {
    echo "Available dependencies: "

    echo -n "  Mogon 1: "
    for d in "${mogon1_deps[@]}"
    for d in "${MOGON1_DEPS[@]}"
    do
        echo -n "$d "
    done
    echo ""

    echo -n "  Mogon 2: "
    for d in "${mogon2_deps[@]}"
    for d in "${MOGON2_DEPS[@]}"
    do
        echo -n "$d "
    done
    echo ""

    echo -n "  fh2: "
    for d in "${fh2_deps[@]}"
    for d in "${FH2_DEPS[@]}"
    do
        echo -n "$d "
    done
@@ -297,7 +297,7 @@ if [[ ( "${DEPENDENCY}" == "" ) || ( "${DEPENDENCY}" == "mercury" ) ]]; then
    CURR=${SOURCE}/mercury
    prepare_build_dir ${CURR}
    cd ${CURR}/build
    $CMAKE \
    PKG_CONFIG_PATH=${INSTALL}/lib/pkgconfig $CMAKE \
        -DCMAKE_BUILD_TYPE:STRING=Debug \
        -DBUILD_TESTING:BOOL=ON \
        -DMERCURY_USE_SM_ROUTING:BOOL=OFF \
@@ -357,7 +357,7 @@ if [[ ( "${DEPENDENCY}" == "" ) || ( "${DEPENDENCY}" == "syscall_intercept" ) ]]
    CURR=${SOURCE}/syscall_intercept
    prepare_build_dir ${CURR}
    cd ${CURR}/build
    CC="" CXX="" $CMAKE -DCMAKE_INSTALL_PREFIX=${INSTALL} -DCMAKE_BUILD_TYPE:STRING=Debug -DBUILD_EXAMPLES:BOOL=OFF -DBUILD_TESTS:BOOK=OFF ..
    $CMAKE -DCMAKE_INSTALL_PREFIX=${INSTALL} -DCMAKE_BUILD_TYPE:STRING=Debug -DBUILD_EXAMPLES:BOOL=OFF -DBUILD_TESTS:BOOK=OFF ..
    make install
fi

+121 −19
Original line number Diff line number Diff line
@@ -4,6 +4,27 @@

COMMON_CURL_FLAGS="--silent --fail --show-error --location -O"
COMMON_GIT_FLAGS="--quiet --single-branch"
PATCH_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PATCH_DIR="${PATCH_DIR}/patches"
CLUSTER=""
DEPENDENCY=""
NA_LAYER=""

MOGON1_DEPS=( 
    "zstd" "lz4" "snappy" "bmi" "libfabric" "mercury" "argobots" "margo" 
    "rocksdb" "syscall_intercept date"
)

MOGON2_DEPS=(
    "zstd" "lz4" "snappy" "bmi" "mercury" "argobots" "margo" "rocksdb" 
    "syscall_intercept date"
)

FH2_DEPS=(
    "zstd" "lz4" "snappy" "bmi" "libfabric" "mercury" "argobots" "margo" 
    "rocksdb" "syscall_intercept date"
)


# Stop all backround jobs on interruption.
# "kill -- -$$" sends a SIGTERM to the whole process group,
@@ -23,14 +44,41 @@ error_exit() {
    exit "${2:-1}"  ## Return a code specified by $2 or 1 by default.
}

list_dependencies() {

    echo "Available dependencies: "

    echo -n "  Mogon 1: "
    for d in "${MOGON1_DEPS[@]}"
    do
        echo -n "$d "
    done
    echo ""

    echo -n "  Mogon 2: "
    for d in "${MOGON2_DEPS[@]}"
    do
        echo -n "$d "
    done
    echo ""

    echo -n "  fh2: "
    for d in "${FH2_DEPS[@]}"
    do
        echo -n "$d "
    done
    echo ""
}

clonedeps() {
    set -e
    set -ex
    trap exit_child EXIT

    local FOLDER=$1
    local REPO=$2
    local COMMIT=$3
    local GIT_FLAGS=$4
    local PATCH=$5

    local ACTION

@@ -44,6 +92,12 @@ clonedeps() {
    # fix the version
    cd "${SOURCE}/${FOLDER}" && git checkout -qf ${COMMIT}
    echo "${ACTION} ${FOLDER} [$COMMIT]"

    # apply patch if provided
    if [ ! -z ${PATCH} ]; then
        git apply --verbose ${PATCH_DIR}/${PATCH}
    fi

}

wgetdeps() {
@@ -69,7 +123,7 @@ wgetdeps() {

usage_short() {
	echo "
usage: dl_dep.sh [-h] [-n <NAPLUGIN>] [-c <CLUSTER>]
usage: dl_dep.sh [-h] [-l] [-n <NAPLUGIN>] [-c <CLUSTER>] [-d <DEPENDENCY>] 
                    source_path
	"
}
@@ -86,16 +140,19 @@ positional arguments:

optional arguments:
        -h, --help              shows this help message and exits
        -l, --list-dependencies
                                list dependencies available for download
        -n <NAPLUGIN>, --na <NAPLUGIN>
                                network layer that is used for communication. Valid: {bmi,ofi,all}
                                defaults to 'all'
        -c <CLUSTER>, --cluster <CLUSTER>
                                additional configurations for specific compute clusters
                                supported clusters: {mogon1,mogon2,fh2}
        -d <DEPENDENCY>, --dependency <DEPENDENCY>
                                download a specific dependency. If unspecified 
                                all dependencies are built and installed.
        "
}
CLUSTER=""
NA_LAYER=""

POSITIONAL=()
while [[ $# -gt 0 ]]
@@ -113,6 +170,19 @@ case ${key} in
    shift # past argument
    shift # past value
    ;;
    -d|--dependency)
    if [[ -z "$2" ]]; then
        echo "Missing argument for -d/--dependency option"
        exit
    fi
    DEPENDENCY="$2"
    shift # past argument
    shift # past value
    ;;
    -l|--list-dependencies)
    list_dependencies
    exit
    ;;
    -h|--help)
    help_msg
    exit
@@ -166,40 +236,72 @@ mkdir -p ${SOURCE}

# get cluster dependencies
if [[ ( "${CLUSTER}" == "mogon1" ) || ( "${CLUSTER}" == "mogon2" ) || ( "${CLUSTER}" == "fh2" ) ]]; then

    # get zstd for fast compression in rocksdb
    if [[ ( "${DEPENDENCY}" == "" ) || ( "${DEPENDENCY}" == "zstd" ) ]]; then
        wgetdeps "zstd" "https://github.com/facebook/zstd/archive/v1.3.2.tar.gz" &
    fi

    # get zlib for rocksdb
    if [[ ( "${DEPENDENCY}" == "" ) || ( "${DEPENDENCY}" == "zstd" ) ]]; then
        wgetdeps "lz4" "https://github.com/lz4/lz4/archive/v1.8.0.tar.gz" &
    fi

	# get snappy for rocksdb
    if [[ ( "${DEPENDENCY}" == "" ) || ( "${DEPENDENCY}" == "snappy" ) ]]; then
            wgetdeps "snappy" "https://github.com/google/snappy/archive/1.1.7.tar.gz" &
    fi
fi
#if [ "${CLUSTER}" == "fh2" ]; then
	# no distinct 3rd party software needed as of now.
#fi

# get BMI
if [[ ( "${DEPENDENCY}" == "" ) || ( "${DEPENDENCY}" == "bmi" ) ]]; then
    if [ "${NA_LAYER}" == "bmi" ] || [ "${NA_LAYER}" == "all" ]; then
        clonedeps "bmi" "https://xgitlab.cels.anl.gov/sds/bmi.git" "81ad0575fc57a69269a16208417cbcbefa51f9ea" &
    fi
fi

# get libfabric
if [[ ( "${DEPENDENCY}" == "" ) || ( "${DEPENDENCY}" == "ofi" ) ]]; then
    if [ "${NA_LAYER}" == "ofi" ] || [ "${NA_LAYER}" == "all" ]; then
        # No need to get libfabric for mogon2 as it is already installed
        if [[ ("${CLUSTER}" != "mogon2") ]]; then
            wgetdeps "libfabric" "https://github.com/ofiwg/libfabric/releases/download/v1.7.2/libfabric-1.7.2.tar.gz" &
        fi
    fi
fi

# get Mercury
if [[ ( "${DEPENDENCY}" == "" ) || ( "${DEPENDENCY}" == "mercury" ) ]]; then
    clonedeps "mercury" "https://github.com/mercury-hpc/mercury" "9906f25b6f9c52079d57006f199b3ea47960c435"  "--recurse-submodules" &
fi

# get Argobots
if [[ ( "${DEPENDENCY}" == "" ) || ( "${DEPENDENCY}" == "argobots" ) ]]; then
    wgetdeps "argobots" "https://github.com/pmodels/argobots/archive/v1.0rc1.tar.gz" &
fi

# get Margo
if [[ ( "${DEPENDENCY}" == "" ) || ( "${DEPENDENCY}" == "margo" ) ]]; then
    clonedeps "margo" "https://xgitlab.cels.anl.gov/sds/margo.git" "6ed94e4f3a4d526b0a3b4e57be075461e86d3666" &
fi

# get rocksdb
if [[ ( "${DEPENDENCY}" == "" ) || ( "${DEPENDENCY}" == "rocksdb" ) ]]; then
    wgetdeps "rocksdb" "https://github.com/facebook/rocksdb/archive/v6.1.2.tar.gz" &
fi

# get syscall_intercept
clonedeps "syscall_intercept" "https://github.com/pmem/syscall_intercept.git" "cc3412a2ad39f2e26cc307d5b155232811d7408e" &
if [[ ( "${DEPENDENCY}" == "" ) || ( "${DEPENDENCY}" == "syscall_intercept" ) ]]; then
    clonedeps "syscall_intercept" "https://github.com/pmem/syscall_intercept.git" "cc3412a2ad39f2e26cc307d5b155232811d7408e" "" "syscall_intercept2.patch" &
fi

# get date
clonedeps "date" "https://github.com/HowardHinnant/date.git" "e7e1482087f58913b80a20b04d5c58d9d6d90155"
if [[ ( "${DEPENDENCY}" == "" ) || ( "${DEPENDENCY}" == "date" ) ]]; then
    clonedeps "date" "https://github.com/HowardHinnant/date.git" "e7e1482087f58913b80a20b04d5c58d9d6d90155" &
fi

# Wait for all download to be completed
wait
+131 −0
Original line number Diff line number Diff line
diff --git a/include/libsyscall_intercept_hook_point.h b/include/libsyscall_intercept_hook_point.h
index 2fe7d57..43a8974 100644
--- a/include/libsyscall_intercept_hook_point.h
+++ b/include/libsyscall_intercept_hook_point.h
@@ -56,9 +56,18 @@ extern int (*intercept_hook_point)(long syscall_number,
 			long arg2, long arg3,
 			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/src/intercept.c b/src/intercept.c
index 41fd95d..c0cd865 100644
--- a/src/intercept.c
+++ b/src/intercept.c
@@ -67,9 +67,23 @@ int (*intercept_hook_point)(long syscall_number,
 			long *result)
 	__attribute__((visibility("default")));
 
-void (*intercept_hook_point_clone_child)(void)
+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)(long)
+
+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;
@@ -655,6 +669,21 @@ intercept_routine(struct context *context)
 					desc.args[3],
 					desc.args[4],
 					desc.args[5]);
+
+		/*
+		 * some users might want to execute code after a syscall has
+		 * been forwarded to the kernel (for example, to check its
+		 * return value).
+		 */
+		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, KNOWN, result);
@@ -670,12 +699,26 @@ 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->rax == 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->rax);
+			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->rax);
 	}
 
 	return (struct wrapper_ret){.rax = context->rax, .rdx = 1 };
diff --git a/test/test_clone_thread_preload.c b/test/test_clone_thread_preload.c
index c7663a2..bff239e 100644
--- a/test/test_clone_thread_preload.c
+++ b/test/test_clone_thread_preload.c
@@ -96,8 +96,18 @@ hook(long syscall_number,
  * of the clone syscall.
  */
 static void
-hook_child(void)
+hook_child(unsigned long clone_flags,
+			void *child_stack,
+			int *ptid,
+			int *ctid,
+			long newtls)
 {
+	(void) clone_flags;
+	(void) child_stack;
+	(void) ptid;
+	(void) ctid;
+	(void) newtls;
+
 	static const char msg[] = "clone_hook_child called\n";
 
 	assert(flags != -1);