瀏覽代碼

Add sys_dup and sys_dup2 support (#2)

Co-authored-by: su <sujintao@dragonos.org>
Gou Ngai 2 年之前
父節點
當前提交
691200021c
共有 4 個文件被更改,包括 46 次插入6 次删除
  1. 1 1
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 42 0
      init_dragonos_toolchain.sh
  4. 2 4
      src/platform/dragonos/mod.rs

+ 1 - 1
Cargo.lock

@@ -111,7 +111,7 @@ version = "0.1.0"
 [[package]]
 name = "dsc"
 version = "0.1.0"
-source = "git+https://github.com/DragonOS-Community/dsc.git?rev=f073773#f073773275e0969be41a3de68d4cf2aa8773ad05"
+source = "git+https://github.com/DragonOS-Community/dsc.git?rev=0f61350#0f61350272d93e1cbda1f5f565bdaf81cc942a9f"
 
 [[package]]
 name = "errno"

+ 1 - 1
Cargo.toml

@@ -43,7 +43,7 @@ sc = "0.2.3"
 [target.'cfg(target_os = "dragonos")'.dependencies]
 # Development
 #dsc = { path = "本地存放dsc的代码的路径" }
-dsc = { git = "https://github.com/DragonOS-Community/dsc.git", rev = "f073773" }
+dsc = { git = "https://github.com/DragonOS-Community/dsc.git", rev = "0f61350" }
 
 [target.'cfg(target_os = "redox")'.dependencies]
 redox_syscall = "0.3"

+ 42 - 0
init_dragonos_toolchain.sh

@@ -0,0 +1,42 @@
+# 当前脚本用于初始化自定义的Rust工具链
+if [ -z "$(which cargo)" ]; then
+    echo "尚未安装Rust,请先安装Rust"
+    exit 1
+fi
+
+DRAGONOS_UNKNOWN_ELF_PATH=$(rustc --print sysroot)/lib/rustlib/x86_64-unknown-dragonos
+mkdir -p ${DRAGONOS_UNKNOWN_ELF_PATH}/lib
+# 设置工具链配置文件
+echo   \
+"{\
+    \"arch\": \"x86_64\",
+    \"code-model\": \"kernel\",
+    \"cpu\": \"x86-64\",
+    \"os\": \"dragonos\",
+    \"target-endian\": \"little\",
+    \"target-pointer-width\": \"64\",
+    \"target-c-int-width\": \"32\",
+    \"data-layout\": \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\",
+    \"disable-redzone\": true,
+    \"features\": \"-3dnow,-3dnowa,-avx,-avx2\",
+    \"linker\": \"rust-lld\",
+    \"linker-flavor\": \"ld.lld\",
+    \"llvm-target\": \"x86_64-unknown-none\",
+    \"max-atomic-width\": 64,
+    \"panic-strategy\": \"abort\",
+    \"position-independent-executables\": true,
+    \"relro-level\": \"full\",
+    \"stack-probes\": {
+      \"kind\": \"inline-or-call\",
+      \"min-llvm-version-for-inline\": [
+        16,
+        0,
+        0
+      ]
+    },
+    \"static-position-independent-executables\": true,
+    \"supported-sanitizers\": [
+      \"kcfi\"
+    ],
+    \"target-pointer-width\": \"64\"
+}" > ${DRAGONOS_UNKNOWN_ELF_PATH}/target.json || exit 1

+ 2 - 4
src/platform/dragonos/mod.rs

@@ -120,13 +120,11 @@ impl Pal for Sys {
     }
 
     fn dup(fildes: c_int) -> c_int {
-        // e(unsafe { syscall!(DUP, fildes) }) as c_int
-        unimplemented!()
+        e(unsafe { syscall!(SYS_DUP, fildes) }) as c_int
     }
 
     fn dup2(fildes: c_int, fildes2: c_int) -> c_int {
-        // e(unsafe { syscall!(DUP3, fildes, fildes2, 0) }) as c_int
-        unimplemented!()
+        e(unsafe { syscall!(SYS_DUP2, fildes, fildes2) }) as c_int
     }
 
     unsafe fn execve(path: &CStr, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int {