From 9ce23a8c08f544de666244b526ff5e0bf7717e75 Mon Sep 17 00:00:00 2001 From: "Hui, Chunyang" Date: Tue, 9 Jun 2020 07:27:38 +0000 Subject: [PATCH] Add symbolic file support for FISH demo --- demos/fish/Occlum.json | 18 ++++++++---- demos/fish/README.md | 28 ++++++------------- demos/fish/download_and_build.sh | 6 ++-- demos/fish/fish_script.sh | 3 +- demos/fish/{env_setup.sh => run_fish_test.sh} | 8 +++++- 5 files changed, 34 insertions(+), 29 deletions(-) rename demos/fish/{env_setup.sh => run_fish_test.sh} (56%) diff --git a/demos/fish/Occlum.json b/demos/fish/Occlum.json index ce82cac2..a615af57 100644 --- a/demos/fish/Occlum.json +++ b/demos/fish/Occlum.json @@ -1,12 +1,18 @@ { - "vm": { - "user_space_size": "512MB" + "resource_limits": { + "user_space_size": "512MB", + "kernel_space_heap_size": "32MB", + "kernel_space_stack_size": "1MB", + "max_num_of_threads": 32 }, "process": { "default_stack_size": "4MB", "default_heap_size": "32MB", "default_mmap_size": "80MB" }, + "entry_points": [ + "/bin" + ], "env": { "default": [ "OCCLUM=yes", @@ -15,9 +21,11 @@ "untrusted": [ ] }, - "entry_points": [ - "/bin" - ], + "metadata": { + "product_id": 0, + "version_number": 0, + "debuggable": true + }, "mount": [ { "target": "/", diff --git a/demos/fish/README.md b/demos/fish/README.md index a145f4a5..e7f2d537 100644 --- a/demos/fish/README.md +++ b/demos/fish/README.md @@ -11,12 +11,15 @@ for most of the utilities you usually find in GNU fileutils, shellutils, etc. This shell script contains executable binaries, pipe symbols and output redirection like this: ``` -busybox echo "Hello-world-from-fish" | busybox awk '$1=$1' FS="-" OFS=" " > /root/output.txt +command echo "Hello-world-from-fish" | awk '$1=$1' FS="-" OFS=" " > /root/output.txt +cat /root/output.txt ``` which is defined in `fish_script.sh`. `awk` will replace `-` to `space` and should output result string `Hello world from fish` and store in `/root/output.txt` of Occlum SEFS and can only be read -inside Occlum. +inside Occlum. `echo`, `awk`, `cat` here are actually symbolic files linked to busybox and in this way, we don't need +to write `busybox` prefix. The `command` keyword tells FISH that `echo` is an external command because FISH also provides +builtin `echo` command. ## Step 1: Downlaod FISH and busybox and build them with Occlum tool chain: @@ -25,26 +28,13 @@ Downlaod FISH and busybox and build them with Occlum tool chain: ``` ## Step 2: -Prepare environment by running: +Run command to prepare context and execute script: ``` -./env_setup.sh +./run_fish_test.sh ``` - -If user wants to run this demo on non-SGX platform, run command: +Or if this demo is running on non-SGX platform, use: ``` -SGX_MODE=SIM ./env_setup.sh -``` - -## Step 3: -Run command to execute script: -``` -cd occlum-context && occlum run /bin/fish /fish_script.sh -``` - -## Step 4: -Go to `occlum-context` and check result by running: -``` -occlum run /bin/busybox cat /root/output.txt +SGX_MODE=SIM ./run_fish_test.sh ``` And you should see `Hello world from fish`. diff --git a/demos/fish/download_and_build.sh b/demos/fish/download_and_build.sh index 21610889..9a206fbb 100755 --- a/demos/fish/download_and_build.sh +++ b/demos/fish/download_and_build.sh @@ -6,7 +6,7 @@ git clone -b v6.1 --depth 1 https://github.com/mirror/ncurses.git cd ncurses CC=occlum-gcc CXX=occlum-g++ CFLAGS="-O2 -fPIC" CXXFLAGS="-O2 -fPIC" LDFLAGS="-pie" \ ./configure --without-shared --without-cxx-shared --prefix=/usr/local/occlum --enable-overwrite -make && make install +make -j$(nproc) && make install cd .. # download and build FISH @@ -22,7 +22,7 @@ cmake ../ -DCMAKE_BUILD_TYPE=Debug -DCURSES_LIBRARY=/opt/occlum/toolchains/gcc/ -DCMAKE_C_COMPILER_RANLIB=/usr/local/occlum/bin/occlum-ranlib \ -DCMAKE_LINKER=/usr/local/occlum/bin/occlum-ld -DCMAKE_C_FLAGS="-I/usr/local/occlum/include -fpic -pie" \ -DCMAKE_CXX_FLAGS="-I/usr/local/occlum/include -fpic -pie" -make +make -j$(nproc) cd ../../ # download and build busybox @@ -31,4 +31,4 @@ cd busybox CROSS_COMPILE=/opt/occlum/toolchains/gcc/bin/occlum- make CROSS_COMPILE="$CROSS_COMPILE" defconfig cp ../.config . -make CROSS_COMPILE="$CROSS_COMPILE" +make CROSS_COMPILE="$CROSS_COMPILE" -j$(nproc) diff --git a/demos/fish/fish_script.sh b/demos/fish/fish_script.sh index 3487e299..e500d5e3 100644 --- a/demos/fish/fish_script.sh +++ b/demos/fish/fish_script.sh @@ -1,2 +1,3 @@ #! /bin/fish -busybox echo "Hello-world-from-fish" | busybox awk '$1=$1' FS="-" OFS=" " > /root/output.txt \ No newline at end of file +command echo "Hello-world-from-fish" | awk '$1=$1' FS="-" OFS=" " > /root/output.txt +cat /root/output.txt diff --git a/demos/fish/env_setup.sh b/demos/fish/run_fish_test.sh similarity index 56% rename from demos/fish/env_setup.sh rename to demos/fish/run_fish_test.sh index b8bc8766..60ea02f7 100755 --- a/demos/fish/env_setup.sh +++ b/demos/fish/run_fish_test.sh @@ -1,7 +1,6 @@ #!/bin/bash set -e -# rm -rf occlum-context mkdir occlum-context && cd occlum-context occlum init @@ -9,5 +8,12 @@ cp ../Occlum.json . cp ../fish-shell/build/fish image/bin cp ../busybox/busybox image/bin cp ../fish_script.sh image +pushd image/bin +ln -s /bin/busybox cat +ln -s /bin/busybox echo +ln -s /bin/busybox awk +popd occlum build +echo -e "\nBuild done. Running fish script ..." +occlum run /bin/fish /fish_script.sh