Browse Source

Merge pull request #1 from DragonOS-Community/patch-add-dragonos-port

Patch add dragonos port
login 2 years ago
parent
commit
7016e5c833
45 changed files with 1674 additions and 10 deletions
  1. 2 0
      .cargo/config.toml
  2. 6 0
      Cargo.lock
  3. 5 0
      Cargo.toml
  4. 18 7
      Makefile
  5. 11 1
      README.md
  6. 1 0
      src/header/fcntl/cbindgen.toml
  7. 17 0
      src/header/fcntl/dragonos.rs
  8. 4 0
      src/header/fcntl/mod.rs
  9. 29 0
      src/header/netdb/dragonos.rs
  10. 4 0
      src/header/netdb/mod.rs
  11. 15 0
      src/header/pwd/dragonos.rs
  12. 5 0
      src/header/pwd/mod.rs
  13. 1 0
      src/header/signal/cbindgen.toml
  14. 76 0
      src/header/signal/dragonos.rs
  15. 4 0
      src/header/signal/mod.rs
  16. 1 0
      src/header/sys_epoll/cbindgen.toml
  17. 20 0
      src/header/sys_epoll/dragonos.rs
  18. 4 0
      src/header/sys_epoll/mod.rs
  19. 1 0
      src/header/sys_ioctl/cbindgen.toml
  20. 195 0
      src/header/sys_ioctl/dragonos.rs
  21. 4 0
      src/header/sys_ioctl/mod.rs
  22. 1 0
      src/header/sys_mman/cbindgen.toml
  23. 9 0
      src/header/sys_mman/dragonos.rs
  24. 7 0
      src/header/sys_mman/mod.rs
  25. 1 0
      src/header/sys_resource/cbindgen.toml
  26. 1 0
      src/header/sys_socket/cbindgen.toml
  27. 1 0
      src/header/termios/cbindgen.toml
  28. 113 0
      src/header/termios/dragonos.rs
  29. 18 0
      src/header/termios/mod.rs
  30. 1 0
      src/header/time/cbindgen.toml
  31. 4 0
      src/header/time/constants.rs
  32. 13 0
      src/header/time/dragonos.rs
  33. 1 0
      src/header/unistd/cbindgen.toml
  34. 3 0
      src/header/unistd/mod.rs
  35. 7 0
      src/ld_so/access.rs
  36. 248 0
      src/ld_so/ld_script/x86_64-unknown-dragonos.ld
  37. 10 1
      src/ld_so/mod.rs
  38. 9 1
      src/ld_so/tcb.rs
  39. 5 0
      src/lib.rs
  40. 37 0
      src/platform/dragonos/epoll.rs
  41. 546 0
      src/platform/dragonos/mod.rs
  42. 11 0
      src/platform/dragonos/ptrace.rs
  43. 63 0
      src/platform/dragonos/signal.rs
  44. 135 0
      src/platform/dragonos/socket.rs
  45. 7 0
      src/platform/mod.rs

+ 2 - 0
.cargo/config.toml

@@ -0,0 +1,2 @@
+[build]
+target = "x86_64-unknown-dragonos"

+ 6 - 0
Cargo.lock

@@ -108,6 +108,11 @@ version = "0.1.0"
 name = "crtn"
 version = "0.1.0"
 
+[[package]]
+name = "dsc"
+version = "0.1.0"
+source = "git+https://github.com/DragonOS-Community/dsc.git?rev=f073773#f073773275e0969be41a3de68d4cf2aa8773ad05"
+
 [[package]]
 name = "errno"
 version = "0.2.8"
