Skip to content

Commit 60e5745

Browse files
committed
Auto merge of #734 - humenda:l4re-improvements, r=alexcrichton
L4Re improvements This commit improves the x86_64 uClibc port and splits of L4Re-specific structs into a separate submodule. It defines additional constants and fixes some unfinished structs.
2 parents fc28288 + cc58834 commit 60e5745

File tree

3 files changed

+126
-90
lines changed

3 files changed

+126
-90
lines changed

src/unix/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ pub const INADDR_NONE: in_addr_t = 4294967295;
232232
cfg_if! {
233233
if #[cfg(dox)] {
234234
// on dox builds don't pull in anything
235+
} else if #[cfg(target_os = "l4re")] {
236+
// required libraries for L4Re are linked externally, ATM
235237
} else if #[cfg(all(not(stdbuild), feature = "use_std"))] {
236238
// cargo build, don't pull in anything extra as the libstd dep
237239
// already pulls in all libs.

src/unix/uclibc/x86_64/l4re.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/// L4Re specifics
2+
/// This module contains definitions required by various L4Re libc backends.
3+
/// Some of them are formally not part of the libc, but are a dependency of the
4+
/// libc and hence we should provide them here.
5+
6+
pub type l4_umword_t = ::c_ulong; // Unsigned machine word.
7+
8+
s! {
9+
/// CPU sets.
10+
pub struct l4_sched_cpu_set_t {
11+
// from the L4Re docs
12+
/// Combination of granularity and offset.
13+
///
14+
/// The granularity defines how many CPUs each bit in map describes.
15+
/// The offset is the numer of the first CPU described by the first
16+
/// bit in the bitmap.
17+
/// offset must be a multiple of 2^graularity.
18+
///
19+
/// | MSB | LSB |
20+
/// | ---------------- | ------------------- |
21+
/// | 8bit granularity | 24bit offset .. |
22+
gran_offset: l4_umword_t ,
23+
/// Bitmap of CPUs.
24+
map: l4_umword_t ,
25+
}
26+
}
27+
28+
#[cfg(target_os = "l4re")]
29+
pub struct pthread_attr_t {
30+
pub __detachstate: ::c_int,
31+
pub __schedpolicy: ::c_int,
32+
pub __schedparam: super::__sched_param,
33+
pub __inheritsched: ::c_int,
34+
pub __scope: ::c_int,
35+
pub __guardsize: ::size_t,
36+
pub __stackaddr_set: ::c_int,
37+
pub __stackaddr: *mut ::c_void, // better don't use it
38+
pub __stacksize: ::size_t,
39+
// L4Re specifics
40+
pub affinity: l4_sched_cpu_set_t,
41+
pub create_flags: ::c_uint,
42+
}
43+
44+
// L4Re requires a min stack size of 64k; that isn't defined in uClibc, but
45+
// somewhere in the core libraries. uClibc wants 16k, but that's not enough.
46+
pub const PTHREAD_STACK_MIN: usize = 65536;

src/unix/uclibc/x86_64/mod.rs

Lines changed: 78 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//! Definitions for l4re-uclibc on 64bit systems
2-
1+
//! Definitions for uclibc on 64bit systems
2+
//!
33
pub type blkcnt_t = i64;
44
pub type blksize_t = i64;
55
pub type clock_t = i64;
@@ -14,15 +14,31 @@ pub type nlink_t = ::c_uint;
1414
pub type off_t = ::c_long;
1515
pub type rlim_t = c_ulong;
1616
pub type rlim64_t = u64;
17+
// [uClibc docs] Note stat64 has the same shape as stat for x86-64.
18+
pub type stat64 = stat;
1719
pub type suseconds_t = ::c_long;
1820
pub type time_t = ::c_int;
1921
pub type wchar_t = ::c_int;
2022

21-
// ToDo, used?
22-
//pub type d_ino = ::c_ulong;
2323
pub type nfds_t = ::c_ulong;
2424

