Skip to content

Commit a1f23f0

Browse files
committed
Add port for RTEMS
1 parent 72c4000 commit a1f23f0

File tree

3 files changed

+162
-1
lines changed

3 files changed

+162
-1
lines changed

build.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
2323

2424
// Extra values to allow for check-cfg.
2525
const CHECK_CFG_EXTRA: &'static [(&'static str, &'static [&'static str])] = &[
26-
("target_os", &["switch", "aix", "ohos", "hurd", "visionos"]),
26+
(
27+
"target_os",
28+
&["switch", "aix", "ohos", "hurd", "rtems", "visionos"]
29+
),
2730
("target_env", &["illumos", "wasi", "aix", "ohos"]),
2831
(
2932
"target_arch",

src/unix/newlib/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,16 @@ cfg_if! {
258258
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 4;
259259
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 4;
260260
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 4;
261+
} else if #[cfg(target_os = "rtems")] {
262+
const __PTHREAD_INITIALIZER_BYTE: u8 = 0x00;
263+
pub const __SIZEOF_PTHREAD_ATTR_T: usize = 96;
264+
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 64;
265+
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 24;
266+
pub const __SIZEOF_PTHREAD_COND_T: usize = 28;
267+
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 24;
268+
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
269+
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
270+
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
261271
} else {
262272
const __PTHREAD_INITIALIZER_BYTE: u8 = 0;
263273
pub const __SIZEOF_PTHREAD_ATTR_T: usize = 56;
@@ -767,6 +777,13 @@ cfg_if! {
767777
}
768778
}
769779

780+
cfg_if! {
781+
if #[cfg(target_os = "rtems")] {
782+
mod rtems;
783+
pub use self::rtems::*;
784+
}
785+
}
786+
770787
#[macro_use]
771788
mod align;
772789
expand_align!();