@@ -406,6 +411,7 @@ dependencies = [
  "cbitset",
  "cc",
  "core_io",
+ "dsc",
  "goblin",
  "lazy_static",
  "memchr",

+ 5 - 0
Cargo.toml

@@ -40,6 +40,11 @@ optional = true
 [target.'cfg(target_os = "linux")'.dependencies]
 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" }
+
 [target.'cfg(target_os = "redox")'.dependencies]
 redox_syscall = "0.3"
 spin = "0.9.0"

+ 18 - 7
Makefile

@@ -1,4 +1,5 @@
-TARGET?=$(shell rustc -Z unstable-options --print target-spec-json | grep llvm-target | cut -d '"' -f4)
+# TARGET?=$(shell rustc -Z unstable-options --print target-spec-json | grep llvm-target | cut -d '"' -f4)
+TARGET=x86_64-unknown-dragonos
 
 CARGO?=cargo
 CARGO_TEST?=$(CARGO)
@@ -45,6 +46,16 @@ ifeq ($(TARGET),x86_64-unknown-redox)
 	export OBJCOPY=x86_64-unknown-redox-objcopy
 endif
 
+ifeq ($(TARGET),x86_64-unknown-dragonos)
+	export CC=gcc
+# export LD=ld
+	export LD=ld
+	export AR=ar
+# export AR=x86_64-dragonos-ar
+	export OBJCOPY=objcopy
+# export OBJCOPY=x86_64-dragonos-objcopy
+endif
+
 SRC=\
 	Cargo.* \
 	$(shell find src -type f)
@@ -74,24 +85,24 @@ install-headers: libs
 	cp -v "openlibm/src"/*.h "$(DESTDIR)/include"
 	cp -v "pthreads-emb/"*.h "$(DESTDIR)/include"
 
+# $(BUILD)/release/libc.so
 libs: \
 	$(BUILD)/release/libc.a \
-	$(BUILD)/release/libc.so \
 	$(BUILD)/release/crt0.o \
 	$(BUILD)/release/crti.o \
-	$(BUILD)/release/crtn.o \
-	$(BUILD)/release/ld_so
+	$(BUILD)/release/crtn.o
+#$(BUILD)/release/ld_so
 
 install-libs: libs
 	mkdir -pv "$(DESTDIR)/lib"
 	cp -v "$(BUILD)/release/libc.a" "$(DESTDIR)/lib"
-	cp -v "$(BUILD)/release/libc.so" "$(DESTDIR)/lib"
-	ln -frsv "$(DESTDIR)/lib/libc.so" "$(DESTDIR)/lib/libc.so.6"
+# cp -v "$(BUILD)/release/libc.so" "$(DESTDIR)/lib"
+# ln -frsv "$(DESTDIR)/lib/libc.so" "$(DESTDIR)/lib/libc.so.6"
 	cp -v "$(BUILD)/release/crt0.o" "$(DESTDIR)/lib"
 	ln -frsv "$(DESTDIR)/lib/crt0.o" "$(DESTDIR)/lib/crt1.o"
 	cp -v "$(BUILD)/release/crti.o" "$(DESTDIR)/lib"
 	cp -v "$(BUILD)/release/crtn.o" "$(DESTDIR)/lib"
-	cp -v "$(BUILD)/release/ld_so" "$(DESTDIR)/lib/ld64.so.1"
+# cp -v "$(BUILD)/release/ld_so" "$(DESTDIR)/lib/ld64.so.1"
 	cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a"
 	cp -v "$(BUILD)/pthreads-emb/libpthread.a" "$(DESTDIR)/lib/libpthread.a"
 	# Empty libraries for dl and rt

+ 11 - 1
README.md

@@ -1,11 +1,20 @@
 # relibc ![build](https://travis-ci.org/redox-os/relibc.svg?branch=master)
-relibc is a portable POSIX C standard library written in Rust. It is under heavy development, and currently supports Redox and Linux.
+relibc is a portable POSIX C standard library written in Rust. It is under heavy development, and currently supports Redox, Linux and DragonOS.
 
 The motivation for this project is twofold: Reduce issues the redox crew was having with newlib, and create a safer alternative to a C standard library written in C. It is mainly designed to be used under redox, as an alternative to newlib, but it also supports linux syscalls via the [sc](https://crates.io/crates/sc) crate.
 
 ## Building
 Just run `make all`.
 
+### Build for DragonOS
+
+You can follow the instructions to build relibc for DragonOS:
+
+```bash
+mkdir -p sysroot/usr
+make -j $(nproc) && DESTDIR=sysroot/usr make install -j $(nproc)
+```
+
 ### Issues
 #### I'm building for my own platform which I run, and am getting `x86_64-linux-gnu-ar: command not found` (or similar)
 The Makefile expects the gnu compiler tools prefixed with the platform specifier, as would be present when you'd install a cross compiler. Since you are building for your own platform, some distros (like Manjaro) don't install/symlink the prefixed executables.
@@ -27,6 +36,7 @@ An easy fix would be to replace the corresponding lines in the Makefile, e.g.
 
  - Redox OS
  - Linux
+ - DragonOS
 
 ## Supported architectures
 

+ 1 - 0
src/header/fcntl/cbindgen.toml

@@ -9,6 +9,7 @@ cpp_compat = true
 [defines]
 "target_os=linux" = "__linux__"
 "target_os=redox" = "__redox__"
+"target_os=dragonos" = "__dragonos__"
 
 [enum]
 prefix_with_name = true

+ 17 - 0
src/header/fcntl/dragonos.rs

@@ -0,0 +1,17 @@
+use crate::platform::types::*;
+
+pub const O_RDONLY: c_int = 0x0000;
+pub const O_WRONLY: c_int = 0x0001;
+pub const O_RDWR: c_int = 0x0002;
+pub const O_ACCMODE: c_int = 0x0003;
+pub const O_CREAT: c_int = 0x0040;
+pub const O_EXCL: c_int = 0x0080;
+pub const O_TRUNC: c_int = 0x0200;
+pub const O_APPEND: c_int = 0x0400;
+pub const O_NONBLOCK: c_int = 0x0800;
+pub const O_DIRECTORY: c_int = 0x1_0000;
+pub const O_NOFOLLOW: c_int = 0x2_0000;
+pub const O_CLOEXEC: c_int = 0x8_0000;
+pub const O_PATH: c_int = 0x20_0000;
+
+pub const FD_CLOEXEC: c_int = 0x8_0000;

+ 4 - 0
src/header/fcntl/mod.rs

@@ -11,6 +11,10 @@ pub use self::sys::*;
 #[path = "linux.rs"]
 pub mod sys;
 
+#[cfg(target_os = "dragonos")]
+#[path = "dragonos.rs"]
+pub mod sys;
+
 #[cfg(target_os = "redox")]
 #[path = "redox.rs"]
 pub mod sys;

+ 29 - 0
src/header/netdb/dragonos.rs

@@ -0,0 +1,29 @@
+use crate::{
+    c_str::CString,
+    fs::File,
+    header::fcntl,
+    io::{BufRead, BufReader},
+};
+use alloc::string::String;
+
+pub fn get_dns_server() -> String {
+    let file = match File::open(&CString::new("/etc/resolv.conf").unwrap(), fcntl::O_RDONLY) {
+        Ok(file) => file,
+        Err(_) => return String::new(), // TODO: better error handling
+    };
+    let file = BufReader::new(file);
+
+    for line in file.split(b'\n') {
+        let mut line = match line {
+            Ok(line) => line,
+            Err(_) => return String::new(), // TODO: pls handle errors
+        };
+        if line.starts_with(b"nameserver ") {
+            line.drain(..11);
+            return String::from_utf8(line).unwrap_or_default();
+        }
+    }
+
+    // TODO: better error handling
+    String::new()
+}

+ 4 - 0
src/header/netdb/mod.rs

@@ -33,6 +33,10 @@ use crate::{
 #[path = "linux.rs"]
 pub mod sys;
 
+#[cfg(target_os = "dragonos")]
+#[path = "dragonos.rs"]
+pub mod sys;
+
 #[cfg(target_os = "redox")]
 #[path = "redox.rs"]
 pub mod sys;

+ 15 - 0
src/header/pwd/dragonos.rs

@@ -0,0 +1,15 @@
+use super::{parsed, passwd};
+use crate::platform::types::*;
+
+pub fn split(line: &mut [u8]) -> Option<passwd> {
+    let mut parts = line.split_mut(|&c| c == b'\0');
+    Some(passwd {
+        pw_name: parts.next()?.as_mut_ptr() as *mut c_char,
+        pw_passwd: parts.next()?.as_mut_ptr() as *mut c_char,
+        pw_uid: parsed(parts.next())?,
+        pw_gid: parsed(parts.next())?,
+        pw_gecos: parts.next()?.as_mut_ptr() as *mut c_char,
+        pw_dir: parts.next()?.as_mut_ptr() as *mut c_char,
+        pw_shell: parts.next()?.as_mut_ptr() as *mut c_char,
+    })
+}

+ 5 - 0
src/header/pwd/mod.rs

@@ -16,11 +16,16 @@ use crate::{
 
 #[cfg(target_os = "linux")]
 mod linux;
+
+#[cfg(target_os = "dragonos")]
+mod dragonos;
 #[cfg(target_os = "redox")]
 mod redox;
 
 #[cfg(target_os = "linux")]
 use self::linux as sys;
+#[cfg(target_os = "dragonos")]
+use self::dragonos as sys;
 #[cfg(target_os = "redox")]
 use self::redox as sys;
 

+ 1 - 0
src/header/signal/cbindgen.toml

@@ -9,6 +9,7 @@ cpp_compat = true
 [defines]
 "target_os=linux" = "__linux__"
 "target_os=redox" = "__redox__"
+"target_os=dragonos" = "__dragonos__"
 
 [enum]
 prefix_with_name = true

+ 76 - 0
src/header/signal/dragonos.rs

@@ -0,0 +1,76 @@
+use core::arch::global_asm;
+
+// Needs to be defined in assembly because it can't have a function prologue
+// rax is register, 25 is RT_SIGRETURN
+#[cfg(target_arch = "x86_64")]
+global_asm!(
+    "
+    .global __restore_rt
+    __restore_rt:
+        mov rax, 25
+        int 0x80
+"
+);
+
+// x8 is register, 139 is RT_SIGRETURN
+#[cfg(target_arch = "aarch64")]
+global_asm!(
+    "
+    .global __restore_rt
+    __restore_rt:
+        mov x8, #139
+        svc 0
+"
+);
+
+pub const SIGHUP: usize = 1;
+pub const SIGINT: usize = 2;
+pub const SIGQUIT: usize = 3;
+pub const SIGILL: usize = 4;
+pub const SIGTRAP: usize = 5;
+pub const SIGABRT: usize = 6;
+pub const SIGIOT: usize = SIGABRT;
+pub const SIGBUS: usize = 7;
+pub const SIGFPE: usize = 8;
+pub const SIGKILL: usize = 9;
+pub const SIGUSR1: usize = 10;
+pub const SIGSEGV: usize = 11;
+pub const SIGUSR2: usize = 12;
+pub const SIGPIPE: usize = 13;
+pub const SIGALRM: usize = 14;
+pub const SIGTERM: usize = 15;
+pub const SIGSTKFLT: usize = 16;
+pub const SIGCHLD: usize = 17;
+pub const SIGCONT: usize = 18;
+pub const SIGSTOP: usize = 19;
+pub const SIGTSTP: usize = 20;
+pub const SIGTTIN: usize = 21;
+pub const SIGTTOU: usize = 22;
+pub const SIGURG: usize = 23;
+pub const SIGXCPU: usize = 24;
+pub const SIGXFSZ: usize = 25;
+pub const SIGVTALRM: usize = 26;
+pub const SIGPROF: usize = 27;
+pub const SIGWINCH: usize = 28;
+pub const SIGIO: usize = 29;
+pub const SIGPOLL: usize = SIGIO;
+pub const SIGPWR: usize = 30;
+pub const SIGSYS: usize = 31;
+pub const SIGUNUSED: usize = SIGSYS;
+pub const NSIG: usize = 32;
+
+pub const SA_NOCLDSTOP: usize = 1;
+pub const SA_NOCLDWAIT: usize = 2;
+pub const SA_SIGINFO: usize = 4;
+pub const SA_ONSTACK: usize = 0x0800_0000;
+pub const SA_RESTART: usize = 0x1000_0000;
+pub const SA_NODEFER: usize = 0x4000_0000;
+pub const SA_RESETHAND: usize = 0x8000_0000;
+pub const SA_RESTORER: usize = 0x0400_0000;
+
+pub const SS_ONSTACK: usize = 1;
+pub const SS_DISABLE: usize = 2;
+
+// Those two should be updated from kernel headers
+pub const MINSIGSTKSZ: usize = 2048;
+pub const SIGSTKSZ: usize = 8096;

+ 4 - 0
src/header/signal/mod.rs

@@ -15,6 +15,10 @@ pub use self::sys::*;
 #[path = "linux.rs"]
 pub mod sys;
 
+#[cfg(target_os = "dragonos")]
+#[path = "dragonos.rs"]
+pub mod sys;
+
 #[cfg(target_os = "redox")]
 #[path = "redox.rs"]
 pub mod sys;

+ 1 - 0
src/header/sys_epoll/cbindgen.toml

@@ -7,6 +7,7 @@ cpp_compat = true
 
 [defines]
 "target_os=linux" = "__linux__"
+"target_os=dragonos" = "__dragonos__"
 "target_os=redox" = "__redox__"
 "target_pointer_width=64" = "__LP64__"
 

+ 20 - 0
src/header/sys_epoll/dragonos.rs

@@ -0,0 +1,20 @@
+use crate::platform::types::*;
+
+pub const EPOLL_CLOEXEC: c_int = 0x8_0000;
+
+pub const EPOLLIN: c_uint = 0x001;
+pub const EPOLLPRI: c_uint = 0x002;
+pub const EPOLLOUT: c_uint = 0x004;
+pub const EPOLLRDNORM: c_uint = 0x040;
+pub const EPOLLNVAL: c_uint = 0x020;
+pub const EPOLLRDBAND: c_uint = 0x080;
+pub const EPOLLWRNORM: c_uint = 0x100;
+pub const EPOLLWRBAND: c_uint = 0x200;
+pub const EPOLLMSG: c_uint = 0x400;
+pub const EPOLLERR: c_uint = 0x008;
+pub const EPOLLHUP: c_uint = 0x010;
+pub const EPOLLRDHUP: c_uint = 0x2000;
+pub const EPOLLEXCLUSIVE: c_uint = 1 << 28;
+pub const EPOLLWAKEUP: c_uint = 1 << 29;
+pub const EPOLLONESHOT: c_uint = 1 << 30;
+pub const EPOLLET: c_uint = 1 << 31;

+ 4 - 0
src/header/sys_epoll/mod.rs

@@ -13,6 +13,10 @@ pub use self::sys::*;
 #[path = "linux.rs"]
 pub mod sys;
 
+#[cfg(target_os = "dragonos")]
+#[path = "dragonos.rs"]
+pub mod sys;
+
 #[cfg(target_os = "redox")]
 #[path = "redox.rs"]
 pub mod sys;

+ 1 - 0
src/header/sys_ioctl/cbindgen.toml

@@ -7,6 +7,7 @@ cpp_compat = true
 [defines]
 "target_os=linux" = "__linux__"
 "target_os=redox" = "__redox__"
+"target_os=dragonos" = "__dragonos__"
 
 [enum]
 prefix_with_name = true

+ 195 - 0
src/header/sys_ioctl/dragonos.rs

@@ -0,0 +1,195 @@
+use crate::platform::{types::*, Sys};
+
+#[no_mangle]
+pub unsafe extern "C" fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> c_int {
+    // TODO: Somehow support varargs to syscall??
+    Sys::ioctl(fd, request, out)
+}
+
+pub const TCGETS: c_ulong = 0x5401;
+pub const TCSETS: c_ulong = 0x5402;
+pub const TCSETSW: c_ulong = 0x5403;
+pub const TCSETSF: c_ulong = 0x5404;
+pub const TCGETA: c_ulong = 0x5405;
+pub const TCSETA: c_ulong = 0x5406;
+pub const TCSETAW: c_ulong = 0x5407;
+pub const TCSETAF: c_ulong = 0x5408;
+pub const TCSBRK: c_ulong = 0x5409;
+pub const TCXONC: c_ulong = 0x540A;
+pub const TCFLSH: c_ulong = 0x540B;
+pub const TIOCEXCL: c_ulong = 0x540C;
+pub const TIOCNXCL: c_ulong = 0x540D;
+pub const TIOCSCTTY: c_ulong = 0x540E;
+pub const TIOCGPGRP: c_ulong = 0x540F;
+pub const TIOCSPGRP: c_ulong = 0x5410;
+pub const TIOCOUTQ: c_ulong = 0x5411;
+pub const TIOCSTI: c_ulong = 0x5412;
+pub const TIOCGWINSZ: c_ulong = 0x5413;
+pub const TIOCSWINSZ: c_ulong = 0x5414;
+pub const TIOCMGET: c_ulong = 0x5415;
+pub const TIOCMBIS: c_ulong = 0x5416;
+pub const TIOCMBIC: c_ulong = 0x5417;
+pub const TIOCMSET: c_ulong = 0x5418;
+pub const TIOCGSOFTCAR: c_ulong = 0x5419;
+pub const TIOCSSOFTCAR: c_ulong = 0x541A;
+pub const FIONREAD: c_ulong = 0x541B;
+pub const TIOCINQ: c_ulong = FIONREAD;
+pub const TIOCLINUX: c_ulong = 0x541C;
+pub const TIOCCONS: c_ulong = 0x541D;
+pub const TIOCGSERIAL: c_ulong = 0x541E;
+pub const TIOCSSERIAL: c_ulong = 0x541F;
+pub const TIOCPKT: c_ulong = 0x5420;
+pub const FIONBIO: c_ulong = 0x5421;
+pub const TIOCNOTTY: c_ulong = 0x5422;
+pub const TIOCSETD: c_ulong = 0x5423;
+pub const TIOCGETD: c_ulong = 0x5424;
+pub const TCSBRKP: c_ulong = 0x5425;
+pub const TIOCSBRK: c_ulong = 0x5427;
+pub const TIOCCBRK: c_ulong = 0x5428;
+pub const TIOCGSID: c_ulong = 0x5429;
+pub const TIOCGRS485: c_ulong = 0x542E;
+pub const TIOCSRS485: c_ulong = 0x542F;
+pub const TIOCGPTN: c_ulong = 0x8004_5430;
+pub const TIOCSPTLCK: c_ulong = 0x4004_5431;
+pub const TIOCGDEV: c_ulong = 0x8004_5432;
+pub const TCGETX: c_ulong = 0x5432;
+pub const TCSETX: c_ulong = 0x5433;
+pub const TCSETXF: c_ulong = 0x5434;
+pub const TCSETXW: c_ulong = 0x5435;
+pub const TIOCSIG: c_ulong = 0x4004_5436;
+pub const TIOCVHANGUP: c_ulong = 0x5437;
+pub const TIOCGPKT: c_ulong = 0x8004_5438;
+pub const TIOCGPTLCK: c_ulong = 0x8004_5439;
+pub const TIOCGEXCL: c_ulong = 0x8004_5440;
+pub const TIOCGPTPEER: c_ulong = 0x5441;
+
+pub const FIONCLEX: c_ulong = 0x5450;
+pub const FIOCLEX: c_ulong = 0x5451;
+pub const FIOASYNC: c_ulong = 0x5452;
+pub const TIOCSERCONFIG: c_ulong = 0x5453;
+pub const TIOCSERGWILD: c_ulong = 0x5454;
+pub const TIOCSERSWILD: c_ulong = 0x5455;
+pub const TIOCGLCKTRMIOS: c_ulong = 0x5456;
+pub const TIOCSLCKTRMIOS: c_ulong = 0x5457;
+pub const TIOCSERGSTRUCT: c_ulong = 0x5458;
+pub const TIOCSERGETLSR: c_ulong = 0x5459;
+pub const TIOCSERGETMULTI: c_ulong = 0x545A;
+pub const TIOCSERSETMULTI: c_ulong = 0x545B;
+
+pub const TIOCMIWAIT: c_ulong = 0x545C;
+pub const TIOCGICOUNT: c_ulong = 0x545D;
+pub const FIOQSIZE: c_ulong = 0x5460;
+
+pub const TIOCPKT_DATA: c_ulong = 0;
+pub const TIOCPKT_FLUSHREAD: c_ulong = 1;
+pub const TIOCPKT_FLUSHWRITE: c_ulong = 2;
+pub const TIOCPKT_STOP: c_ulong = 4;
+pub const TIOCPKT_START: c_ulong = 8;
+pub const TIOCPKT_NOSTOP: c_ulong = 16;
+pub const TIOCPKT_DOSTOP: c_ulong = 32;
+pub const TIOCPKT_IOCTL: c_ulong = 64;
+
+pub const TIOCSER_TEMT: c_ulong = 0x01;
+
+pub const TIOCM_LE: c_ulong = 0x001;
+pub const TIOCM_DTR: c_ulong = 0x002;
+pub const TIOCM_RTS: c_ulong = 0x004;
+pub const TIOCM_ST: c_ulong = 0x008;
+pub const TIOCM_SR: c_ulong = 0x010;
+pub const TIOCM_CTS: c_ulong = 0x020;
+pub const TIOCM_CAR: c_ulong = 0x040;
+pub const TIOCM_RNG: c_ulong = 0x080;
+pub const TIOCM_DSR: c_ulong = 0x100;
+pub const TIOCM_CD: c_ulong = TIOCM_CAR;
+pub const TIOCM_RI: c_ulong = TIOCM_RNG;
+pub const TIOCM_OUT1: c_ulong = 0x2000;
+pub const TIOCM_OUT2: c_ulong = 0x4000;
+pub const TIOCM_LOOP: c_ulong = 0x8000;
+
+pub const N_TTY: c_ulong = 0;
+pub const N_SLIP: c_ulong = 1;
+pub const N_MOUSE: c_ulong = 2;
+pub const N_PPP: c_ulong = 3;
+pub const N_STRIP: c_ulong = 4;
+pub const N_AX25: c_ulong = 5;
+pub const N_X25: c_ulong = 6;
+pub const N_6PACK: c_ulong = 7;
+pub const N_MASC: c_ulong = 8;
+pub const N_R3964: c_ulong = 9;
+pub const N_PROFIBUS_FDL: c_ulong = 10;
+pub const N_IRDA: c_ulong = 11;
+pub const N_SMSBLOCK: c_ulong = 12;
+pub const N_HDLC: c_ulong = 13;
+pub const N_SYNC_PPP: c_ulong = 14;
+pub const N_HCI: c_ulong = 15;
+
+pub const FIOSETOWN: c_ulong = 0x8901;
+pub const SIOCSPGRP: c_ulong = 0x8902;
+pub const FIOGETOWN: c_ulong = 0x8903;
+pub const SIOCGPGRP: c_ulong = 0x8904;
+pub const SIOCATMARK: c_ulong = 0x8905;
+pub const SIOCGSTAMP: c_ulong = 0x8906;
+pub const SIOCGSTAMPNS: c_ulong = 0x8907;
+
+pub const SIOCADDRT: c_ulong = 0x890B;
+pub const SIOCDELRT: c_ulong = 0x890C;
+pub const SIOCRTMSG: c_ulong = 0x890D;
+
+pub const SIOCGIFNAME: c_ulong = 0x8910;
+pub const SIOCSIFLINK: c_ulong = 0x8911;
+pub const SIOCGIFCONF: c_ulong = 0x8912;
+pub const SIOCGIFFLAGS: c_ulong = 0x8913;
+pub const SIOCSIFFLAGS: c_ulong = 0x8914;
+pub const SIOCGIFADDR: c_ulong = 0x8915;
+pub const SIOCSIFADDR: c_ulong = 0x8916;
+pub const SIOCGIFDSTADDR: c_ulong = 0x8917;
+pub const SIOCSIFDSTADDR: c_ulong = 0x8918;
+pub const SIOCGIFBRDADDR: c_ulong = 0x8919;
+pub const SIOCSIFBRDADDR: c_ulong = 0x891a;
+pub const SIOCGIFNETMASK: c_ulong = 0x891b;
+pub const SIOCSIFNETMASK: c_ulong = 0x891c;
+pub const SIOCGIFMETRIC: c_ulong = 0x891d;
+pub const SIOCSIFMETRIC: c_ulong = 0x891e;
+pub const SIOCGIFMEM: c_ulong = 0x891f;
+pub const SIOCSIFMEM: c_ulong = 0x8920;
+pub const SIOCGIFMTU: c_ulong = 0x8921;
+pub const SIOCSIFMTU: c_ulong = 0x8922;
+pub const SIOCSIFNAME: c_ulong = 0x8923;
+pub const SIOCSIFHWADDR: c_ulong = 0x8924;
+pub const SIOCGIFENCAP: c_ulong = 0x8925;
+pub const SIOCSIFENCAP: c_ulong = 0x8926;
+pub const SIOCGIFHWADDR: c_ulong = 0x8927;
+pub const SIOCGIFSLAVE: c_ulong = 0x8929;
+pub const SIOCSIFSLAVE: c_ulong = 0x8930;
+pub const SIOCADDMULTI: c_ulong = 0x8931;
+pub const SIOCDELMULTI: c_ulong = 0x8932;
+pub const SIOCGIFINDEX: c_ulong = 0x8933;
+pub const SIOGIFINDEX: c_ulong = SIOCGIFINDEX;
+pub const SIOCSIFPFLAGS: c_ulong = 0x8934;
+pub const SIOCGIFPFLAGS: c_ulong = 0x8935;
+pub const SIOCDIFADDR: c_ulong = 0x8936;
+pub const SIOCSIFHWBROADCAST: c_ulong = 0x8937;
+pub const SIOCGIFCOUNT: c_ulong = 0x8938;
+
+pub const SIOCGIFBR: c_ulong = 0x8940;
+pub const SIOCSIFBR: c_ulong = 0x8941;
+
+pub const SIOCGIFTXQLEN: c_ulong = 0x8942;
+pub const SIOCSIFTXQLEN: c_ulong = 0x8943;
+
+pub const SIOCDARP: c_ulong = 0x8953;
+pub const SIOCGARP: c_ulong = 0x8954;
+pub const SIOCSARP: c_ulong = 0x8955;
+
+pub const SIOCDRARP: c_ulong = 0x8960;
+pub const SIOCGRARP: c_ulong = 0x8961;
+pub const SIOCSRARP: c_ulong = 0x8962;
+
+pub const SIOCGIFMAP: c_ulong = 0x8970;
+pub const SIOCSIFMAP: c_ulong = 0x8971;
+
+pub const SIOCADDDLCI: c_ulong = 0x8980;
+pub const SIOCDELDLCI: c_ulong = 0x8981;
+
+pub const SIOCDEVPRIVATE: c_ulong = 0x89F0;
+pub const SIOCPROTOPRIVATE: c_ulong = 0x89E0;

+ 4 - 0
src/header/sys_ioctl/mod.rs

@@ -27,6 +27,10 @@ pub use self::sys::*;
 #[path = "linux.rs"]
 pub mod sys;
 
+#[cfg(target_os = "dragonos")]
+#[path = "dragonos.rs"]
+pub mod sys;
+
 #[cfg(target_os = "redox")]
 #[path = "redox.rs"]
 pub mod sys;

+ 1 - 0
src/header/sys_mman/cbindgen.toml

@@ -9,6 +9,7 @@ cpp_compat = true
 [defines]
 "target_os=linux" = "__linux__"
 "target_os=redox" = "__redox__"
+"target_os=dragonos" = "__dragonos__"
 
 [enum]
 prefix_with_name = true

+ 9 - 0
src/header/sys_mman/dragonos.rs

@@ -0,0 +1,9 @@
+use crate::platform::types::*;
+
+pub const PROT_READ: c_int = 0x0001;
+pub const PROT_WRITE: c_int = 0x0002;
+pub const PROT_EXEC: c_int = 0x0004;
+pub const PROT_NONE: c_int = 0x0000;
+
+pub const MAP_FIXED: c_int = 0x0010;
+pub const MAP_FIXED_NOREPLACE: c_int = 0x100000;

+ 7 - 0
src/header/sys_mman/mod.rs

@@ -10,6 +10,10 @@ pub use self::sys::*;
 #[path = "linux.rs"]
 pub mod sys;
 
+#[cfg(target_os = "dragonos")]
+#[path = "dragonos.rs"]
+pub mod sys;
+
 #[cfg(target_os = "redox")]
 #[path = "redox.rs"]
 pub mod sys;
@@ -89,6 +93,9 @@ pub unsafe extern "C" fn munmap(addr: *mut c_void, len: size_t) -> c_int {
 #[cfg(target_os = "linux")]
 static SHM_PATH: &'static [u8] = b"/dev/shm/";
 
+#[cfg(target_os = "dragonos")]
+static SHM_PATH: &'static [u8] = b"/dev/shm/";
+
 #[cfg(target_os = "redox")]
 static SHM_PATH: &'static [u8] = b"shm:";
 

+ 1 - 0
src/header/sys_resource/cbindgen.toml

@@ -9,6 +9,7 @@ cpp_compat = true
 [defines]
 "target_os=linux" = "__linux__"
 "target_os=redox" = "__redox__"
+"target_os=dragonos" = "__dragonos__"
 
 [enum]
 prefix_with_name = true

+ 1 - 0
src/header/sys_socket/cbindgen.toml

@@ -9,6 +9,7 @@ cpp_compat = true
 [defines]
 "target_os=linux" = "__linux__"
 "target_os=redox" = "__redox__"
+"target_os=dragonos" = "__dragonos__"
 
 [enum]
 prefix_with_name = true

+ 1 - 0
src/header/termios/cbindgen.toml

@@ -8,6 +8,7 @@ cpp_compat = true
 [defines]
 "target_os=linux" = "__linux__"
 "target_os=redox" = "__redox__"
+"target_os=dragonos" = "__dragonos__"
 
 [enum]
 prefix_with_name = true

+ 113 - 0
src/header/termios/dragonos.rs

@@ -0,0 +1,113 @@
+/* c_cc { */
+pub const VINTR: usize = 0;
+pub const VQUIT: usize = 1;
+pub const VERASE: usize = 2;
+pub const VKILL: usize = 3;
+pub const VEOF: usize = 4;
+pub const VTIME: usize = 5;
+pub const VMIN: usize = 6;
+pub const VSWTC: usize = 7;
+pub const VSTART: usize = 8;
+pub const VSTOP: usize = 9;
+pub const VSUSP: usize = 10;
+pub const VEOL: usize = 11;
+pub const VREPRINT: usize = 12;
+pub const VDISCARD: usize = 13;
+pub const VWERASE: usize = 14;
+pub const VLNEXT: usize = 15;
+pub const VEOL2: usize = 16;
+pub const NCCS: usize = 32;
+/* } c_cc */
+
+/* c_iflag { */
+pub const IGNBRK: usize = 0o000_001;
+pub const BRKINT: usize = 0o000_002;
+pub const IGNPAR: usize = 0o000_004;
+pub const PARMRK: usize = 0o000_010;
+pub const INPCK: usize = 0o000_020;
+pub const ISTRIP: usize = 0o000_040;
+pub const INLCR: usize = 0o000_100;
+pub const IGNCR: usize = 0o000_200;
+pub const ICRNL: usize = 0o000_400;
+pub const IUCLC: usize = 0o001_000;
+pub const IXON: usize = 0o002_000;
+pub const IXANY: usize = 0o004_000;
+pub const IXOFF: usize = 0o010_000;
+pub const IMAXBEL: usize = 0o020_000;
+pub const IUTF8: usize = 0o040_000;
+/* } c_iflag */
+
+/* c_oflag { */
+pub const OPOST: usize = 0o000_001;
+pub const OLCUC: usize = 0o000_002;
+pub const ONLCR: usize = 0o000_004;
+pub const OCRNL: usize = 0o000_010;
+pub const ONOCR: usize = 0o000_020;
+pub const ONLRET: usize = 0o000_040;
+pub const OFILL: usize = 0o000_100;
+pub const OFDEL: usize = 0o000_200;
+
+pub const VTDLY: usize = 0o040_000;
+pub const VT0: usize = 0o000_000;
+pub const VT1: usize = 0o040_000;
+/* } c_oflag */
+
+/* c_cflag { */
+pub const B0: usize = 0o000_000;
+pub const B50: usize = 0o000_001;
+pub const B75: usize = 0o000_002;
+pub const B110: usize = 0o000_003;
+pub const B134: usize = 0o000_004;
+pub const B150: usize = 0o000_005;
+pub const B200: usize = 0o000_006;
+pub const B300: usize = 0o000_007;
+pub const B600: usize = 0o000_010;
+pub const B1200: usize = 0o000_011;
+pub const B1800: usize = 0o000_012;
+pub const B2400: usize = 0o000_013;
+pub const B4800: usize = 0o000_014;
+pub const B9600: usize = 0o000_015;
+pub const B19200: usize = 0o000_016;
+pub const B38400: usize = 0o000_017;
+
+pub const B57600: usize = 0o010_001;
+pub const B115200: usize = 0o010_002;
+pub const B230400: usize = 0o010_003;
+pub const B460800: usize = 0o010_004;
+pub const B500000: usize = 0o010_005;
+pub const B576000: usize = 0o010_006;
+pub const B921600: usize = 0o010_007;
+pub const B1000000: usize = 0o010_010;
+pub const B1152000: usize = 0o010_011;
+pub const B1500000: usize = 0o010_012;
+pub const B2000000: usize = 0o010_013;
+pub const B2500000: usize = 0o010_014;
+pub const B3000000: usize = 0o010_015;
+pub const B3500000: usize = 0o010_016;
+pub const B4000000: usize = 0o010_017;
+
+pub const CSIZE: usize = 0o000_060;
+pub const CS5: usize = 0o000_000;
+pub const CS6: usize = 0o000_020;
+pub const CS7: usize = 0o000_040;
+pub const CS8: usize = 0o000_060;
+
+pub const CSTOPB: usize = 0o000_100;
+pub const CREAD: usize = 0o000_200;
+pub const PARENB: usize = 0o000_400;
+pub const PARODD: usize = 0o001_000;
+pub const HUPCL: usize = 0o002_000;
+pub const CLOCAL: usize = 0o004_000;
+/* } c_clfag */
+
+/* c_lflag { */
+pub const ISIG: usize = 0o000_001;
+pub const ICANON: usize = 0o000_002;
+pub const ECHO: usize = 0o000_010;
+pub const ECHOE: usize = 0o000_020;
+pub const ECHOK: usize = 0o000_040;
+pub const ECHONL: usize = 0o000_100;
+pub const NOFLSH: usize = 0o000_200;
+pub const TOSTOP: usize = 0o000_400;
+pub const IEXTEN: usize = 0o100_000;
+/* } c_lflag */

+ 18 - 0
src/header/termios/mod.rs

@@ -11,6 +11,10 @@ pub use self::sys::*;
 #[path = "linux.rs"]
 pub mod sys;
 
+#[cfg(target_os = "dragonos")]
+#[path = "dragonos.rs"]
+pub mod sys;
+
 #[cfg(target_os = "redox")]
 #[path = "redox.rs"]
 pub mod sys;
@@ -46,6 +50,20 @@ pub struct termios {
     __c_ospeed: speed_t,
 }
 
+#[cfg(target_os = "dragonos")]
+#[repr(C)]
+#[derive(Default)]
+pub struct termios {
+    c_iflag: tcflag_t,
+    c_oflag: tcflag_t,
+    c_cflag: tcflag_t,
+    c_lflag: tcflag_t,
+    c_line: cc_t,
+    c_cc: [cc_t; NCCS],
+    __c_ispeed: speed_t,
+    __c_ospeed: speed_t,
+}
+
 // Must match structure in redox_termios
 #[cfg(target_os = "redox")]
 #[repr(C)]

+ 1 - 0
src/header/time/cbindgen.toml

@@ -11,3 +11,4 @@ prefix_with_name = true
 [defines]
 "target_os = linux" = "__linux__"
 "target_os = redox" = "__redox__"
+"target_os = dragonos" = "__dragonos__"

+ 4 - 0
src/header/time/constants.rs

@@ -6,6 +6,10 @@ pub use self::sys::*;
 #[path = "linux.rs"]
 pub mod sys;
 
+#[cfg(target_os = "dragonos")]
+#[path = "dragonos.rs"]
+pub mod sys;
+
 #[cfg(target_os = "redox")]
 #[path = "redox.rs"]
 pub mod sys;

+ 13 - 0
src/header/time/dragonos.rs

@@ -0,0 +1,13 @@
+use crate::platform::types::*;
+
+pub const CLOCK_REALTIME: c_int = 0;
+pub const CLOCK_MONOTONIC: c_int = 1;
+pub const CLOCK_PROCESS_CPUTIME_ID: c_int = 2;
+pub const CLOCK_THREAD_CPUTIME_ID: c_int = 3;
+pub const CLOCK_MONOTONIC_RAW: c_int = 4;
+pub const CLOCK_REALTIME_COARSE: c_int = 5;
+pub const CLOCK_MONOTONIC_COARSE: c_int = 6;
+pub const CLOCK_BOOTTIME: c_int = 7;
+pub const CLOCK_REALTIME_ALARM: c_int = 8;
+pub const CLOCK_BOOTTIME_ALARM: c_int = 9;
+pub const CLOCK_TAI: c_int = 11;

+ 1 - 0
src/header/unistd/cbindgen.toml

@@ -12,3 +12,4 @@ prefix_with_name = true
 [defines]
 "target_os = linux" = "__linux__"
 "target_os = redox" = "__redox__"
+"target_os = dragonos" = "__dragonos__"

+ 3 - 0
src/header/unistd/mod.rs

@@ -171,6 +171,9 @@ pub unsafe extern "C" fn execve(
 #[cfg(target_os = "linux")]
 const PATH_SEPARATOR: u8 = b':';
 
+#[cfg(target_os = "dragonos")]
+const PATH_SEPARATOR: u8 = b':';
+
 #[cfg(target_os = "redox")]
 const PATH_SEPARATOR: u8 = b';';
 

+ 7 - 0
src/ld_so/access.rs

@@ -21,6 +21,13 @@ unsafe fn access(path: *const c_char, mode: c_int) -> c_int {
     syscall!(ACCESS, (path).as_ptr(), mode) as c_int
 }
 
+#[cfg(target_os = "dragonos")]
+unsafe fn access(path: *const c_char, mode: c_int) -> c_int {
+    // let path = CStr::from_ptr(path);
+    // syscall!(ACCESS, (path).as_ptr(), mode) as c_int
+    return -1;
+}
+
 // Wrapper over the systemcall, Do not use outside of ld_so
 #[cfg(target_os = "redox")]
 unsafe fn access(path: *const c_char, mode: c_int) -> c_int {

+ 248 - 0
src/ld_so/ld_script/x86_64-unknown-dragonos.ld

@@ -0,0 +1,248 @@
+/* Script for -z combreloc */
+/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
+   Copying and distribution of this script, with or without modification,
+   are permitted in any medium without royalty provided the copyright
+   notice and this notice are preserved.  */
+OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64",
+              "elf64-x86-64")
+OUTPUT_ARCH(i386:x86-64)
+ENTRY(_start)
+SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib64");
+SEARCH_DIR("/usr/lib64/binutils/x86_64-pc-linux-gnu/2.33.164");
+SEARCH_DIR("/usr/local/lib64");
+SEARCH_DIR("/lib64");
+SEARCH_DIR("/usr/lib64");
+SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib");
+SEARCH_DIR("/usr/lib64/binutils/x86_64-pc-linux-gnu/2.33.1");
+SEARCH_DIR("/usr/local/lib");
+SEARCH_DIR("/lib");
+SEARCH_DIR("/usr/lib");
+SECTIONS
+{
+  /* Read-only sections, merged into text segment: */
+  PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x20000000) + SIZEOF_HEADERS;
+  .interp         : { *(.interp) }
+  .note.gnu.build-id  : { *(.note.gnu.build-id) }
+  .hash           : { *(.hash) }
+  .gnu.hash       : { *(.gnu.hash) }
+  .dynsym         : { *(.dynsym) }
+  .dynstr         : { *(.dynstr) }
+  .gnu.version    : { *(.gnu.version) }
+  .gnu.version_d  : { *(.gnu.version_d) }
+  .gnu.version_r  : { *(.gnu.version_r) }
+  .rela.dyn       :
+    {
+      *(.rela.init)
+      *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
+      *(.rela.fini)
+      *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
+      *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
+      *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
+      *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
+      *(.rela.ctors)
+      *(.rela.dtors)
+      *(.rela.got)
+      *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
+      *(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
+      *(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
+      *(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
+      *(.rela.ifunc)
+    }
+  .rela.plt       :
+    {
+      *(.rela.plt)
+      PROVIDE_HIDDEN (__rela_iplt_start = .);
+      *(.rela.iplt)
+      PROVIDE_HIDDEN (__rela_iplt_end = .);
+    }
+  . = ALIGN(CONSTANT (MAXPAGESIZE));
+  .init           :
+  {
+    KEEP (*(SORT_NONE(.init)))
+  }
+  .plt            : { *(.plt) *(.iplt) }
+.plt.got        : { *(.plt.got) }
+.plt.sec        : { *(.plt.sec) }
+  .text           :
+  {
+    *(.text.unlikely .text.*_unlikely .text.unlikely.*)
+    *(.text.exit .text.exit.*)
+    *(.text.startup .text.startup.*)
+    *(.text.hot .text.hot.*)
+    *(.text .stub .text.* .gnu.linkonce.t.*)
+    /* .gnu.warning sections are handled specially by elf.em.  */
+    *(.gnu.warning)
+  }
+  .fini           :
+  {
+    KEEP (*(SORT_NONE(.fini)))
+  }
+  PROVIDE (__etext = .);
+  PROVIDE (_etext = .);
+  PROVIDE (etext = .);
+  . = ALIGN(CONSTANT (MAXPAGESIZE));
+  /* Adjust the address for the rodata segment.  We want to adjust up to
+     the same address within the page on the next page up.  */
+  . = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)));
+  .rodata         : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
+  .rodata1        : { *(.rodata1) }
+  .eh_frame_hdr   : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
+  .eh_frame       : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
+  .gcc_except_table   : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
+  .gnu_extab   : ONLY_IF_RO { *(.gnu_extab*) }
+  /* These sections are generated by the Sun/Oracle C++ compiler.  */
+  .exception_ranges   : ONLY_IF_RO { *(.exception_ranges*) }
+  /* Adjust the address for the data segment.  We want to adjust up to
+     the same address within the page on the next page up.  */
+  . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
+  /* Exception handling  */
+  .eh_frame       : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
+  .gnu_extab      : ONLY_IF_RW { *(.gnu_extab) }
+  .gcc_except_table   : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
+  .exception_ranges   : ONLY_IF_RW { *(.exception_ranges*) }
+  /* Thread Local Storage sections  */
+  .tdata          :
+   {
+     PROVIDE_HIDDEN (__tdata_start = .);
+     *(.tdata .tdata.* .gnu.linkonce.td.*)
+   }
+  .tbss           : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
+  .preinit_array    :
+  {
+    PROVIDE_HIDDEN (__preinit_array_start = .);
+    KEEP (*(.preinit_array))
+    PROVIDE_HIDDEN (__preinit_array_end = .);
+  }
+  .init_array    :
+  {
+    PROVIDE_HIDDEN (__init_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
+    KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
+    PROVIDE_HIDDEN (__init_array_end = .);
+  }
+  .fini_array    :
+  {
+    PROVIDE_HIDDEN (__fini_array_start = .);
+    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
+    KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
+    PROVIDE_HIDDEN (__fini_array_end = .);
+  }
+  .ctors          :
+  {
+    /* gcc uses crtbegin.o to find the start of
+       the constructors, so we make sure it is
+       first.  Because this is a wildcard, it
+       doesn't matter if the user does not
+       actually link against crtbegin.o; the
+       linker won't look for a file to match a
+       wildcard.  The wildcard also means that it
+       doesn't matter which directory crtbegin.o
+       is in.  */
+    KEEP (*crtbegin.o(.ctors))
+    KEEP (*crtbegin?.o(.ctors))
+    /* We don't want to include the .ctor section from
+       the crtend.o file until after the sorted ctors.
+       The .ctor section from the crtend file contains the
+       end of ctors marker and it must be last */
+    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
+    KEEP (*(SORT(.ctors.*)))
+    KEEP (*(.ctors))
+  }
+  .dtors          :
+  {
+    KEEP (*crtbegin.o(.dtors))
+    KEEP (*crtbegin?.o(.dtors))
+    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
+    KEEP (*(SORT(.dtors.*)))
+    KEEP (*(.dtors))
+  }
+  .jcr            : { KEEP (*(.jcr)) }
+  .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
+  .dynamic        : { *(.dynamic) }
+  .got            : { *(.got) *(.igot) }
+  . = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
+  .got.plt        : { *(.got.plt) *(.igot.plt) }
+  .data           :
+  {
+    *(.data .data.* .gnu.linkonce.d.*)
+    SORT(CONSTRUCTORS)
+  }
+  .data1          : { *(.data1) }
+  _edata = .; PROVIDE (edata = .);
+  . = .;
+  __bss_start = .;
+  .bss            :
+  {
+   *(.dynbss)
+   *(.bss .bss.* .gnu.linkonce.b.*)
+   *(COMMON)
+   /* Align here to ensure that the .bss section occupies space up to
+      _end.  Align after .bss to ensure correct alignment even if the
+      .bss section disappears because there are no input sections.
+      FIXME: Why do we need it? When there is no .bss section, we do not
+      pad the .data section.  */
+   . = ALIGN(. != 0 ? 64 / 8 : 1);
+  }
+  .lbss   :
+  {
+    *(.dynlbss)
+    *(.lbss .lbss.* .gnu.linkonce.lb.*)
+    *(LARGE_COMMON)
+  }
+  . = ALIGN(64 / 8);
+  . = SEGMENT_START("ldata-segment", .);
+  .lrodata   ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
+  {
+    *(.lrodata .lrodata.* .gnu.linkonce.lr.*)
+  }
+  .ldata   ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
+  {
+    *(.ldata .ldata.* .gnu.linkonce.l.*)
+    . = ALIGN(. != 0 ? 64 / 8 : 1);
+  }
+  . = ALIGN(64 / 8);
+  _end = .; PROVIDE (end = .);
+  . = DATA_SEGMENT_END (.);
+  /* Stabs debugging sections.  */
+  .stab          0 : { *(.stab) }
+  .stabstr       0 : { *(.stabstr) }
+  .stab.excl     0 : { *(.stab.excl) }
+  .stab.exclstr  0 : { *(.stab.exclstr) }
+  .stab.index    0 : { *(.stab.index) }
+  .stab.indexstr 0 : { *(.stab.indexstr) }
+  .comment       0 : { *(.comment) }
+  .gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
+  /* DWARF debug sections.
+     Symbols in the DWARF debugging sections are relative to the beginning
+     of the section so we begin them at 0.  */
+  /* DWARF 1 */
+  .debug          0 : { *(.debug) }
+  .line           0 : { *(.line) }
+  /* GNU DWARF 1 extensions */
+  .debug_srcinfo  0 : { *(.debug_srcinfo) }
+  .debug_sfnames  0 : { *(.debug_sfnames) }
+  /* DWARF 1.1 and DWARF 2 */
+  .debug_aranges  0 : { *(.debug_aranges) }
+  .debug_pubnames 0 : { *(.debug_pubnames) }
+  /* DWARF 2 */
+  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
+  .debug_abbrev   0 : { *(.debug_abbrev) }
+  .debug_line     0 : { *(.debug_line .debug_line.* .debug_line_end) }
+  .debug_frame    0 : { *(.debug_frame) }
+  .debug_str      0 : { *(.debug_str) }
+  .debug_loc      0 : { *(.debug_loc) }
+  .debug_macinfo  0 : { *(.debug_macinfo) }
+  /* SGI/MIPS DWARF 2 extensions */
+  .debug_weaknames 0 : { *(.debug_weaknames) }
+  .debug_funcnames 0 : { *(.debug_funcnames) }
+  .debug_typenames 0 : { *(.debug_typenames) }
+  .debug_varnames  0 : { *(.debug_varnames) }
+  /* DWARF 3 */
+  .debug_pubtypes 0 : { *(.debug_pubtypes) }
+  .debug_ranges   0 : { *(.debug_ranges) }
+  /* DWARF Extension.  */
+  .debug_macro    0 : { *(.debug_macro) }
+  .debug_addr     0 : { *(.debug_addr) }
+  .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
+  /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
+}

+ 10 - 1
src/ld_so/mod.rs

@@ -14,6 +14,9 @@ pub const PATH_SEP: char = ';';
 #[cfg(target_os = "linux")]
 pub const PATH_SEP: char = ':';
 
+#[cfg(target_os = "dragonos")]
+pub const PATH_SEP: char = ':';
+
 mod access;
 pub mod callbacks;
 pub mod debug;
@@ -138,7 +141,7 @@ pub fn static_init(sp: &'static Stack) {
     }
 }
 
-#[cfg(any(target_os = "linux", target_os = "redox"))]
+#[cfg(any(target_os = "linux", target_os = "redox", target_os = "dragonos"))]
 pub unsafe fn init(sp: &'static Stack) {
     let mut tp = 0usize;
 
@@ -147,6 +150,12 @@ pub unsafe fn init(sp: &'static Stack) {
         const ARCH_GET_FS: usize = 0x1003;
         syscall!(ARCH_PRCTL, ARCH_GET_FS, &mut tp as *mut usize);
     }
+    #[cfg(target_os = "dragonos")]
+    {
+        const ARCH_GET_FS: usize = 0x1003;
+        // syscall!(ARCH_PRCTL, ARCH_GET_FS, &mut tp as *mut usize);
+        unimplemented!()
+    }
     #[cfg(all(target_os = "redox", target_arch = "aarch64"))]
     {
         core::arch::asm!(

+ 9 - 1
src/ld_so/tcb.rs

@@ -194,7 +194,7 @@ impl Tcb {
     }
 
     /// OS specific code to create a new TLS and TCB - Linux and Redox
-    #[cfg(any(target_os = "linux", target_os = "redox"))]
+    #[cfg(any(target_os = "linux", target_os = "redox", target_os = "dragonos"))]
     unsafe fn os_new(
         size: usize,
     ) -> Result<(&'static mut [u8], &'static mut [u8], &'static mut [u8])> {
@@ -255,6 +255,14 @@ impl Tcb {
         const ARCH_SET_FS: usize = 0x1002;
         syscall!(ARCH_PRCTL, ARCH_SET_FS, tls_end);
     }
+    
+    /// OS and architecture specific code to activate TLS - DragonOS x86_64
+    #[cfg(all(target_os = "dragonos", target_arch = "x86_64"))]
+    unsafe fn os_arch_activate(tls_end: usize, _tls_len: usize) {
+        const ARCH_SET_FS: usize = 0x1002;
+        // syscall!(ARCH_PRCTL, ARCH_SET_FS, tls_end);
+        unimplemented!()
+    }
 
     /// OS and architecture specific code to activate TLS - Redox aarch64
     #[cfg(all(target_os = "redox", target_arch = "aarch64"))]

+ 5 - 0
src/lib.rs

@@ -40,6 +40,11 @@ extern crate rand;
 #[macro_use]
 extern crate sc;
 
+// TODO: fix this: adjust to dragonos sc
+#[cfg(target_os = "dragonos")]
+#[macro_use]
+extern crate dsc;
+
 #[cfg(target_os = "redox")]
 extern crate syscall;
 

+ 37 - 0
src/platform/dragonos/epoll.rs

@@ -0,0 +1,37 @@
+use super::{
+    super::{types::*, PalEpoll},
+    e, Sys,
+};
+use crate::header::{signal::sigset_t, sys_epoll::epoll_event};
+
+impl PalEpoll for Sys {
+    fn epoll_create1(flags: c_int) -> c_int {
+        // unsafe { e(syscall!(EPOLL_CREATE1, flags)) as c_int }
+        unimplemented!()
+    }
+
+    fn epoll_ctl(epfd: c_int, op: c_int, fd: c_int, event: *mut epoll_event) -> c_int {
+        // unsafe { e(syscall!(EPOLL_CTL, epfd, op, fd, event)) as c_int }
+        unimplemented!()
+    }
+
+    fn epoll_pwait(
+        epfd: c_int,
+        events: *mut epoll_event,
+        maxevents: c_int,
+        timeout: c_int,
+        sigmask: *const sigset_t,
+    ) -> c_int {
+        // unsafe {
+        //     e(syscall!(
+        //         EPOLL_PWAIT,
+        //         epfd,
+        //         events,
+        //         maxevents,
+        //         timeout,
+        //         sigmask
+        //     )) as c_int
+        // }
+        unimplemented!()
+    }
+}

+ 546 - 0
src/platform/dragonos/mod.rs

@@ -0,0 +1,546 @@
+use core::{arch::asm, ptr};
+use core_io::Write;
+
+use super::{errno, types::*, Pal};
+use crate::{
+    c_str::CStr,
+    header::{dirent::dirent, signal::SIGCHLD, sys_stat::S_IFIFO},
+};
+// use header::sys_resource::rusage;
+use crate::header::{
+    sys_resource::rlimit,
+    sys_stat::stat,
+    sys_statvfs::statvfs,
+    sys_time::{timeval, timezone},
+};
+// use header::sys_times::tms;
+use crate::header::{sys_utsname::utsname, time::timespec};
+
+mod epoll;
+mod ptrace;
+mod signal;
+mod socket;
+
+const AT_FDCWD: c_int = -100;
+const AT_EMPTY_PATH: c_int = 0x1000;
+const AT_REMOVEDIR: c_int = 0x200;
+
+const SYS_CLONE: usize = 56;
+const CLONE_VM: usize = 0x0100;
+const CLONE_FS: usize = 0x0200;
+const CLONE_FILES: usize = 0x0400;
+const CLONE_SIGHAND: usize = 0x0800;
+const CLONE_THREAD: usize = 0x00010000;
+
+#[repr(C)]
+#[derive(Default)]
+struct linux_statfs {
+    f_type: c_long,       /* type of file system (see below) */
+    f_bsize: c_long,      /* optimal transfer block size */
+    f_blocks: fsblkcnt_t, /* total data blocks in file system */
+    f_bfree: fsblkcnt_t,  /* free blocks in fs */
+    f_bavail: fsblkcnt_t, /* free blocks available to unprivileged user */
+    f_files: fsfilcnt_t,  /* total file nodes in file system */
+    f_ffree: fsfilcnt_t,  /* free file nodes in fs */
+    f_fsid: c_long,       /* file system id */
+    f_namelen: c_long,    /* maximum length of filenames */
+    f_frsize: c_long,     /* fragment size (since Linux 2.6) */
+    f_flags: c_long,
+    f_spare: [c_long; 4],
+}
+
+pub fn e(sys: usize) -> usize {
+    if (sys as isize) < 0 && (sys as isize) >= -256 {
+        unsafe {
+            errno = -(sys as isize) as c_int;
+        }
+        !0
+    } else {
+        sys
+    }
+}
+
+pub struct Sys;
+
+impl Sys {
+    // fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int {
+    //     e(unsafe { syscall!(GETRUSAGE, who, r_usage) }) as c_int
+    // }
+
+    pub unsafe fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> c_int {
+        // TODO: Somehow support varargs to syscall??
+        // e(syscall!(IOCTL, fd, request, out)) as c_int
+        unimplemented!()
+    }
+
+    // fn times(out: *mut tms) -> clock_t {
+    //     unsafe { syscall!(TIMES, out) as clock_t }
+    // }
+}
+
+impl Pal for Sys {
+    fn access(path: &CStr, mode: c_int) -> c_int {
+        // e(unsafe { syscall!(ACCESS, path.as_ptr(), mode) }) as c_int
+        unimplemented!()
+    }
+
+    fn brk(addr: *mut c_void) -> *mut c_void {
+        unsafe { syscall!(SYS_BRK, addr) as *mut c_void }
+    }
+
+    fn chdir(path: &CStr) -> c_int {
+        e(unsafe { syscall!(SYS_CHDIR, path.as_ptr()) }) as c_int
+    }
+
+    fn chmod(path: &CStr, mode: mode_t) -> c_int {
+        // e(unsafe { syscall!(FCHMODAT, AT_FDCWD, path.as_ptr(), mode, 0) }) as c_int
+        return 0;
+    }
+
+    fn chown(path: &CStr, owner: uid_t, group: gid_t) -> c_int {
+        // e(unsafe {
+        //     syscall!(
+        //         FCHOWNAT,
+        //         AT_FDCWD,
+        //         path.as_ptr(),
+        //         owner as u32,
+        //         group as u32
+        //     )
+        // }) as c_int
+        return 0;
+    }
+
+    fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int {
+        // e(unsafe { syscall!(CLOCK_GETTIME, clk_id, tp) }) as c_int
+        unimplemented!()
+    }
+
+    fn close(fildes: c_int) -> c_int {
+        e(unsafe { syscall!(SYS_CLOSE, fildes) }) as c_int
+    }
+
+    fn dup(fildes: c_int) -> c_int {
+        // e(unsafe { syscall!(DUP, fildes) }) as c_int
+        unimplemented!()
+    }
+
+    fn dup2(fildes: c_int, fildes2: c_int) -> c_int {
+        // e(unsafe { syscall!(DUP3, fildes, fildes2, 0) }) as c_int
+        unimplemented!()
+    }
+
+    unsafe fn execve(path: &CStr, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int {
+        e(syscall!(SYS_EXECVE, path.as_ptr(), argv, envp)) as c_int
+    }
+
+    fn exit(status: c_int) -> ! {
+        unsafe {
+            syscall!(SYS_EXIT, status);
+        }
+        loop {}
+    }
+
+    fn fchdir(fildes: c_int) -> c_int {
+        // e(unsafe { syscall!(FCHDIR, fildes) }) as c_int
+        unimplemented!()
+    }
+
+    fn fchmod(fildes: c_int, mode: mode_t) -> c_int {
+        // e(unsafe { syscall!(FCHMOD, fildes, mode) }) as c_int
+        return 0;
+    }
+
+    fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int {
+        // e(unsafe { syscall!(FCHOWN, fildes, owner, group) }) as c_int
+        return 0;
+    }
+
+    fn flock(fd: c_int, operation: c_int) -> c_int {
+        // e(unsafe { syscall!(FLOCK, fd, operation) }) as c_int
+        return 0;
+    }
+
+    fn fstat(fildes: c_int, buf: *mut stat) -> c_int {
+        // let empty = b"\0";
+        // let empty_ptr = empty.as_ptr() as *const c_char;
+        // e(unsafe { syscall!(NEWFSTATAT, fildes, empty_ptr, buf, AT_EMPTY_PATH) }) as c_int
+        unimplemented!()
+    }
+
+    fn fstatvfs(fildes: c_int, buf: *mut statvfs) -> c_int {
+        // let mut kbuf = linux_statfs::default();
+        // let kbuf_ptr = &mut kbuf as *mut linux_statfs;
+        // let res = e(unsafe { syscall!(FSTATFS, fildes, kbuf_ptr) }) as c_int;
+        // if res == 0 {
+        //     unsafe {
+        //         if !buf.is_null() {
+        //             (*buf).f_bsize = kbuf.f_bsize as c_ulong;
+        //             (*buf).f_frsize = if kbuf.f_frsize != 0 {
+        //                 kbuf.f_frsize
+        //             } else {
+        //                 kbuf.f_bsize
+        //             } as c_ulong;
+        //             (*buf).f_blocks = kbuf.f_blocks;
+        //             (*buf).f_bfree = kbuf.f_bfree;
+        //             (*buf).f_bavail = kbuf.f_bavail;
+        //             (*buf).f_files = kbuf.f_files;
+        //             (*buf).f_ffree = kbuf.f_ffree;
+        //             (*buf).f_favail = kbuf.f_ffree;
+        //             (*buf).f_fsid = kbuf.f_fsid as c_ulong;
+        //             (*buf).f_flag = kbuf.f_flags as c_ulong;
+        //             (*buf).f_namemax = kbuf.f_namelen as c_ulong;
+        //         }
+        //     }
+        // }
+        // res
+
+        unimplemented!()
+    }
+
+    fn fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int {
+        // e(unsafe { syscall!(FCNTL, fildes, cmd, arg) }) as c_int
+        unimplemented!()
+    }
+
+    fn fork() -> pid_t {
+        // e(unsafe { syscall!(CLONE, SIGCHLD, 0, 0, 0, 0) }) as pid_t
+        e(unsafe { syscall!(SYS_FORK) }) as pid_t
+    }
+
+    fn fpath(fildes: c_int, out: &mut [u8]) -> ssize_t {
+        // let mut proc_path = b"/proc/self/fd/".to_vec();
+        // write!(proc_path, "{}", fildes).unwrap();
+        // proc_path.push(0);
+
+        // Self::readlink(CStr::from_bytes_with_nul(&proc_path).unwrap(), out)
+        unimplemented!()
+    }
+
+    fn fsync(fildes: c_int) -> c_int {
+        // e(unsafe { syscall!(FSYNC, fildes) }) as c_int
+        return 0;
+    }
+
+    fn ftruncate(fildes: c_int, length: off_t) -> c_int {
+        // e(unsafe { syscall!(FTRUNCATE, fildes, length) }) as c_int
+        unimplemented!()
+    }
+
+    fn futex(addr: *mut c_int, op: c_int, val: c_int, val2: usize) -> c_int {
+        // unsafe { syscall!(FUTEX, addr, op, val, val2, 0, 0) as c_int }
+        unimplemented!()
+    }
+
+    fn futimens(fd: c_int, times: *const timespec) -> c_int {
+        // e(unsafe { syscall!(UTIMENSAT, fd, ptr::null::<c_char>(), times, 0) }) as c_int
+        unimplemented!()
+    }
+
+    fn utimens(path: &CStr, times: *const timespec) -> c_int {
+        // e(unsafe { syscall!(UTIMENSAT, AT_FDCWD, path.as_ptr(), times, 0) }) as c_int
+        unimplemented!()
+    }
+
+    fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
+        // if e(unsafe { syscall!(GETCWD, buf, size) }) == !0 {
+        //     ptr::null_mut()
+        // } else {
+        //     buf
+        // }
+        unimplemented!()
+    }
+
+    fn getdents(fd: c_int, dirents: *mut dirent, bytes: usize) -> c_int {
+        unsafe { syscall!(SYS_GET_DENTS, fd, dirents, bytes) as c_int }
+    }
+
+    fn getegid() -> gid_t {
+        // e(unsafe { syscall!(GETEGID) }) as gid_t
+        return 0;
+    }
+
+    fn geteuid() -> uid_t {
+        // e(unsafe { syscall!(GETEUID) }) as uid_t
+        return 0;
+    }
+
+    fn getgid() -> gid_t {
+        // e(unsafe { syscall!(GETGID) }) as gid_t
+        return 0;
+    }
+
+    fn getpagesize() -> usize {
+        // 4096
+        1024 * 1024 * 2
+    }
+
+    fn getpgid(pid: pid_t) -> pid_t {
+        // e(unsafe { syscall!(GETPGID, pid) }) as pid_t
+        return 0;
+    }
+
+    fn getpid() -> pid_t {
+        e(unsafe { syscall!(SYS_GETPID) }) as pid_t
+    }
+
+    fn getppid() -> pid_t {
+        // e(unsafe { syscall!(GETPPID) }) as pid_t
+        return 0;
+    }
+
+    fn getrandom(buf: &mut [u8], flags: c_uint) -> ssize_t {
+        // e(unsafe { syscall!(GETRANDOM, buf.as_mut_ptr(), buf.len(), flags) }) as ssize_t
+        unimplemented!()
+    }
+
+    unsafe fn getrlimit(resource: c_int, rlim: *mut rlimit) -> c_int {
+        // e(syscall!(GETRLIMIT, resource, rlim)) as c_int
+        unimplemented!()
+    }
+
+    fn getsid(pid: pid_t) -> pid_t {
+        // e(unsafe { syscall!(GETSID, pid) }) as pid_t
+        return 0;
+    }
+
+    fn gettid() -> pid_t {
+        // e(unsafe { syscall!(GETTID) }) as pid_t
+        return Self::getpid();
+    }
+
+    fn gettimeofday(tp: *mut timeval, tzp: *mut timezone) -> c_int {
+        // e(unsafe { syscall!(GETTIMEOFDAY, tp, tzp) }) as c_int
+        unimplemented!()
+    }
+
+    fn getuid() -> uid_t {
+        // e(unsafe { syscall!(GETUID) }) as uid_t
+        return 0;
+    }
+
+    fn lchown(path: &CStr, owner: uid_t, group: gid_t) -> c_int {
+        // e(unsafe { syscall!(LCHOWN, path.as_ptr(), owner, group) }) as c_int
+        return 0;
+    }
+
+    fn link(path1: &CStr, path2: &CStr) -> c_int {
+        // e(unsafe {
+        //     syscall!(
+        //         LINKAT,
+        //         AT_FDCWD,
+        //         path1.as_ptr(),
+        //         AT_FDCWD,
+        //         path2.as_ptr(),
+        //         0
+        //     )
+        // }) as c_int
+        unimplemented!()
+    }
+
+    fn lseek(fildes: c_int, offset: off_t, whence: c_int) -> off_t {
+        e(unsafe { syscall!(SYS_LSEEK, fildes, offset, whence) }) as off_t
+    }
+
+    fn mkdir(path: &CStr, mode: mode_t) -> c_int {
+        // e(unsafe { syscall!(MKDIRAT, AT_FDCWD, path.as_ptr(), mode) }) as c_int
+        e(unsafe { syscall!(SYS_MKDIR, path.as_ptr(), mode) }) as c_int
+    }
+
+    fn mkfifo(path: &CStr, mode: mode_t) -> c_int {
+        // e(unsafe { syscall!(MKNODAT, AT_FDCWD, path.as_ptr(), mode | S_IFIFO, 0) }) as c_int
+        unimplemented!()
+    }
+
+    unsafe fn mlock(addr: *const c_void, len: usize) -> c_int {
+        // e(syscall!(MLOCK, addr, len)) as c_int
+        unimplemented!()
+    }
+
+    fn mlockall(flags: c_int) -> c_int {
+        // e(unsafe { syscall!(MLOCKALL, flags) }) as c_int
+        unimplemented!()
+    }
+
+    unsafe fn mmap(
+        addr: *mut c_void,
+        len: usize,
+        prot: c_int,
+        flags: c_int,
+        fildes: c_int,
+        off: off_t,
+    ) -> *mut c_void {
+        // e(syscall!(MMAP, addr, len, prot, flags, fildes, off)) as *mut c_void
+        unimplemented!()
+    }
+
+    unsafe fn mprotect(addr: *mut c_void, len: usize, prot: c_int) -> c_int {
+        // e(syscall!(MPROTECT, addr, len, prot)) as c_int
+        unimplemented!()
+    }
+
+    unsafe fn msync(addr: *mut c_void, len: usize, flags: c_int) -> c_int {
+        // e(syscall!(MSYNC, addr, len, flags)) as c_int
+        unimplemented!()
+    }
+
+    unsafe fn munlock(addr: *const c_void, len: usize) -> c_int {
+        // e(syscall!(MUNLOCK, addr, len)) as c_int
+        unimplemented!()
+    }
+
+    fn munlockall() -> c_int {
+        // e(unsafe { syscall!(MUNLOCKALL) }) as c_int
+        unimplemented!()
+    }
+
+    unsafe fn munmap(addr: *mut c_void, len: usize) -> c_int {
+        // e(syscall!(MUNMAP, addr, len)) as c_int
+        unimplemented!()
+    }
+
+    fn nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int {
+        e(unsafe { syscall!(SYS_NANOSLEEP, rqtp, rmtp) }) as c_int
+    }
+
+    fn open(path: &CStr, oflag: c_int, mode: mode_t) -> c_int {
+        e(unsafe { syscall!(SYS_OPEN, path.as_ptr(), oflag, mode) }) as c_int
+    }
+
+    fn pipe2(fildes: &mut [c_int], flags: c_int) -> c_int {
+        // e(unsafe { syscall!(PIPE2, fildes.as_mut_ptr(), flags) }) as c_int
+        unimplemented!()
+    }
+
+    #[cfg(target_arch = "x86_64")]
+    unsafe fn pte_clone(stack: *mut usize) -> pid_t {
+        unimplemented!()
+        // let flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_THREAD;
+        // let pid;
+        // asm!("
+        //     # Call clone syscall
+        //     syscall
+
+        //     # Check if child or parent
+        //     test rax, rax
+        //     jnz 1f
+
+        //     # Load registers
+        //     pop rax
+        //     pop rdi
+        //     pop rsi
+        //     pop rdx
+        //     pop rcx
+        //     pop r8
+        //     pop r9
+
+        //     # Call entry point
+        //     call rax
+
+        //     # Exit
+        //     mov rax, 60
+        //     xor rdi, rdi
+        //     syscall
+
+        //     # Invalid instruction on failure to exit
+        //     ud2
+
+        //     # Return PID if parent
+        //     1:
+        //     ",
+        //     inout("rax") SYS_CLONE => pid,
+        //     inout("rdi") flags => _,
+        //     inout("rsi") stack => _,
+        //     inout("rdx") 0 => _,
+        //     inout("r10") 0 => _,
+        //     inout("r8") 0 => _,
+        //     //TODO: out("rbx") _,
+        //     out("rcx") _,
+        //     out("r9") _,
+        //     out("r11") _,
+        //     out("r12") _,
+        //     out("r13") _,
+        //     out("r14") _,
+        //     out("r15") _,
+        // );
+        // e(pid) as pid_t
+    }
+
+    fn read(fildes: c_int, buf: &mut [u8]) -> ssize_t {
+        e(unsafe { syscall!(SYS_READ, fildes, buf.as_mut_ptr(), buf.len()) }) as ssize_t
+    }
+
+    fn readlink(pathname: &CStr, out: &mut [u8]) -> ssize_t {
+        unimplemented!()
+        // e(unsafe {
+        //     syscall!(
+        //         READLINKAT,
+        //         AT_FDCWD,
+        //         pathname.as_ptr(),
+        //         out.as_mut_ptr(),
+        //         out.len()
+        //     )
+        // }) as ssize_t
+    }
+
+    fn rename(old: &CStr, new: &CStr) -> c_int {
+        // e(unsafe { syscall!(RENAMEAT, AT_FDCWD, old.as_ptr(), AT_FDCWD, new.as_ptr()) }) as c_int
+        unimplemented!()
+    }
+
+    fn rmdir(path: &CStr) -> c_int {
+        e(unsafe { syscall!(SYS_UNLINK_AT, 0, path.as_ptr(), AT_REMOVEDIR) }) as c_int
+    }
+
+    fn sched_yield() -> c_int {
+        // e(unsafe { syscall!(SCHED_YIELD) }) as c_int
+        unimplemented!()
+    }
+
+    fn setpgid(pid: pid_t, pgid: pid_t) -> c_int {
+        // e(unsafe { syscall!(SETPGID, pid, pgid) }) as c_int
+        unimplemented!()
+    }
+
+    fn setregid(rgid: gid_t, egid: gid_t) -> c_int {
+        // e(unsafe { syscall!(SETREGID, rgid, egid) }) as c_int
+        unimplemented!()
+    }
+
+    fn setreuid(ruid: uid_t, euid: uid_t) -> c_int {
+        // e(unsafe { syscall!(SETREUID, ruid, euid) }) as c_int
+        unimplemented!()
+    }
+
+    fn symlink(path1: &CStr, path2: &CStr) -> c_int {
+        // e(unsafe { syscall!(SYMLINKAT, path1.as_ptr(), AT_FDCWD, path2.as_ptr()) }) as c_int
+        unimplemented!()
+    }
+
+    fn umask(mask: mode_t) -> mode_t {
+        // unsafe { syscall!(UMASK, mask) as mode_t }
+        unimplemented!()
+    }
+
+    fn uname(utsname: *mut utsname) -> c_int {
+        // e(unsafe { syscall!(UNAME, utsname, 0) }) as c_int
+        unimplemented!()
+    }
+
+    fn unlink(path: &CStr) -> c_int {
+        e(unsafe { syscall!(SYS_UNLINK_AT, AT_FDCWD, path.as_ptr(), 0) }) as c_int
+    }
+
+    fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
+        e(unsafe { syscall!(SYS_WAIT4, pid, stat_loc, options, 0) }) as pid_t
+    }
+
+    fn write(fildes: c_int, buf: &[u8]) -> ssize_t {
+        e(unsafe { syscall!(SYS_WRITE, fildes, buf.as_ptr(), buf.len()) }) as ssize_t
+    }
+
+    fn verify() -> bool {
+        // GETPID on Linux is 39, which does not exist on Redox
+        // e(unsafe { dsc::syscall5(dsc::nr::GETPID, !0, !0, !0, !0, !0) }) != !0
+        unimplemented!()
+    }
+}

+ 11 - 0
src/platform/dragonos/ptrace.rs

@@ -0,0 +1,11 @@
+use super::{
+    super::{types::*, PalPtrace},
+    e, Sys,
+};
+
+impl PalPtrace for Sys {
+    fn ptrace(request: c_int, pid: pid_t, addr: *mut c_void, data: *mut c_void) -> c_int {
+        // unsafe { e(syscall!(PTRACE, request, pid, addr, data)) as c_int }
+        unimplemented!()
+    }
+}

+ 63 - 0
src/platform/dragonos/signal.rs

@@ -0,0 +1,63 @@
+use core::mem;
+
+use super::{
+    super::{types::*, PalSignal},
+    e, Sys,
+};
+
+use crate::header::{
+    signal::{sigaction, sigset_t, stack_t},
+    sys_time::itimerval,
+};
+
+impl PalSignal for Sys {
+    fn getitimer(which: c_int, out: *mut itimerval) -> c_int {
+        // e(unsafe { syscall!(GETITIMER, which, out) }) as c_int
+        unimplemented!()
+    }
+
+    fn kill(pid: pid_t, sig: c_int) -> c_int {
+        e(unsafe { syscall!(SYS_KILL, pid, sig) }) as c_int
+    }
+
+    fn killpg(pgrp: pid_t, sig: c_int) -> c_int {
+        e(unsafe { syscall!(SYS_KILL, -(pgrp as isize) as pid_t, sig) }) as c_int
+    }
+
+    fn raise(sig: c_int) -> c_int {
+        let tid = e(unsafe { syscall!(SYS_GETPID) }) as pid_t;
+        if tid == !0 {
+            -1
+        } else {
+            // e(unsafe { syscall!(TKILL, tid, sig) }) as c_int
+            Self::kill(tid, sig)
+        }
+    }
+
+    fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int {
+        // e(unsafe { syscall!(SETITIMER, which, new, old) }) as c_int
+        unimplemented!()
+    }
+
+    fn sigaction(sig: c_int, act: Option<&sigaction>, oact: Option<&mut sigaction>) -> c_int {
+        e(unsafe {
+            syscall!(
+                SYS_SIGACTION,
+                sig,
+                act.map_or_else(core::ptr::null, |x| x as *const _),
+                oact.map_or_else(core::ptr::null_mut, |x| x as *mut _),
+                mem::size_of::<sigset_t>()
+            )
+        }) as c_int
+    }
+
+    fn sigaltstack(ss: *const stack_t, old_ss: *mut stack_t) -> c_int {
+        // e(unsafe { syscall!(SIGALTSTACK, ss, old_ss) }) as c_int
+        unimplemented!()
+    }
+
+    fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int {
+        // e(unsafe { syscall!(RT_SIGPROCMASK, how, set, oset, mem::size_of::<sigset_t>()) }) as c_int
+        unimplemented!()
+    }
+}

+ 135 - 0
src/platform/dragonos/socket.rs

@@ -0,0 +1,135 @@
+use super::{
+    super::{types::*, PalSocket},
+    e, Sys,
+};
+
+use crate::header::sys_socket::{sockaddr, socklen_t};
+
+impl PalSocket for Sys {
+    unsafe fn accept(socket: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int {
+        // e(syscall!(ACCEPT, socket, address, address_len)) as c_int
+        unimplemented!()
+    }
+
+    unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int {
+        // e(syscall!(BIND, socket, address, address_len)) as c_int
+        unimplemented!()
+    }
+
+    unsafe fn connect(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> c_int {
+        // e(syscall!(CONNECT, socket, address, address_len)) as c_int
+        unimplemented!()
+    }
+
+    unsafe fn getpeername(
+        socket: c_int,
+        address: *mut sockaddr,
+        address_len: *mut socklen_t,
+    ) -> c_int {
+        // e(syscall!(GETPEERNAME, socket, address, address_len)) as c_int
+        unimplemented!()
+    }
+
+    unsafe fn getsockname(
+        socket: c_int,
+        address: *mut sockaddr,
+        address_len: *mut socklen_t,
+    ) -> c_int {
+        // e(syscall!(GETSOCKNAME, socket, address, address_len)) as c_int
+        unimplemented!()
+    }
+
+    fn getsockopt(
+        socket: c_int,
+        level: c_int,
+        option_name: c_int,
+        option_value: *mut c_void,
+        option_len: *mut socklen_t,
+    ) -> c_int {
+        unimplemented!()
+        // e(unsafe {
+        //     syscall!(
+        //         GETSOCKOPT,
+        //         socket,
+        //         level,
+        //         option_name,
+        //         option_value,
+        //         option_len
+        //     )
+        // }) as c_int
+    }
+
+    fn listen(socket: c_int, backlog: c_int) -> c_int {
+        // e(unsafe { syscall!(LISTEN, socket, backlog) }) as c_int
+        unimplemented!()
+    }
+
+    unsafe fn recvfrom(
+        socket: c_int,
+        buf: *mut c_void,
+        len: size_t,
+        flags: c_int,
+        address: *mut sockaddr,
+        address_len: *mut socklen_t,
+    ) -> ssize_t {
+        // e(syscall!(
+        //     RECVFROM,
+        //     socket,
+        //     buf,
+        //     len,
+        //     flags,
+        //     address,
+        //     address_len
+        // )) as ssize_t
+        unimplemented!()
+    }
+
+    unsafe fn sendto(
+        socket: c_int,
+        buf: *const c_void,
+        len: size_t,
+        flags: c_int,
+        dest_addr: *const sockaddr,
+        dest_len: socklen_t,
+    ) -> ssize_t {
+        // e(syscall!(
+        //     SENDTO, socket, buf, len, flags, dest_addr, dest_len
+        // )) as ssize_t
+        unimplemented!()
+    }
+
+    fn setsockopt(
+        socket: c_int,
+        level: c_int,
+        option_name: c_int,
+        option_value: *const c_void,
+        option_len: socklen_t,
+    ) -> c_int {
+        // e(unsafe {
+        //     syscall!(
+        //         SETSOCKOPT,
+        //         socket,
+        //         level,
+        //         option_name,
+        //         option_value,
+        //         option_len
+        //     )
+        // }) as c_int
+        unimplemented!()
+    }
+
+    fn shutdown(socket: c_int, how: c_int) -> c_int {
+        // e(unsafe { syscall!(SHUTDOWN, socket, how) }) as c_int
+        unimplemented!()
+    }
+
+    unsafe fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {
+        // e(syscall!(SOCKET, domain, kind, protocol)) as c_int
+        unimplemented!()
+    }
+
+    fn socketpair(domain: c_int, kind: c_int, protocol: c_int, sv: &mut [c_int; 2]) -> c_int {
+        // e(unsafe { syscall!(SOCKETPAIR, domain, kind, protocol, sv.as_mut_ptr()) }) as c_int
+        unimplemented!()
+    }
+}

+ 7 - 0
src/platform/mod.rs

@@ -22,6 +22,10 @@ pub use self::sys::{e, Sys};
 #[path = "linux/mod.rs"]
 pub(crate) mod sys;
 
+#[cfg(all(not(feature = "no_std"), target_os = "dragonos"))]
+#[path = "dragonos/mod.rs"]
+pub(crate) mod sys;
+
 #[cfg(all(not(feature = "no_std"), target_os = "redox"))]
 #[path = "redox/mod.rs"]
 pub(crate) mod sys;
@@ -37,6 +41,9 @@ pub mod rlb;
 #[cfg(target_os = "linux")]
 pub mod auxv_defs;
 
+#[cfg(target_os = "dragonos")]
+pub mod auxv_defs;
+
 #[cfg(target_os = "redox")]
 pub use redox_exec::auxv_defs;