2525
s! {
26+
pub struct dirent {
27+
pub d_ino: ::ino64_t,
28+
pub d_off: ::off64_t,
29+
pub d_reclen: u16,
30+
pub d_type: u8,
31+
pub d_name: [::c_char; 256],
32+
}
33+
34+
pub struct dirent64 {
35+
pub d_ino: ::ino64_t,
36+
pub d_off: ::off64_t,
37+
pub d_reclen: u16,
38+
pub d_type: u8,
39+
pub d_name: [::c_char; 256],
40+
}
41+
2642
pub struct ipc_perm {
2743
pub __key: ::key_t,
2844
pub uid: ::uid_t,
@@ -37,6 +53,23 @@ s! {
3753
__unused2: ::c_ulong
3854
}
3955

56+
#[cfg(not(target_os = "l4re"))]
57+
pub struct pthread_attr_t {
58+
__detachstate: ::c_int,
59+
__schedpolicy: ::c_int,
60+
__schedparam: __sched_param,
61+
__inheritsched: ::c_int,
62+
__scope: ::c_int,
63+
__guardsize: ::size_t,
64+
__stackaddr_set: ::c_int,
65+
__stackaddr: *mut ::c_void, // better don't use it
66+
__stacksize: ::size_t,
67+
}
68+
69+
pub struct __sched_param {
70+
__sched_priority: ::c_int,
71+
}
72+
4073
pub struct siginfo_t {
4174
si_signo: ::c_int, // signal number
4275
si_errno: ::c_int, // if not zero: error value of signal, see errno.h
@@ -103,77 +136,33 @@ s! {
103136
// __align: [u32; 0],
104137
// }
105138

106-
pub struct stat { // ToDo
139+
pub struct stat {
107140
pub st_dev: ::c_ulong,
108-
st_pad1: [::c_long; 2],
109141
pub st_ino: ::ino_t,
110-
pub st_mode: ::mode_t,
142+
// According to uclibc/libc/sysdeps/linux/x86_64/bits/stat.h, order of
143+
// nlink and mode are swapped on 64 bit systems.
111144
pub st_nlink: ::nlink_t,
145+
pub st_mode: ::mode_t,
112146
pub st_uid: ::uid_t,
113147
pub st_gid: ::gid_t,
114-
pub st_rdev: u64,
115-
pub st_pad2: [u64; 1],
116-
pub st_size: off_t,
117-
st_pad3: ::c_long,
148+
pub st_rdev: ::c_ulong, // dev_t
149+
pub st_size: off_t, // file size
150+
pub st_blksize: ::blksize_t,
151+
pub st_blocks: ::blkcnt_t,
118152
pub st_atime: ::time_t,
119-
pub st_atime_nsec: ::c_long,
153+
pub st_atime_nsec: ::c_ulong,
120154
pub st_mtime: ::time_t,
121-
pub st_mtime_nsec: ::c_long,
155+
pub st_mtime_nsec: ::c_ulong,
122156
pub st_ctime: ::time_t,
123-
pub st_ctime_nsec: ::c_long,
124-
pub st_blksize: ::blksize_t,
125-
st_pad4: ::c_long,
126-
pub st_blocks: ::blkcnt_t,
127-
st_pad5: [::c_long; 7],
157+
pub st_ctime_nsec: ::c_ulong,
158+
st_pad4: [::c_long; 3]
128159
}
129160

130-
pub struct statvfs { // ToDo: broken
131-
pub f_bsize: ::c_ulong,
132-
pub f_frsize: ::c_ulong,
133-
pub f_blocks: ::fsblkcnt_t,
134-
pub f_bfree: ::fsblkcnt_t,
135-
pub f_bavail: ::fsblkcnt_t,
136-
pub f_files: ::fsfilcnt_t,
137-
pub f_ffree: ::fsfilcnt_t,
138-
pub f_favail: ::fsfilcnt_t,
139-
#[cfg(target_endian = "little")]
140-
pub f_fsid: ::c_ulong,
141-
#[cfg(target_pointer_width = "32")]
142-
__f_unused: ::c_int,
143-
#[cfg(target_endian = "big")]
144-
pub f_fsid: ::c_ulong,
145-
pub f_flag: ::c_ulong,
146-
pub f_namemax: ::c_ulong,
147-
__f_spare: [::c_int; 6],
148-
}
149-
150-
pub struct dirent { // Todo
151-
pub d_ino: ::ino64_t,
152-
pub d_off: ::off64_t,
153-
d_reclen: u16,
154-
pub d_type: u8,
155-
pub d_name: [i8; 256],
156-
}
157-
158-
pub struct dirent64 { //
159-
pub d_ino: ::ino64_t,
160-
pub d_off: ::off64_t,
161-
pub d_reclen: u16,
162-
pub d_type: u8,
163-
pub d_name: [i8; 256],
164-
}
165-
166-
pub struct pthread_attr_t { // ToDo
167-
__size: [u64; 7]
168-
}
169-
170-
pub struct sigaction { // TODO!!
171-
pub sa_sigaction: ::sighandler_t,
161+
pub struct sigaction {
162+
pub sa_handler: ::sighandler_t,
163+
pub sa_flags: ::c_ulong,
164+
pub sa_restorer: *mut ::c_void,
172165
pub sa_mask: ::sigset_t,
173-
#[cfg(target_arch = "sparc64")]
174-
__reserved0: ::c_int,
175-
pub sa_flags: ::c_int,
176-
_restorer: *mut ::c_void,
177166
}
178167

179168
pub struct stack_t { // ToDo
@@ -298,27 +287,6 @@ s! {
298287
__unused5: *mut ::c_void,
299288
}
300289

301-
pub struct stat64 { // ToDo
302-
pub st_dev: ::dev_t,
303-
pub st_ino: ::ino64_t,
304-
pub st_nlink: ::nlink_t,
305-
pub st_mode: ::mode_t,
306-
pub st_uid: ::uid_t,
307-
pub st_gid: ::gid_t,
308-
__pad0: ::c_int,
309-
pub st_rdev: ::dev_t,
310-
pub st_size: ::off_t,
311-
pub st_blksize: ::blksize_t,
312-
pub st_blocks: ::blkcnt64_t,
313-
pub st_atime: ::time_t,
314-
pub st_atime_nsec: ::c_long,
315-
pub st_mtime: ::time_t,
316-
pub st_mtime_nsec: ::c_long,
317-
pub st_ctime: ::time_t,
318-
pub st_ctime_nsec: ::c_long,
319-
__reserved: [::c_long; 3],
320-
}
321-
322290
pub struct rlimit64 { // ToDo
323291
pub rlim_cur: rlim64_t,
324292
pub rlim_max: rlim64_t,
@@ -331,20 +299,32 @@ s! {
331299
bits: [u64; 16],
332300
}
333301

334-
pub struct timespec { // ToDo
335-
tv_sec: time_t, // seconds
336-
tv_nsec: ::c_ulong, // nanoseconds
337-
}
338-
339302
pub struct fsid_t { // ToDo
340303
__val: [::c_int; 2],
341304
}
342305
}
343306

344307
// constants
308+
pub const EADDRINUSE: ::c_int = 98; // Address already in use
309+
pub const EADDRNOTAVAIL: ::c_int = 99; // Cannot assign requested address
310+
pub const ECONNABORTED: ::c_int = 103; // Software caused connection abort
311+
pub const ECONNREFUSED: ::c_int = 111; // Connection refused
312+
pub const ECONNRESET: ::c_int = 104; // Connection reset by peer
313+
pub const EDEADLK: ::c_int = 35; // Resource deadlock would occur
314+
pub const ENOSYS: ::c_int = 38; // Function not implemented
315+
pub const ENOTCONN: ::c_int = 107; // Transport endpoint is not connected
316+
pub const ETIMEDOUT: ::c_int = 110; // connection timed out
317+
pub const O_APPEND: ::c_int = 02000;
318+
pub const O_ACCMODE: ::c_int = 0003;
345319
pub const O_CLOEXEC: ::c_int = 0x80000;
320+
pub const O_CREAT: ::c_int = 0100;
346321
pub const O_DIRECTORY: ::c_int = 0200000;
322+
pub const O_EXCL: ::c_int = 0200;
323+
pub const O_NONBLOCK: ::c_int = 04000;
324+
pub const O_TRUNC: ::c_int = 01000;
347325
pub const NCCS: usize = 32;
326+
pub const SIG_SETMASK: ::c_int = 2; // Set the set of blocked signals
327+
pub const PTHREAD_STACK_MIN: usize = 16384;
348328
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
349329
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
350330
pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0;
@@ -359,3 +339,11 @@ pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
359339
extern {
360340
pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void;
361341
}
342+
343+
cfg_if! {
344+
if #[cfg(target_os = "l4re")] {
345+
mod l4re;
346+
pub use self::l4re::*;
347+
} else { }
348+
}
349+

0 commit comments

Comments
 (0)