Skip to content

Commit f74d134

Browse files
committed
Auto merge of rust-lang#591 - humenda:master, r=alexcrichton
Add experimental L4re support This PR introduces a UNIX-alike target for the l4re microkernel operating system. While this system is not a UNIX system at all, it is easiest to use the POSIX interface and hence benefit from common definitions. This version is a very early draft, only the basic data types have been verified and most of the complex data types (structs and unions) have not been ported yet. Thanks to TobiasSchaffner for providing his patched version, to verify some assumptions.
2 parents 80e1422 + 09a04d8 commit f74d134

File tree

2 files changed

+313
-1
lines changed

2 files changed

+313
-1
lines changed

Diff for: src/unix/uclibc/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub type id_t = ::c_uint;
1111
pub type useconds_t = u32;
1212
pub type dev_t = u64;
1313
pub type socklen_t = u32;
14-
pub type pthread_t = c_ulong;
14+
pub type pthread_t = ::c_ulong;
1515
pub type mode_t = u32;
1616
pub type ino64_t = u64;
1717
pub type off64_t = i64;

Diff for: src/unix/uclibc/x86_64/mod.rs

+312
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
1+
//! Definitions for l4re-uclibc on 64bit systems
2+
3+
pub type blkcnt_t = i64;
4+
pub type blksize_t = i64;
5+
pub type c_char = u8;
6+
pub type c_long = i64;
7+
pub type c_ulong = u64;
8+
pub type fsblkcnt_t = ::c_ulong;
9+
pub type fsfilcnt_t = ::c_ulong;
10+
pub type fsword_t = ::c_long;
11+
pub type ino_t = ::c_ulong;
12+
pub type nlink_t = ::c_uint;
13+
pub type off_t = ::c_long;
14+
pub type rlim_t = c_ulong;
15+
pub type rlim64_t = u64;
16+
pub type suseconds_t = ::c_long;
17+
pub type time_t = ::c_int;
18+
pub type wchar_t = ::c_int;
19+
20+
// ToDo, used?
21+
//pub type d_ino = ::c_ulong;
22+
pub type nfds_t = ::c_ulong;
23+
24+
s! {
25+
// ------------------------------------------------------------
26+
// networking
27+
pub struct in_addr {
28+
pub s_addr: in_addr_t,
29+
}
30+
31+
pub struct in6_addr {
32+
pub s6_addr: [u8; 16],
33+
__align: [u32; 0],
34+
}
35+
36+
pub struct sockaddr {
37+
pub sa_family: sa_family_t,
38+
pub sa_data: [::c_char; 14],
39+
}
40+
41+
pub struct sockaddr_in {
42+
pub sin_family: sa_family_t,
43+
pub sin_port: ::in_port_t,
44+
pub sin_addr: ::in_addr,
45+
pub sin_zero: [u8; 8],
46+
}
47+
48+
pub struct sockaddr_in6 {
49+
pub sin6_family: sa_family_t,
50+
pub sin6_port: in_port_t,
51+
pub sin6_flowinfo: u32,
52+
pub sin6_addr: ::in6_addr,
53+
pub sin6_scope_id: u32,
54+
}
55+
56+
// ------------------------------------------------------------
57+
// definitions below are *unverified* and might **break** the software
58+
pub struct stat { // ToDo
59+
pub st_dev: ::c_ulong,
60+
st_pad1: [::c_long; 2],
61+
pub st_ino: ::ino_t,
62+
pub st_mode: ::mode_t,
63+
pub st_nlink: ::nlink_t,
64+
pub st_uid: ::uid_t,
65+
pub st_gid: ::gid_t,
66+
pub st_rdev: u64,
67+
pub st_pad2: [u64; 1],
68+
pub st_size: off_t,
69+
st_pad3: ::c_long,
70+
pub st_atime: ::time_t,
71+
pub st_atime_nsec: ::c_long,
72+
pub st_mtime: ::time_t,
73+
pub st_mtime_nsec: ::c_long,
74+
pub st_ctime: ::time_t,
75+
pub st_ctime_nsec: ::c_long,
76+
pub st_blksize: ::blksize_t,
77+
st_pad4: ::c_long,
78+
pub st_blocks: ::blkcnt_t,
79+
st_pad5: [::c_long; 7],
80+
}
81+
82+
pub struct statvfs { // ToDo: broken
83+
pub f_bsize: ::c_ulong,
84+
pub f_frsize: ::c_ulong,
85+
pub f_blocks: ::fsblkcnt_t,
86+
pub f_bfree: ::fsblkcnt_t,
87+
pub f_bavail: ::fsblkcnt_t,
88+
pub f_files: ::fsfilcnt_t,
89+
pub f_ffree: ::fsfilcnt_t,
90+
pub f_favail: ::fsfilcnt_t,
91+
#[cfg(target_endian = "little")]
92+
pub f_fsid: ::c_ulong,
93+
#[cfg(target_pointer_width = "32")]
94+
__f_unused: ::c_int,
95+
#[cfg(target_endian = "big")]
96+
pub f_fsid: ::c_ulong,
97+
pub f_flag: ::c_ulong,
98+
pub f_namemax: ::c_ulong,
99+
__f_spare: [::c_int; 6],
100+
}
101+
102+
pub struct dirent { // Todo
103+
pub d_ino: ino_64_t,
104+
pub d_off: off64_t,
105+
d_reclen: u16,
106+
pub d_type: u8,
107+
pub d_name: [i8; 256],
108+
}
109+
110+
pub struct dirent64 { //
111+
pub d_ino: ino64_t,
112+
pub d_off: off64_t,
113+
pub d_reclen: u16,
114+
pub d_type: u8,
115+
pub d_name: [i8; 256],
116+
}
117+
118+
pub struct pthread_attr_t { // ToDo
119+
__size: [u64; 7]
120+
}
121+
122+
pub struct sigaction { // TODO!!
123+
pub sa_sigaction: ::sighandler_t,
124+
pub sa_mask: ::sigset_t,
125+
#[cfg(target_arch = "sparc64")]
126+
__reserved0: ::c_int,
127+
pub sa_flags: ::c_int,
128+
_restorer: *mut ::c_void,
129+
}
130+
131+
pub struct stack_t { // ToDo
132+
pub ss_sp: *mut ::c_void,
133+
pub ss_flags: ::c_int,
134+
pub ss_size: ::size_t
135+
}
136+
137+
pub struct statfs { // ToDo
138+
pub f_type: fsword_t,
139+
pub f_bsize: fsword_t,
140+
pub f_blocks: ::fsblkcnt_t,
141+
pub f_bfree: ::fsblkcnt_t,
142+
pub f_bavail: ::fsblkcnt_t,
143+
pub f_files: ::fsfilcnt_t,
144+
pub f_ffree: ::fsfilcnt_t,
145+
pub f_fsid: ::fsid_t,
146+
pub f_namelen: fsword_t,
147+
pub f_frsize: fsword_t,
148+
f_spare: [fsword_t; 5],
149+
}
150+
151+
pub struct msghdr { // ToDo
152+
pub msg_name: *mut ::c_void,
153+
pub msg_namelen: ::socklen_t,
154+
pub msg_iov: *mut ::iovec,
155+
pub msg_iovlen: ::size_t,
156+
pub msg_control: *mut ::c_void,
157+
pub msg_controllen: ::size_t,
158+
pub msg_flags: ::c_int,
159+
}
160+
161+
pub struct termios { // ToDo
162+
pub c_iflag: ::tcflag_t,
163+
pub c_oflag: ::tcflag_t,
164+
pub c_cflag: ::tcflag_t,
165+
pub c_lflag: ::tcflag_t,
166+
pub c_line: ::cc_t,
167+
pub c_cc: [::cc_t; ::NCCS],
168+
}
169+
170+
pub struct sem_t { // ToDo
171+
#[cfg(target_pointer_width = "32")]
172+
__size: [::c_char; 16],
173+
#[cfg(target_pointer_width = "64")]
174+
__size: [::c_char; 32],
175+
__align: [::c_long; 0],
176+
}
177+
178+
pub struct pthread_mutex_t { // ToDo
179+
#[cfg(any(target_arch = "mips", target_arch = "arm",
180+
target_arch = "powerpc"))]
181+
__align: [::c_long; 0],
182+
#[cfg(not(any(target_arch = "mips", target_arch = "arm",
183+
target_arch = "powerpc")))]
184+
__align: [::c_longlong; 0],
185+
size: [u8; __SIZEOF_PTHREAD_MUTEX_T],
186+
}
187+
188+
pub struct pthread_mutexattr_t { // ToDo
189+
#[cfg(any(target_arch = "x86_64", target_arch = "powerpc64",
190+
target_arch = "mips64", target_arch = "s390x",
191+
target_arch = "sparc64"))]
192+
__align: [::c_int; 0],
193+
#[cfg(not(any(target_arch = "x86_64", target_arch = "powerpc64",
194+
target_arch = "mips64", target_arch = "s390x",
195+
target_arch = "sparc64")))]
196+
__align: [::c_long; 0],
197+
size: [u8; __SIZEOF_PTHREAD_MUTEXATTR_T],
198+
}
199+
200+
pub struct pthread_cond_t { // ToDo
201+
__align: [::c_longlong; 0],
202+
size: [u8; __SIZEOF_PTHREAD_COND_T],
203+
}
204+
205+
pub struct pthread_condattr_t { // ToDo
206+
__align: [::c_int; 0],
207+
size: [u8; __SIZEOF_PTHREAD_CONDATTR_T],
208+
}
209+
210+
pub struct pthread_rwlock_t { // ToDo
211+
#[cfg(any(target_arch = "mips", target_arch = "arm",
212+
target_arch = "powerpc"))]
213+
__align: [::c_long; 0],
214+
#[cfg(not(any(target_arch = "mips", target_arch = "arm",
215+
target_arch = "powerpc")))]
216+
__align: [::c_longlong; 0],
217+
size: [u8; __SIZEOF_PTHREAD_RWLOCK_T],
218+
}
219+
220+
pub struct sigset_t { // ToDo
221+
__val: [::c_ulong; 16],
222+
}
223+
224+
pub struct sysinfo { // ToDo
225+
pub uptime: ::c_long,
226+
pub loads: [::c_ulong; 3],
227+
pub totalram: ::c_ulong,
228+
pub freeram: ::c_ulong,
229+
pub sharedram: ::c_ulong,
230+
pub bufferram: ::c_ulong,
231+
pub totalswap: ::c_ulong,
232+
pub freeswap: ::c_ulong,
233+
pub procs: ::c_ushort,
234+
pub pad: ::c_ushort,
235+
pub totalhigh: ::c_ulong,
236+
pub freehigh: ::c_ulong,
237+
pub mem_unit: ::c_uint,
238+
pub _f: [::c_char; 0],
239+
}
240+
241+
pub struct glob_t { // ToDo
242+
pub gl_pathc: ::size_t,
243+
pub gl_pathv: *mut *mut c_char,
244+
pub gl_offs: ::size_t,
245+
pub gl_flags: ::c_int,
246+
__unused1: *mut ::c_void,
247+
__unused2: *mut ::c_void,
248+
__unused3: *mut ::c_void,
249+
__unused4: *mut ::c_void,
250+
__unused5: *mut ::c_void,
251+
}
252+
253+
pub struct stat64 { // ToDo
254+
pub st_dev: ::dev_t,
255+
pub st_ino: ::ino64_t,
256+
pub st_nlink: ::nlink_t,
257+
pub st_mode: ::mode_t,
258+
pub st_uid: ::uid_t,
259+
pub st_gid: ::gid_t,
260+
__pad0: ::c_int,
261+
pub st_rdev: ::dev_t,
262+
pub st_size: ::off_t,
263+
pub st_blksize: ::blksize_t,
264+
pub st_blocks: ::blkcnt64_t,
265+
pub st_atime: ::time_t,
266+
pub st_atime_nsec: ::c_long,
267+
pub st_mtime: ::time_t,
268+
pub st_mtime_nsec: ::c_long,
269+
pub st_ctime: ::time_t,
270+
pub st_ctime_nsec: ::c_long,
271+
__reserved: [::c_long; 3],
272+
}
273+
274+
pub struct rlimit64 { // ToDo
275+
pub rlim_cur: rlim64_t,
276+
pub rlim_max: rlim64_t,
277+
}
278+
279+
pub struct cpu_set_t { // ToDo
280+
#[cfg(target_pointer_width = "32")]
281+
bits: [u32; 32],
282+
#[cfg(target_pointer_width = "64")]
283+
bits: [u64; 16],
284+
}
285+
286+
pub struct timespec { // ToDo
287+
tv_sec: time_t, // seconds
288+
tv_nsec: ::c_ulong, // nanoseconds
289+
}
290+
291+
pub struct fsid_t { // ToDo
292+
__val: [::c_int; 2],
293+
}
294+
}
295+
296+
// constants
297+
pub const O_CLOEXEC: ::c_int = 0x80000;
298+
pub const O_DIRECTORY: ::c_int = 0200000;
299+
pub const NCCS: usize = 32;
300+
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
301+
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
302+
pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0;
303+
pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
304+
pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2;
305+
pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL;
306+
pub const __SIZEOF_PTHREAD_COND_T: usize = 48;
307+
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
308+
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
309+
310+
extern {
311+
pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void;
312+
}

0 commit comments

Comments
 (0)