src/unix/newlib/rtems/mod.rs

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// defined in architecture specific module
2+
use c_long;
3+
4+
s! {
5+
pub struct sockaddr_un {
6+
pub sun_family: ::sa_family_t,
7+
pub sun_path: [::c_char; 108usize],
8+
}
9+
}
10+
11+
pub const AF_UNIX: ::c_int = 1;
12+
13+
pub const RTLD_DEFAULT: *mut ::c_void = -2isize as *mut ::c_void;
14+
15+
pub const UTIME_OMIT: c_long = -1;
16+
pub const AT_FDCWD: ::c_int = -2;
17+
18+
pub const O_DIRECTORY: ::c_int = 0x200000;
19+
pub const O_NOFOLLOW: ::c_int = 0x100000;
20+
21+
pub const AT_EACCESS: ::c_int = 1;
22+
pub const AT_SYMLINK_NOFOLLOW: ::c_int = 2;
23+
pub const AT_SYMLINK_FOLLOW: ::c_int = 4;
24+
pub const AT_REMOVEDIR: ::c_int = 8;
25+
26+
// signal.h
27+
pub const SIG_BLOCK: ::c_int = 1;
28+
pub const SIG_UNBLOCK: ::c_int = 2;
29+
pub const SIG_SETMASK: ::c_int = 0;
30+
pub const SIGHUP: ::c_int = 1;
31+
pub const SIGINT: ::c_int = 2;
32+
pub const SIGQUIT: ::c_int = 3;
33+
pub const SIGILL: ::c_int = 4;
34+
pub const SIGTRAP: ::c_int = 5;
35+
pub const SIGABRT: ::c_int = 6;
36+
pub const SIGEMT: ::c_int = 7;
37+
pub const SIGFPE: ::c_int = 8;
38+
pub const SIGKILL: ::c_int = 9;
39+
pub const SIGBUS: ::c_int = 10;
40+
pub const SIGSEGV: ::c_int = 11;
41+
pub const SIGSYS: ::c_int = 12;
42+
pub const SIGPIPE: ::c_int = 13;
43+
pub const SIGALRM: ::c_int = 14;
44+
pub const SIGTERM: ::c_int = 15;
45+
pub const SIGURG: ::c_int = 16;
46+
pub const SIGSTOP: ::c_int = 17;
47+
pub const SIGTSTP: ::c_int = 18;
48+
pub const SIGCONT: ::c_int = 19;
49+
pub const SIGCHLD: ::c_int = 20;
50+
pub const SIGCLD: ::c_int = 20;
51+
pub const SIGTTIN: ::c_int = 21;
52+
pub const SIGTTOU: ::c_int = 22;
53+
pub const SIGIO: ::c_int = 23;
54+
pub const SIGWINCH: ::c_int = 24;
55+
pub const SIGUSR1: ::c_int = 25;
56+
pub const SIGUSR2: ::c_int = 26;
57+
pub const SIGRTMIN: ::c_int = 27;
58+
pub const SIGRTMAX: ::c_int = 31;
59+
pub const SIGXCPU: ::c_int = 24;
60+
pub const SIGXFSZ: ::c_int = 25;
61+
pub const SIGVTALRM: ::c_int = 26;
62+
pub const SIGPROF: ::c_int = 27;
63+
64+
pub const SA_NOCLDSTOP: ::c_ulong = 0x00000001;
65+
pub const SA_SIGINFO: ::c_ulong = 0x00000002;
66+
pub const SA_ONSTACK: ::c_ulong = 0x00000004;
67+
68+
pub const EAI_AGAIN: ::c_int = 2;
69+
pub const EAI_BADFLAGS: ::c_int = 3;
70+
pub const EAI_FAIL: ::c_int = 4;
71+
pub const EAI_SERVICE: ::c_int = 9;
72+
pub const EAI_SYSTEM: ::c_int = 11;
73+
pub const EAI_OVERFLOW: ::c_int = 14;
74+
75+
pub const _SC_PAGESIZE: ::c_int = 8;
76+
pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 51;
77+
pub const PTHREAD_STACK_MIN: ::size_t = 0;
78+
79+
// sys/wait.h
80+
pub const WNOHANG: ::c_int = 1;
81+
pub const WUNTRACED: ::c_int = 2;
82+
83+
// sys/socket.h
84+
pub const SOMAXCONN: ::c_int = 128;
85+
86+
safe_f! {
87+
pub {const} fn WIFSTOPPED(status: ::c_int) -> bool {
88+
(status & 0xff) == 0x7f
89+
}
90+
91+
pub {const} fn WSTOPSIG(status: ::c_int) -> ::c_int {
92+
// (status >> 8) & 0xff
93+
WEXITSTATUS(status)
94+
}
95+
96+
pub {const} fn WIFSIGNALED(status: ::c_int) -> bool {
97+
((status & 0x7f) > 0) && ((status & 0x7f) < 0x7f)
98+
}
99+
100+
pub {const} fn WTERMSIG(status: ::c_int) -> ::c_int {
101+
status & 0x7f
102+
}
103+
104+
pub {const} fn WIFEXITED(status: ::c_int) -> bool {
105+
(status & 0xff) == 0
106+
}
107+
108+
pub {const} fn WEXITSTATUS(status: ::c_int) -> ::c_int {
109+
(status >> 8) & 0xff
110+
}
111+
112+
// RTEMS doesn't have native WIFCONTINUED.
113+
pub {const} fn WIFCONTINUED(_status: ::c_int) -> bool {
114+
true
115+
}
116+
117+
// RTEMS doesn't have native WCOREDUMP.
118+
pub {const} fn WCOREDUMP(_status: ::c_int) -> bool {
119+
false
120+
}
121+
}
122+
123+
extern "C" {
124+
pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int;
125+
pub fn writev(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t;
126+
pub fn readv(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t;
127+
128+
pub fn pthread_create(
129+
native: *mut ::pthread_t,
130+
attr: *const ::pthread_attr_t,
131+
f: extern "C" fn(_: *mut ::c_void) -> *mut ::c_void,
132+
value: *mut ::c_void,
133+
) -> ::c_int;
134+
135+
pub fn pthread_condattr_setclock(
136+
attr: *mut ::pthread_condattr_t,
137+
clock_id: ::clockid_t,
138+
) -> ::c_int;
139+
140+
pub fn setgroups(ngroups: ::c_int, grouplist: *const ::gid_t) -> ::c_int;
141+
}

0 commit comments

Comments
 (0)