1 //! Definitions for uclibc on 64bit systems
2 
3 use crate::off64_t;
4 use crate::prelude::*;
5 
6 pub type blkcnt_t = i64;
7 pub type blksize_t = i64;
8 pub type clock_t = i64;
9 pub type fsblkcnt_t = c_ulong;
10 pub type fsfilcnt_t = c_ulong;
11 pub type fsword_t = c_long;
12 pub type ino_t = c_ulong;
13 pub type nlink_t = c_uint;
14 pub type off_t = c_long;
15 // [uClibc docs] Note stat64 has the same shape as stat for x86-64.
16 pub type stat64 = stat;
17 pub type suseconds_t = c_long;
18 pub type time_t = c_int;
19 pub type wchar_t = c_int;
20 
21 pub type fsblkcnt64_t = u64;
22 pub type fsfilcnt64_t = u64;
23 pub type __u64 = c_ulong;
24 pub type __s64 = c_long;
25 
26 s! {
27     pub struct ipc_perm {
28         pub __key: crate::key_t,
29         pub uid: crate::uid_t,
30         pub gid: crate::gid_t,
31         pub cuid: crate::uid_t,
32         pub cgid: crate::gid_t,
33         pub mode: c_ushort, // read / write
34         __pad1: c_ushort,
35         pub __seq: c_ushort,
36         __pad2: c_ushort,
37         __unused1: c_ulong,
38         __unused2: c_ulong,
39     }
40 
41     #[cfg(not(target_os = "l4re"))]
42     pub struct pthread_attr_t {
43         __detachstate: c_int,
44         __schedpolicy: c_int,
45         __schedparam: __sched_param,
46         __inheritsched: c_int,
47         __scope: c_int,
48         __guardsize: size_t,
49         __stackaddr_set: c_int,
50         __stackaddr: *mut c_void, // better don't use it
51         __stacksize: size_t,
52     }
53 
54     pub struct __sched_param {
55         __sched_priority: c_int,
56     }
57 
58     pub struct siginfo_t {
59         si_signo: c_int,       // signal number
60         si_errno: c_int,       // if not zero: error value of signal, see errno.h
61         si_code: c_int,        // signal code
62         pub _pad: [c_int; 28], // unported union
63         _align: [usize; 0],
64     }
65 
66     pub struct shmid_ds {
67         pub shm_perm: crate::ipc_perm,
68         pub shm_segsz: size_t,        // segment size in bytes
69         pub shm_atime: crate::time_t, // time of last shmat()
70         pub shm_dtime: crate::time_t,
71         pub shm_ctime: crate::time_t,
72         pub shm_cpid: crate::pid_t,
73         pub shm_lpid: crate::pid_t,
74         pub shm_nattch: crate::shmatt_t,
75         __unused1: c_ulong,
76         __unused2: c_ulong,
77     }
78 
79     pub struct msqid_ds {
80         pub msg_perm: crate::ipc_perm,
81         pub msg_stime: crate::time_t,
82         pub msg_rtime: crate::time_t,
83         pub msg_ctime: crate::time_t,
84         pub __msg_cbytes: c_ulong,
85         pub msg_qnum: crate::msgqnum_t,
86         pub msg_qbytes: crate::msglen_t,
87         pub msg_lspid: crate::pid_t,
88         pub msg_lrpid: crate::pid_t,
89         __ignored1: c_ulong,
90         __ignored2: c_ulong,
91     }
92 
93     pub struct sockaddr {
94         pub sa_family: crate::sa_family_t,
95         pub sa_data: [c_char; 14],
96     }
97 
98     pub struct sockaddr_in {
99         pub sin_family: crate::sa_family_t,
100         pub sin_port: crate::in_port_t,
101         pub sin_addr: crate::in_addr,
102         pub sin_zero: [u8; 8],
103     }
104 
105     pub struct sockaddr_in6 {
106         pub sin6_family: crate::sa_family_t,
107         pub sin6_port: crate::in_port_t,
108         pub sin6_flowinfo: u32,
109         pub sin6_addr: crate::in6_addr,
110         pub sin6_scope_id: u32,
111     }
112 
113     /* ------------------------------------------------------------
114      * definitions below are *unverified* and might **break** the software
115      */
116 
117     //    pub struct in_addr {
118     //        pub s_addr: in_addr_t,
119     //    }
120     //
121     //    pub struct in6_addr {
122     //        pub s6_addr: [u8; 16],
123     //    }
124 
125     pub struct stat {
126         pub st_dev: c_ulong,
127         pub st_ino: crate::ino_t,
128         // According to uclibc/libc/sysdeps/linux/x86_64/bits/stat.h, order of
129         // nlink and mode are swapped on 64 bit systems.
130         pub st_nlink: crate::nlink_t,
131         pub st_mode: crate::mode_t,
132         pub st_uid: crate::uid_t,
133         pub st_gid: crate::gid_t,
134         pub st_rdev: c_ulong, // dev_t
135         pub st_size: off_t,   // file size
136         pub st_blksize: crate::blksize_t,
137         pub st_blocks: crate::blkcnt_t,
138         pub st_atime: crate::time_t,
139         pub st_atime_nsec: c_ulong,
140         pub st_mtime: crate::time_t,
141         pub st_mtime_nsec: c_ulong,
142         pub st_ctime: crate::time_t,
143         pub st_ctime_nsec: c_ulong,
144         st_pad4: [c_long; 3],
145     }
146 
147     // FIXME(1.0): This should not implement `PartialEq`
148     #[allow(unpredictable_function_pointer_comparisons)]
149     pub struct sigaction {
150         pub sa_handler: crate::sighandler_t,
151         pub sa_flags: c_ulong,
152         pub sa_restorer: Option<extern "C" fn()>,
153         pub sa_mask: crate::sigset_t,
154     }
155 
156     pub struct stack_t {
157         // FIXME(ulibc)
158         pub ss_sp: *mut c_void,
159         pub ss_flags: c_int,
160         pub ss_size: size_t,
161     }
162 
163     pub struct statfs {
164         // FIXME(ulibc)
165         pub f_type: fsword_t,
166         pub f_bsize: fsword_t,
167         pub f_blocks: crate::fsblkcnt_t,
168         pub f_bfree: crate::fsblkcnt_t,
169         pub f_bavail: crate::fsblkcnt_t,
170         pub f_files: crate::fsfilcnt_t,
171         pub f_ffree: crate::fsfilcnt_t,
172         pub f_fsid: crate::fsid_t,
173         pub f_namelen: fsword_t,
174         pub f_frsize: fsword_t,
175         f_spare: [fsword_t; 5],
176     }
177 
178     pub struct statfs64 {
179         pub f_type: c_int,
180         pub f_bsize: c_int,
181         pub f_blocks: crate::fsblkcnt64_t,
182         pub f_bfree: crate::fsblkcnt64_t,
183         pub f_bavail: crate::fsblkcnt64_t,
184         pub f_files: crate::fsfilcnt64_t,
185         pub f_ffree: crate::fsfilcnt64_t,
186         pub f_fsid: crate::fsid_t,
187         pub f_namelen: c_int,
188         pub f_frsize: c_int,
189         pub f_flags: c_int,
190         pub f_spare: [c_int; 4],
191     }
192 
193     pub struct statvfs64 {
194         pub f_bsize: c_ulong,
195         pub f_frsize: c_ulong,
196         pub f_blocks: u64,
197         pub f_bfree: u64,
198         pub f_bavail: u64,
199         pub f_files: u64,
200         pub f_ffree: u64,
201         pub f_favail: u64,
202         pub f_fsid: c_ulong,
203         __f_unused: c_int,
204         pub f_flag: c_ulong,
205         pub f_namemax: c_ulong,
206         __f_spare: [c_int; 6],
207     }
208 
209     pub struct msghdr {
210         // FIXME(ulibc)
211         pub msg_name: *mut c_void,
212         pub msg_namelen: crate::socklen_t,
213         pub msg_iov: *mut crate::iovec,
214         pub msg_iovlen: size_t,
215         pub msg_control: *mut c_void,
216         pub msg_controllen: size_t,
217         pub msg_flags: c_int,
218     }
219 
220     pub struct termios {
221         // FIXME(ulibc)
222         pub c_iflag: crate::tcflag_t,
223         pub c_oflag: crate::tcflag_t,
224         pub c_cflag: crate::tcflag_t,
225         pub c_lflag: crate::tcflag_t,
226         pub c_line: crate::cc_t,
227         pub c_cc: [crate::cc_t; crate::NCCS],
228     }
229 
230     pub struct sigset_t {
231         // FIXME(ulibc)
232         __val: [c_ulong; 16],
233     }
234 
235     pub struct sysinfo {
236         // FIXME(ulibc)
237         pub uptime: c_long,
238         pub loads: [c_ulong; 3],
239         pub totalram: c_ulong,
240         pub freeram: c_ulong,
241         pub sharedram: c_ulong,
242         pub bufferram: c_ulong,
243         pub totalswap: c_ulong,
244         pub freeswap: c_ulong,
245         pub procs: c_ushort,
246         pub pad: c_ushort,
247         pub totalhigh: c_ulong,
248         pub freehigh: c_ulong,
249         pub mem_unit: c_uint,
250         pub _f: [c_char; 0],
251     }
252 
253     pub struct glob_t {
254         // FIXME(ulibc)
255         pub gl_pathc: size_t,
256         pub gl_pathv: *mut *mut c_char,
257         pub gl_offs: size_t,
258         pub gl_flags: c_int,
259         __unused1: *mut c_void,
260         __unused2: *mut c_void,
261         __unused3: *mut c_void,
262         __unused4: *mut c_void,
263         __unused5: *mut c_void,
264     }
265 
266     pub struct cpu_set_t {
267         // FIXME(ulibc)
268         #[cfg(target_pointer_width = "32")]
269         bits: [u32; 32],
270         #[cfg(target_pointer_width = "64")]
271         bits: [u64; 16],
272     }
273 
274     pub struct fsid_t {
275         // FIXME(ulibc)
276         __val: [c_int; 2],
277     }
278 
279     // FIXME(1.0): this is actually a union
280     pub struct sem_t {
281         #[cfg(target_pointer_width = "32")]
282         __size: [c_char; 16],
283         #[cfg(target_pointer_width = "64")]
284         __size: [c_char; 32],
285         __align: [c_long; 0],
286     }
287 
288     pub struct cmsghdr {
289         pub cmsg_len: size_t,
290         pub cmsg_level: c_int,
291         pub cmsg_type: c_int,
292     }
293 }
294 
295 s_no_extra_traits! {
296     #[allow(missing_debug_implementations)]
297     pub struct dirent {
298         pub d_ino: crate::ino64_t,
299         pub d_off: off64_t,
300         pub d_reclen: u16,
301         pub d_type: u8,
302         pub d_name: [c_char; 256],
303     }
304 }
305 
306 // constants
307 pub const ENAMETOOLONG: c_int = 36; // File name too long
308 pub const ENOTEMPTY: c_int = 39; // Directory not empty
309 pub const ELOOP: c_int = 40; // Too many symbolic links encountered
310 pub const EADDRINUSE: c_int = 98; // Address already in use
311 pub const EADDRNOTAVAIL: c_int = 99; // Cannot assign requested address
312 pub const ENETDOWN: c_int = 100; // Network is down
313 pub const ENETUNREACH: c_int = 101; // Network is unreachable
314 pub const ECONNABORTED: c_int = 103; // Software caused connection abort
315 pub const ECONNREFUSED: c_int = 111; // Connection refused
316 pub const ECONNRESET: c_int = 104; // Connection reset by peer
317 pub const EDEADLK: c_int = 35; // Resource deadlock would occur
318 pub const ENOSYS: c_int = 38; // Function not implemented
319 pub const ENOTCONN: c_int = 107; // Transport endpoint is not connected
320 pub const ETIMEDOUT: c_int = 110; // connection timed out
321 pub const ESTALE: c_int = 116; // Stale file handle
322 pub const EHOSTUNREACH: c_int = 113; // No route to host
323 pub const EDQUOT: c_int = 122; // Quota exceeded
324 pub const EOPNOTSUPP: c_int = 0x5f;
325 pub const ENODATA: c_int = 0x3d;
326 pub const O_APPEND: c_int = 0o2000;
327 pub const O_ACCMODE: c_int = 0o003;
328 pub const O_CLOEXEC: c_int = 0x80000;
329 pub const O_CREAT: c_int = 0100;
330 pub const O_DIRECTORY: c_int = 0o200000;
331 pub const O_EXCL: c_int = 0o200;
332 pub const O_NOFOLLOW: c_int = 0x20000;
333 pub const O_NONBLOCK: c_int = 0o4000;
334 pub const O_TRUNC: c_int = 0o1000;
335 pub const NCCS: usize = 32;
336 pub const SIG_SETMASK: c_int = 2; // Set the set of blocked signals
337 pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
338 pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
339 pub const SOCK_DGRAM: c_int = 2; // connectionless, unreliable datagrams
340 pub const SOCK_STREAM: c_int = 1; // …/common/bits/socket_type.h
341 pub const __SIZEOF_PTHREAD_COND_T: usize = 48;
342 pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
343 pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
344 pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
345 pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
346 pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
347 
348 cfg_if! {
349     if #[cfg(target_os = "l4re")] {
350         mod l4re;
351         pub use self::l4re::*;
352     } else {
353         mod other;
354         pub use other::*;
355     }
356 }
357