Debian Codegraph @

third_party/rust/libc/src/unix/nuttx/mod.rs

raw
1 use crate::prelude::*;
2 use crate::{in6_addr, in_addr_t, timespec, DIR};
3
4 pub type nlink_t = u16;
5 pub type ino_t = u16;
6 pub type blkcnt_t = u64;
7 pub type blksize_t = i16;
8 pub type cc_t = u8;
9 pub type clock_t = i64;
10 pub type dev_t = i32;
11 pub type fsblkcnt_t = u64;
12 pub type locale_t = *mut i8;
13 pub type mode_t = u32;
14 pub type nfds_t = u32;
15 pub type off_t = i64;
16 pub type pthread_key_t = i32;
17 pub type pthread_mutexattr_t = u8;
18 pub type pthread_rwlockattr_t = i32;
19 pub type pthread_t = i32;
20 pub type rlim_t = i64;
21 pub type sa_family_t = u16;
22 pub type socklen_t = u32;
23 pub type speed_t = usize;
24 pub type suseconds_t = i32;
25 pub type tcflag_t = u32;
26 pub type clockid_t = i32;
27 pub type time_t = i64;
28 pub type wchar_t = i32;
29
30 s! {
31 pub struct stat {
32 pub st_dev: dev_t,
33 pub st_ino: ino_t,
34 pub st_mode: mode_t,
35 pub st_nlink: u64,
36 pub st_uid: u32,
37 pub st_gid: u32,
38 pub st_rdev: dev_t,
39 pub st_size: off_t,
40 pub st_atim: timespec,
41 pub st_mtim: timespec,
42 pub st_ctim: timespec,
43 pub st_blksize: blksize_t,
44 pub st_blocks: i64,
45 __reserved: [usize; __DEFAULT_RESERVED_SIZE__],
46 }
47
48 pub struct sockaddr {
49 pub sa_family: sa_family_t,
50 pub sa_data: [u8; 14],
51 }
52
53 pub struct passwd {
54 pub pw_name: *const c_char,
55 pub pw_passwd: *const c_char,
56 pub pw_uid: u32,
57 pub pw_gid: u32,
58 pub pw_gecos: *const c_char,
59 pub pw_dir: *const c_char,
60 pub pw_shell: *const c_char,
61 __reserved: [usize; __DEFAULT_RESERVED_SIZE__],
62 }
63
64 pub struct sem_t {
65 __val: [usize; __SEM_SIZE__],
66 }
67
68 pub struct pthread_attr_t {
69 __val: [usize; __PTHREAD_ATTR_SIZE__],
70 }
71
72 pub struct pthread_mutex_t {
73 __val: [usize; __PTHREAD_MUTEX_SIZE__],
74 }
75
76 pub struct pthread_cond_t {
77 __val: [usize; __PTHREAD_COND_SIZE__],
78 }
79
80 pub struct pthread_condattr_t {
81 __val: [usize; __PTHREAD_CONDATTR_SIZE__],
82 }
83
84 pub struct Dl_info {
85 pub dli_fname: *const c_char,
86 pub dli_fbase: *mut c_void,
87 pub dli_sname: *const c_char,
88 pub dli_saddr: *mut c_void,
89 }
90
91 pub struct lconv {
92 pub decimal_point: *const c_char,
93 pub thousands_sep: *const c_char,
94 pub grouping: *const c_char,
95 pub int_curr_symbol: *const c_char,
96 pub currency_symbol: *const c_char,
97 pub mon_decimal_point: *const c_char,
98 pub mon_thousands_sep: *const c_char,
99 pub mon_grouping: *const c_char,
100 pub positive_sign: *const c_char,
101 pub negative_sign: *const c_char,
102 pub int_frac_digits: i8,
103 pub frac_digits: i8,
104 pub p_cs_precedes: i8,
105 pub p_sep_by_space: i8,
106 pub n_cs_precedes: i8,
107 pub n_sep_by_space: i8,
108 pub p_sign_posn: i8,
109 pub n_sign_posn: i8,
110 pub int_n_cs_precedes: i8,
111 pub int_n_sep_by_space: i8,
112 pub int_n_sign_posn: i8,
113 pub int_p_cs_precedes: i8,
114 pub int_p_sep_by_space: i8,
115 pub int_p_sign_posn: i8,
116 __reserved: [usize; __DEFAULT_RESERVED_SIZE__],
117 }
118
119 pub struct tm {
120 pub tm_sec: i32,
121 pub tm_min: i32,
122 pub tm_hour: i32,
123 pub tm_mday: i32,
124 pub tm_mon: i32,
125 pub tm_year: i32,
126 pub tm_wday: i32,
127 pub tm_yday: i32,
128 pub tm_isdst: i32,
129 pub tm_gmtoff: isize,
130 pub tm_zone: *const c_char,
131 __reserved: [usize; __DEFAULT_RESERVED_SIZE__],
132 }
133
134 pub struct addrinfo {
135 pub ai_flags: i32,
136 pub ai_family: i32,
137 pub ai_socktype: i32,
138 pub ai_protocol: i32,
139 pub ai_addrlen: socklen_t,
140 pub ai_addr: *mut sockaddr,
141 pub ai_canonname: *mut c_char,
142 pub ai_next: *mut addrinfo,
143 __reserved: [usize; __DEFAULT_RESERVED_SIZE__],
144 }
145
146 pub struct pthread_rwlock_t {
147 __val: [usize; __PTHREAD_RWLOCK_SIZE__],
148 }
149
150 pub struct statvfs {
151 pub f_bsize: usize,
152 pub f_frsize: usize,
153 pub f_blocks: fsblkcnt_t,
154 pub f_bfree: fsblkcnt_t,
155 pub f_bavail: fsblkcnt_t,
156 pub f_files: fsblkcnt_t,
157 pub f_ffree: fsblkcnt_t,
158 pub f_favail: fsblkcnt_t,
159 pub f_fsid: usize,
160 pub f_flag: usize,
161 pub f_namemax: usize,
162 __reserved: [usize; __DEFAULT_RESERVED_SIZE__],
163 }
164
165 pub struct dirent {
166 pub d_type: u8,
167 pub d_name: [c_char; __NAME_MAX__ + 1],
168 }
169
170 pub struct fd_set {
171 __val: [u32; __FDSET_SIZE__],
172 }
173
174 pub struct sigset_t {
175 __val: [u32; __SIGSET_SIZE__],
176 }
177
178 pub struct sigaction {
179 pub sa_handler: usize,
180 pub sa_mask: sigset_t,
181 pub sa_flags: i32,
182 pub sa_user: usize,
183 __reserved: [usize; __DEFAULT_RESERVED_SIZE__],
184 }
185
186 pub struct termios {
187 pub c_iflag: tcflag_t,
188 pub c_oflag: tcflag_t,
189 pub c_cflag: tcflag_t,
190 pub c_lflag: tcflag_t,
191 pub c_cc: [cc_t; 12],
192 pub c_speed: speed_t,
193 __reserved: [usize; __DEFAULT_RESERVED_SIZE__],
194 }
195
196 pub struct in_addr {
197 pub s_addr: in_addr_t,
198 }
199
200 pub struct sockaddr_in {
201 pub sin_family: sa_family_t,
202 pub sin_port: crate::in_port_t,
203 pub sin_addr: crate::in_addr,
204 pub sin_zero: [u8; 8],
205 }
206
207 pub struct sockaddr_in6 {
208 pub sin6_family: sa_family_t,
209 pub sin6_port: crate::in_port_t,
210 pub sin6_flowinfo: u32,
211 pub sin6_addr: crate::in6_addr,
212 pub sin6_scope_id: u32,
213 }
214
215 pub struct sockaddr_un {
216 pub sun_family: sa_family_t,
217 pub sun_path: [c_char; 108],
218 }
219
220 pub struct sockaddr_storage {
221 pub ss_family: sa_family_t,
222 ss_data: [u32; __SOCKADDR_STORAGE_SIZE__],
223 }
224
225 pub struct ip_mreq {
226 pub imr_multiaddr: in_addr,
227 pub imr_interface: in_addr,
228 }
229
230 pub struct ipv6_mreq {
231 pub ipv6mr_multiaddr: in6_addr,
232 pub ipv6mr_interface: u32,
233 }
234
235 pub struct timeval {
236 pub tv_sec: time_t,
237 pub tv_usec: suseconds_t,
238 }
239 }
240
241 // Reserved two pointer size for reserved area for some structures.
242 // This ensures that the size of these structures is large enough
243 // if more fields are added in the NuttX side.
244 //
245 // These structures are that defined by POSIX but only necessary fields are included,
246 // for example, struct passwd, https://pubs.opengroup.org/onlinepubs/009695399/basedefs/pwd.h.html,
247 // POSIX only defines following fields in struct passwd:
248 // char *pw_name User's login name.
249 // char *pw_passwd Encrypted password.
250 // uid_t pw_uid Numerical user ID.
251 // gid_t pw_gid Numerical group ID.
252 // char *pw_dir Initial working directory.
253 // char *pw_shell Program to use as shell.
254 // Other fields can be different depending on the implementation.
255
256 const __DEFAULT_RESERVED_SIZE__: usize = 2;
257
258 const __SOCKADDR_STORAGE_SIZE__: usize = 36;
259 const __PTHREAD_ATTR_SIZE__: usize = 5;
260 const __PTHREAD_MUTEX_SIZE__: usize = 9;
261 const __PTHREAD_COND_SIZE__: usize = 7;
262 const __PTHREAD_CONDATTR_SIZE__: usize = 5;
263 const __PTHREAD_RWLOCK_SIZE__: usize = 17;
264 const __SEM_SIZE__: usize = 6;
265 const __NAME_MAX__: usize = 64;
266 const __FDSET_SIZE__: usize = 10;
267 const __SIGSET_SIZE__: usize = 8;
268
269 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
270 __val: [0; __PTHREAD_COND_SIZE__],
271 };
272 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
273 __val: [0; __PTHREAD_MUTEX_SIZE__],
274 };
275
276 // dlfcn.h
277 pub const RTLD_DEFAULT: *mut c_void = 0 as *mut c_void;
278
279 // stdlib.h
280 pub const EXIT_SUCCESS: i32 = 0;
281 pub const EXIT_FAILURE: i32 = 1;
282
283 // time.h
284 pub const CLOCK_REALTIME: i32 = 0;
285 pub const CLOCK_MONOTONIC: i32 = 1;
286
287 // errno.h
288 pub const EPERM: i32 = 1;
289 pub const ENOENT: i32 = 2;
290 pub const ESRCH: i32 = 3;
291 pub const EINTR: i32 = 4;
292 pub const EIO: i32 = 5;
293 pub const ENXIO: i32 = 6;
294 pub const E2BIG: i32 = 7;
295 pub const ENOEXEC: i32 = 8;
296 pub const EBADF: i32 = 9;
297 pub const ECHILD: i32 = 10;
298 pub const EAGAIN: i32 = 11;
299 pub const ENOMEM: i32 = 12;
300 pub const EACCES: i32 = 13;
301 pub const EFAULT: i32 = 14;
302 pub const ENOTBLK: i32 = 15;
303 pub const EBUSY: i32 = 16;
304 pub const EEXIST: i32 = 17;
305 pub const EXDEV: i32 = 18;
306 pub const ENODEV: i32 = 19;
307 pub const ENOTDIR: i32 = 20;
308 pub const EISDIR: i32 = 21;
309 pub const EINVAL: i32 = 22;
310 pub const ENFILE: i32 = 23;
311 pub const EMFILE: i32 = 24;
312 pub const ENOTTY: i32 = 25;
313 pub const ETXTBSY: i32 = 26;
314 pub const EFBIG: i32 = 27;
315 pub const ENOSPC: i32 = 28;
316 pub const ESPIPE: i32 = 29;
317 pub const EROFS: i32 = 30;
318 pub const EMLINK: i32 = 31;
319 pub const EPIPE: i32 = 32;
320 pub const EDOM: i32 = 33;
321 pub const ERANGE: i32 = 34;
322 pub const EDEADLK: i32 = 35;
323 pub const ENAMETOOLONG: i32 = 36;
324 pub const ENOLCK: i32 = 37;
325 pub const ENOSYS: i32 = 38;
326 pub const ENOTEMPTY: i32 = 39;
327 pub const ELOOP: i32 = 40;
328 pub const EWOULDBLOCK: i32 = EAGAIN;
329 pub const ENOMSG: i32 = 42;
330 pub const EIDRM: i32 = 43;
331 pub const ECHRNG: i32 = 44;
332 pub const EL2NSYNC: i32 = 45;
333 pub const EL3HLT: i32 = 46;
334 pub const EL3RST: i32 = 47;
335 pub const ELNRNG: i32 = 48;
336 pub const EUNATCH: i32 = 49;
337 pub const ENOCSI: i32 = 50;
338 pub const EL2HLT: i32 = 51;
339 pub const EBADE: i32 = 52;
340 pub const EBADR: i32 = 53;
341 pub const EXFULL: i32 = 54;
342 pub const ENOANO: i32 = 55;
343 pub const EBADRQC: i32 = 56;
344 pub const EBADSLT: i32 = 57;
345 pub const EDEADLOCK: i32 = EDEADLK;
346 pub const EBFONT: i32 = 59;
347 pub const ENOSTR: i32 = 60;
348 pub const ENODATA: i32 = 61;
349 pub const ETIME: i32 = 62;
350 pub const ENOSR: i32 = 63;
351 pub const ENONET: i32 = 64;
352 pub const ENOPKG: i32 = 65;
353 pub const EREMOTE: i32 = 66;
354 pub const ENOLINK: i32 = 67;
355 pub const EADV: i32 = 68;
356 pub const ESRMNT: i32 = 69;
357 pub const ECOMM: i32 = 70;
358 pub const EPROTO: i32 = 71;
359 pub const EMULTIHOP: i32 = 72;
360 pub const EDOTDOT: i32 = 73;
361 pub const EBADMSG: i32 = 74;
362 pub const EOVERFLOW: i32 = 75;
363 pub const ENOTUNIQ: i32 = 76;
364 pub const EBADFD: i32 = 77;
365 pub const EREMCHG: i32 = 78;
366 pub const ELIBACC: i32 = 79;
367 pub const ELIBBAD: i32 = 80;
368 pub const ELIBSCN: i32 = 81;
369 pub const ELIBMAX: i32 = 82;
370 pub const ELIBEXEC: i32 = 83;
371 pub const EILSEQ: i32 = 84;
372 pub const ERESTART: i32 = 85;
373 pub const ESTRPIPE: i32 = 86;
374 pub const EUSERS: i32 = 87;
375 pub const ENOTSOCK: i32 = 88;
376 pub const EDESTADDRREQ: i32 = 89;
377 pub const EMSGSIZE: i32 = 90;
378 pub const EPROTOTYPE: i32 = 91;
379 pub const ENOPROTOOPT: i32 = 92;
380 pub const EPROTONOSUPPORT: i32 = 93;
381 pub const ESOCKTNOSUPPORT: i32 = 94;
382 pub const EOPNOTSUPP: i32 = 95;
383 pub const EPFNOSUPPORT: i32 = 96;
384 pub const EAFNOSUPPORT: i32 = 97;
385 pub const EADDRINUSE: i32 = 98;
386 pub const EADDRNOTAVAIL: i32 = 99;
387 pub const ENETDOWN: i32 = 100;
388 pub const ENETUNREACH: i32 = 101;
389 pub const ENETRESET: i32 = 102;
390 pub const ECONNABORTED: i32 = 103;
391 pub const ECONNRESET: i32 = 104;
392 pub const ENOBUFS: i32 = 105;
393 pub const EISCONN: i32 = 106;
394 pub const ENOTCONN: i32 = 107;
395 pub const ESHUTDOWN: i32 = 108;
396 pub const ETOOMANYREFS: i32 = 109;
397 pub const ETIMEDOUT: i32 = 110;
398 pub const ECONNREFUSED: i32 = 111;
399 pub const EHOSTDOWN: i32 = 112;
400 pub const EHOSTUNREACH: i32 = 113;
401 pub const EALREADY: i32 = 114;
402 pub const EINPROGRESS: i32 = 115;
403 pub const ESTALE: i32 = 116;
404 pub const EUCLEAN: i32 = 117;
405 pub const ENOTNAM: i32 = 118;
406 pub const ENAVAIL: i32 = 119;
407 pub const EISNAM: i32 = 120;
408 pub const EREMOTEIO: i32 = 121;
409 pub const EDQUOT: i32 = 122;
410 pub const ENOMEDIUM: i32 = 123;
411 pub const EMEDIUMTYPE: i32 = 124;
412 pub const ECANCELED: i32 = 125;
413 pub const ENOKEY: i32 = 126;
414 pub const EKEYEXPIRED: i32 = 127;
415 pub const EKEYREVOKED: i32 = 128;
416 pub const EKEYREJECTED: i32 = 129;
417 pub const EOWNERDEAD: i32 = 130;
418 pub const ENOTRECOVERABLE: i32 = 131;
419 pub const ERFKILL: i32 = 132;
420 pub const EHWPOISON: i32 = 133;
421 pub const ELBIN: i32 = 134;
422 pub const EFTYPE: i32 = 135;
423 pub const ENMFILE: i32 = 136;
424 pub const EPROCLIM: i32 = 137;
425 pub const ENOTSUP: i32 = 138;
426 pub const ENOSHARE: i32 = 139;
427 pub const ECASECLASH: i32 = 140;
428
429 // fcntl.h
430 pub const FIOCLEX: i32 = 0x30b;
431 pub const F_SETFL: i32 = 0x9;
432 pub const F_DUPFD_CLOEXEC: i32 = 0x12;
433 pub const F_GETFD: i32 = 0x1;
434 pub const F_GETFL: i32 = 0x2;
435 pub const O_RDONLY: i32 = 0x1;
436 pub const O_WRONLY: i32 = 0x2;
437 pub const O_RDWR: i32 = 0x3;
438 pub const O_CREAT: i32 = 0x4;
439 pub const O_EXCL: i32 = 0x8;
440 pub const O_NOCTTY: i32 = 0x0;
441 pub const O_TRUNC: i32 = 0x20;
442 pub const O_APPEND: i32 = 0x10;
443 pub const O_NONBLOCK: i32 = 0x40;
444 pub const O_DSYNC: i32 = 0x80;
445 pub const O_DIRECT: i32 = 0x200;
446 pub const O_LARGEFILE: i32 = 0x2000;
447 pub const O_DIRECTORY: i32 = 0x800;
448 pub const O_NOFOLLOW: i32 = 0x1000;
449 pub const O_NOATIME: i32 = 0x40000;
450 pub const O_CLOEXEC: i32 = 0x400;
451 pub const O_ACCMODE: i32 = 0x0003;
452 pub const AT_FDCWD: i32 = -100;
453 pub const AT_REMOVEDIR: i32 = 0x200;
454
455 // sys/types.h
456 pub const SEEK_SET: i32 = 0;
457 pub const SEEK_CUR: i32 = 1;
458 pub const SEEK_END: i32 = 2;
459
460 // sys/stat.h
461 pub const S_IFDIR: u32 = 0x4000;
462 pub const S_IFLNK: u32 = 0xA000;
463 pub const S_IFREG: u32 = 0x8000;
464 pub const S_IFMT: u32 = 0xF000;
465 pub const S_IFIFO: u32 = 0x1000;
466 pub const S_IFSOCK: u32 = 0xc000;
467 pub const S_IFBLK: u32 = 0x6000;
468 pub const S_IFCHR: u32 = 0x2000;
469 pub const S_IRUSR: u32 = 0x100;
470 pub const S_IWUSR: u32 = 0x80;
471 pub const S_IXUSR: u32 = 0x40;
472 pub const S_IRGRP: u32 = 0x20;
473 pub const S_IWGRP: u32 = 0x10;
474 pub const S_IXGRP: u32 = 0x8;
475 pub const S_IROTH: u32 = 0x004;
476 pub const S_IWOTH: u32 = 0x002;
477 pub const S_IXOTH: u32 = 0x001;
478
479 // sys/poll.h
480 pub const POLLIN: i16 = 0x01;
481 pub const POLLOUT: i16 = 0x04;
482 pub const POLLHUP: i16 = 0x10;
483 pub const POLLERR: i16 = 0x08;
484 pub const POLLNVAL: i16 = 0x20;
485
486 // sys/socket.h
487 pub const AF_UNIX: i32 = 1;
488 pub const SOCK_DGRAM: i32 = 2;
489 pub const SOCK_STREAM: i32 = 1;
490 pub const AF_INET: i32 = 2;
491 pub const AF_INET6: i32 = 10;
492 pub const MSG_PEEK: i32 = 0x02;
493 pub const SOL_SOCKET: i32 = 1;
494 pub const SHUT_WR: i32 = 2;
495 pub const SHUT_RD: i32 = 1;
496 pub const SHUT_RDWR: i32 = 3;
497 pub const SO_ERROR: i32 = 4;
498 pub const SO_REUSEADDR: i32 = 11;
499 pub const SOMAXCONN: i32 = 8;
500 pub const SO_LINGER: i32 = 6;
501 pub const SO_RCVTIMEO: i32 = 0xa;
502 pub const SO_SNDTIMEO: i32 = 0xe;
503 pub const SO_BROADCAST: i32 = 1;
504
505 // netinet/tcp.h
506 pub const TCP_NODELAY: i32 = 0x10;
507
508 // nuttx/fs/ioctl.h
509 pub const FIONBIO: i32 = 0x30a;
510
511 // unistd.h
512 pub const STDIN_FILENO: i32 = 0;
513 pub const STDOUT_FILENO: i32 = 1;
514 pub const STDERR_FILENO: i32 = 2;
515 pub const _SC_PAGESIZE: i32 = 0x36;
516 pub const _SC_THREAD_STACK_MIN: i32 = 0x58;
517 pub const _SC_GETPW_R_SIZE_MAX: i32 = 0x25;
518
519 // signal.h
520 pub const SIGPIPE: i32 = 13;
521
522 // pthread.h
523 pub const PTHREAD_MUTEX_NORMAL: i32 = 0;
524
525 // netinet/in.h
526 pub const IP_TTL: i32 = 0x1e;
527 pub const IPV6_V6ONLY: i32 = 0x17;
528 pub const IPV6_JOIN_GROUP: i32 = 0x11;
529 pub const IPV6_LEAVE_GROUP: i32 = 0x12;
530 pub const IP_MULTICAST_LOOP: i32 = 0x13;
531 pub const IPV6_MULTICAST_LOOP: i32 = 0x15;
532 pub const IP_MULTICAST_TTL: i32 = 0x12;
533 pub const IP_ADD_MEMBERSHIP: i32 = 0x14;
534 pub const IP_DROP_MEMBERSHIP: i32 = 0x15;
535
536 extern "C" {
537 pub fn bind(sockfd: i32, addr: *const sockaddr, addrlen: socklen_t) -> i32;
538 pub fn ioctl(fd: i32, request: i32, ...) -> i32;
539 pub fn dirfd(dirp: *mut DIR) -> i32;
540 pub fn recvfrom(
541 sockfd: i32,
542 buf: *mut c_void,
543 len: usize,
544 flags: i32,
545 src_addr: *mut sockaddr,
546 addrlen: *mut socklen_t,
547 ) -> i32;
548
549 pub fn pthread_create(
550 thread: *mut pthread_t,
551 attr: *const pthread_attr_t,
552 start_routine: extern "C" fn(*mut c_void) -> *mut c_void,
553 arg: *mut c_void,
554 ) -> i32;
555
556 pub fn clock_gettime(clockid: clockid_t, tp: *mut timespec) -> i32;
557 pub fn futimens(fd: i32, times: *const timespec) -> i32;
558 pub fn pthread_condattr_setclock(attr: *mut pthread_condattr_t, clock_id: clockid_t) -> i32;
559 pub fn pthread_setname_np(thread: pthread_t, name: *const c_char) -> i32;
560 pub fn pthread_getname_np(thread: pthread_t, name: *mut c_char, len: usize) -> i32;
561 pub fn getrandom(buf: *mut c_void, buflen: usize, flags: u32) -> isize;
562 }