From b9b1d4bb82b10310bebbf8a9a854645df212a0b5 Mon Sep 17 00:00:00 2001 From: Dmitrii Kuvaiskii Date: Thu, 19 Dec 2019 15:04:18 -0800 Subject: [PATCH] [LibOS] Replace hardcoded paths with manifest-supplied parameters --- LibOS/shim/src/sys/shim_open.c | 12 +++++++----- LibOS/shim/src/sys/shim_stat.c | 36 ++++++++++++++++++++-------------- LibOS/shim/test/apps | 2 +- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/LibOS/shim/src/sys/shim_open.c b/LibOS/shim/src/sys/shim_open.c index b3a0fe3e..9f90cc51 100644 --- a/LibOS/shim/src/sys/shim_open.c +++ b/LibOS/shim/src/sys/shim_open.c @@ -134,11 +134,13 @@ size_t shim_do_write (int fd, const void * buf, size_t count) int shim_do_open (const char * file, int flags, mode_t mode) { if (strlen(file) >= 15 && strpartcmp_static(file, "/sys/class/fpga")) { - char hardlink[128] = {'\0'}; - strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink)); - memcpy(hardlink + strlen(hardlink), file + 15, strlen(file) - 15); - file = hardlink; - debug("[FPGA DEMO] opening hardlink file: %s\n", file); + //char hardlink[128] = {'\0'}; + //strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink)); + char devicepath[CONFIG_MAX] = {'\0'}; + get_config(root_config, "fpga.devicepath", devicepath, sizeof(devicepath)); + memcpy(devicepath + strlen(devicepath), file + 15, strlen(file) - 15); + file = devicepath; + debug("[FPGA DEMO] opening devicepath file: %s\n", file); } if (!file || test_user_string(file)) diff --git a/LibOS/shim/src/sys/shim_stat.c b/LibOS/shim/src/sys/shim_stat.c index 58b94f9c..0cb56d3d 100644 --- a/LibOS/shim/src/sys/shim_stat.c +++ b/LibOS/shim/src/sys/shim_stat.c @@ -33,11 +33,13 @@ int shim_do_stat (const char * file, struct stat * stat) { if (strlen(file) >= 15 && strpartcmp_static(file, "/sys/class/fpga")) { - char hardlink[128] = {'\0'}; - strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink)); - memcpy(hardlink + strlen(hardlink), file + 15, strlen(file) - 15); - file = hardlink; - debug("[FPGA DEMO] stating hardlink file: %s\n", file); + //char hardlink[128] = {'\0'}; + //strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink)); + char devicepath[CONFIG_MAX] = {'\0'}; + get_config(root_config, "fpga.devicepath", devicepath, sizeof(devicepath)); + memcpy(devicepath + strlen(devicepath), file + 15, strlen(file) - 15); + file = devicepath; + debug("[FPGA DEMO] stating devicepath file: %s\n", file); } if (!file || test_user_string(file)) @@ -69,11 +71,13 @@ out: int shim_do_lstat (const char * file, struct stat * stat) { if (strlen(file) >= 15 && strpartcmp_static(file, "/sys/class/fpga")) { - char hardlink[128] = {'\0'}; - strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink)); - memcpy(hardlink + strlen(hardlink), file + 15, strlen(file) - 15); - file = hardlink; - debug("[FPGA DEMO] stating hardlink file: %s\n", file); + //char hardlink[128] = {'\0'}; + //strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink)); + char devicepath[CONFIG_MAX] = {'\0'}; + get_config(root_config, "fpga.devicepath", devicepath, sizeof(devicepath)); + memcpy(devicepath + strlen(devicepath), file + 15, strlen(file) - 15); + file = devicepath; + debug("[FPGA DEMO] stating devicepath file: %s\n", file); } if (!file || test_user_string(file)) @@ -135,11 +139,13 @@ int shim_do_readlink (const char * file, char * buf, size_t bufsize) return -EINVAL; if (strlen(file) >= 15 && strpartcmp_static(file, "/sys/class/fpga")) { - char hardlink[128] = {'\0'}; - strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink)); - memcpy(hardlink + strlen(hardlink), file + 15, strlen(file) - 15); - memcpy(buf, hardlink, strlen(hardlink)); - return strlen(hardlink); + //char hardlink[128] = {'\0'}; + //strcpy_static(hardlink, "/sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0/fpga/", sizeof(hardlink)); + char devicepath[CONFIG_MAX] = {'\0'}; + get_config(root_config, "fpga.devicepath", devicepath, sizeof(devicepath)); + memcpy(devicepath + strlen(devicepath), file + 15, strlen(file) - 15); + memcpy(buf, devicepath, strlen(devicepath)); + return strlen(devicepath); } int ret; diff --git a/LibOS/shim/test/apps b/LibOS/shim/test/apps index c8c086b2..72698c8c 160000 --- a/LibOS/shim/test/apps +++ b/LibOS/shim/test/apps @@ -1 +1 @@ -Subproject commit c8c086b2fe84914820624902315c789f6d9a59d7 +Subproject commit 72698c8cbd6a21e3c2c3d2cb3571c6189ee21206