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