@@ -10,6 +10,7 @@ pub mod errno;
10
10
pub mod tcplistener;
11
11
pub mod tcpstream;
12
12
13
+ use core:: ffi:: c_char;
13
14
pub use core:: ffi:: { c_int, c_short, c_void} ;
14
15
15
16
pub use self :: errno:: * ;
@@ -42,7 +43,6 @@ pub const LOW_PRIO: Priority = Priority::from(1);
42
43
#[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Default , Hash ) ]
43
44
pub struct Handle ( usize ) ;
44
45
45
- pub const NSEC_PER_SEC : u64 = 1_000_000_000 ;
46
46
pub const FUTEX_RELATIVE_TIMEOUT : u32 = 1 ;
47
47
pub const CLOCK_REALTIME : u64 = 1 ;
48
48
pub const CLOCK_MONOTONIC : u64 = 4 ;
@@ -75,9 +75,16 @@ pub fn isatty(_fd: c_int) -> bool {
75
75
#[ repr( C ) ]
76
76
pub struct timespec {
77
77
/// seconds
78
- pub tv_sec : i64 ,
78
+ pub tv_sec : time_t ,
79
79
/// nanoseconds
80
- pub tv_nsec : i64 ,
80
+ pub tv_nsec : u32 ,
81
+ }
82
+
83
+ #[ repr( C ) ]
84
+ #[ derive( Debug , Copy , Clone ) ]
85
+ pub struct timeval {
86
+ pub tv_sec : time_t ,
87
+ pub tv_usec : suseconds_t ,
81
88
}
82
89
83
90
/// Internet protocol version.
@@ -109,7 +116,7 @@ pub enum IpAddress {
109
116
}
110
117
111
118
/// The largest number `rand` will return
112
- pub const RAND_MAX : u64 = 2_147_483_647 ;
119
+ pub const RAND_MAX : i32 = 2_147_483_647 ;
113
120
114
121
pub const AF_INET : i32 = 0 ;
115
122
pub const AF_INET6 : i32 = 1 ;
@@ -173,14 +180,17 @@ pub type in_port_t = u16;
173
180
pub type time_t = i64 ;
174
181
pub type suseconds_t = i64 ;
175
182
pub type nfds_t = usize ;
183
+ pub type sem_t = * const c_void ;
184
+ pub type pid_t = i32 ;
185
+ pub type clockid_t = i32 ;
176
186
177
187
#[ repr( C ) ]
178
188
#[ derive( Debug , Copy , Clone ) ]
179
189
pub struct in_addr {
180
- pub s_addr : u32 ,
190
+ pub s_addr : in_addr_t ,
181
191
}
182
192
183
- #[ repr( C ) ]
193
+ #[ repr( C , align ( 4 ) ) ]
184
194
#[ derive( Debug , Copy , Clone ) ]
185
195
pub struct in6_addr {
186
196
pub s6_addr : [ u8 ; 16 ] ,
@@ -207,10 +217,11 @@ pub struct sockaddr_in {
207
217
#[ repr( C ) ]
208
218
#[ derive( Debug , Copy , Clone ) ]
209
219
pub struct sockaddr_in6 {
220
+ pub sin6_len : u8 ,
210
221
pub sin6_family : sa_family_t ,
211
- pub sin6_port : u16 ,
212
- pub sin6_addr : in6_addr ,
222
+ pub sin6_port : in_port_t ,
213
223
pub sin6_flowinfo : u32 ,
224
+ pub sin6_addr : in6_addr ,
214
225
pub sin6_scope_id : u32 ,
215
226
}
216
227
@@ -222,8 +233,8 @@ pub struct addrinfo {
222
233
pub ai_socktype : i32 ,
223
234
pub ai_protocol : i32 ,
224
235
pub ai_addrlen : socklen_t ,
225
- pub ai_addr : * mut sockaddr ,
226
236
pub ai_canonname : * mut u8 ,
237
+ pub ai_addr : * mut sockaddr ,
227
238
pub ai_next : * mut addrinfo ,
228
239
}
229
240
@@ -232,8 +243,9 @@ pub struct addrinfo {
232
243
pub struct sockaddr_storage {
233
244
pub s2_len : u8 ,
234
245
pub ss_family : sa_family_t ,
235
- pub s2_data1 : [ i8 ; 2usize ] ,
236
- pub s2_data2 : [ u32 ; 3usize ] ,
246
+ __ss_pad1 : [ u8 ; 6 ] ,
247
+ __ss_align : i64 ,
248
+ __ss_pad2 : [ u8 ; 112 ] ,
237
249
}
238
250
239
251
#[ repr( C ) ]
@@ -257,13 +269,6 @@ pub struct linger {
257
269
pub l_linger : i32 ,
258
270
}
259
271
260
- #[ repr( C ) ]
261
- #[ derive( Debug , Copy , Clone ) ]
262
- pub struct timeval {
263
- pub tv_sec : time_t ,
264
- pub tv_usec : suseconds_t ,
265
- }
266
-
267
272
#[ repr( C ) ]
268
273
#[ derive( Debug , Copy , Clone ) ]
269
274
pub struct pollfd {
@@ -296,14 +301,14 @@ pub struct stat {
296
301
/// size in blocks
297
302
pub st_blocks : i64 ,
298
303
/// time of last access
299
- pub st_atime : u64 ,
300
- pub st_atime_nsec : u64 ,
304
+ pub st_atime : time_t ,
305
+ pub st_atime_nsec : u32 ,
301
306
/// time of last modification
302
- pub st_mtime : u64 ,
303
- pub st_mtime_nsec : u64 ,
307
+ pub st_mtime : time_t ,
308
+ pub st_mtime_nsec : u32 ,
304
309
/// time of last status change
305
- pub st_ctime : u64 ,
306
- pub st_ctime_nsec : u64 ,
310
+ pub st_ctime : time_t ,
311
+ pub st_ctime_nsec : u32 ,
307
312
}
308
313
309
314
#[ repr( C ) ]
@@ -318,30 +323,38 @@ pub struct dirent64 {
318
323
/// File type
319
324
pub d_type : u8 ,
320
325
/// Filename (null-terminated)
321
- pub d_name : core :: marker :: PhantomData < u8 > ,
326
+ pub d_name : [ u8 ; 256 ] ,
322
327
}
323
328
324
- pub const DT_UNKNOWN : u32 = 0 ;
325
- pub const DT_FIFO : u32 = 1 ;
326
- pub const DT_CHR : u32 = 2 ;
327
- pub const DT_DIR : u32 = 4 ;
328
- pub const DT_BLK : u32 = 6 ;
329
- pub const DT_REG : u32 = 8 ;
330
- pub const DT_LNK : u32 = 10 ;
331
- pub const DT_SOCK : u32 = 12 ;
332
- pub const DT_WHT : u32 = 14 ;
333
-
334
- pub const S_IFDIR : u32 = 0x4000 ;
335
- pub const S_IFREG : u32 = 0x8000 ;
336
- pub const S_IFLNK : u32 = 0xA000 ;
337
- pub const S_IFMT : u32 = 0xF000 ;
338
-
339
- // sysmbols, which are part of the library operating system
329
+ pub const DT_UNKNOWN : u8 = 0 ;
330
+ pub const DT_FIFO : u8 = 1 ;
331
+ pub const DT_CHR : u8 = 2 ;
332
+ pub const DT_DIR : u8 = 4 ;
333
+ pub const DT_BLK : u8 = 6 ;
334
+ pub const DT_REG : u8 = 8 ;
335
+ pub const DT_LNK : u8 = 10 ;
336
+ pub const DT_SOCK : u8 = 12 ;
337
+ pub const DT_WHT : u8 = 14 ;
338
+
339
+ pub const S_IFIFO : u32 = 0o1_0000 ;
340
+ pub const S_IFCHR : u32 = 0o2_0000 ;
341
+ pub const S_IFBLK : u32 = 0o6_0000 ;
342
+ pub const S_IFDIR : u32 = 0o4_0000 ;
343
+ pub const S_IFREG : u32 = 0o10_0000 ;
344
+ pub const S_IFLNK : u32 = 0o12_0000 ;
345
+ pub const S_IFSOCK : u32 = 0o14_0000 ;
346
+ pub const S_IFMT : u32 = 0o17_0000 ;
347
+
348
+ // symbols, which are part of the library operating system
340
349
extern "C" {
341
350
/// Get the last error number from the thread local storage
342
351
#[ link_name = "sys_get_errno" ]
343
352
pub fn get_errno ( ) -> i32 ;
344
353
354
+ /// Get the last error number from the thread local storage
355
+ #[ link_name = "sys_errno" ]
356
+ pub fn errno ( ) -> i32 ;
357
+
345
358
/// If the value at address matches the expected value, park the current thread until it is either
346
359
/// woken up with [`futex_wake`] (returns 0) or an optional timeout elapses (returns -ETIMEDOUT).
347
360
///
@@ -367,29 +380,31 @@ extern "C" {
367
380
368
381
/// sem_init() initializes the unnamed semaphore at the address
369
382
/// pointed to by `sem`. The `value` argument specifies the
370
- /// initial value for the semaphore.
383
+ /// initial value for the semaphore. If `pshared` is nonzero,
384
+ /// then the semaphore is shared between processes (currently
385
+ /// not supported).
371
386
#[ link_name = "sys_sem_init" ]
372
- pub fn sem_init ( sem : * mut * const c_void , value : u32 ) -> i32 ;
387
+ pub fn sem_init ( sem : * mut sem_t , pshared : i32 , value : u32 ) -> i32 ;
373
388
374
389
/// sem_destroy() frees the unnamed semaphore at the address
375
390
/// pointed to by `sem`.
376
391
#[ link_name = "sys_sem_destroy" ]
377
- pub fn sem_destroy ( sem : * const c_void ) -> i32 ;
392
+ pub fn sem_destroy ( sem : * mut sem_t ) -> i32 ;
378
393
379
394
/// sem_post() increments the semaphore pointed to by `sem`.
380
395
/// If the semaphore's value consequently becomes greater
381
396
/// than zero, then another thread blocked in a sem_wait call
382
397
/// will be woken up and proceed to lock the semaphore.
383
398
#[ link_name = "sys_sem_post" ]
384
- pub fn sem_post ( sem : * const c_void ) -> i32 ;
399
+ pub fn sem_post ( sem : * mut sem_t ) -> i32 ;
385
400
386
401
/// try to decrement a semaphore
387
402
///
388
403
/// sem_trywait() is the same as sem_timedwait(), except that
389
404
/// if the decrement cannot be immediately performed, then call
390
405
/// returns a negative value instead of blocking.
391
406
#[ link_name = "sys_sem_trywait" ]
392
- pub fn sem_trywait ( sem : * const c_void ) -> i32 ;
407
+ pub fn sem_trywait ( sem : * mut sem_t ) -> i32 ;
393
408
394
409
/// decrement a semaphore
395
410
///
@@ -400,17 +415,17 @@ extern "C" {
400
415
/// it becomes possible to perform the decrement of the time limit
401
416
/// to wait for the semaphore is expired. A time limit `ms` of
402
417
/// means infinity waiting time.
403
- #[ link_name = "sys_timedwait " ]
404
- pub fn sem_timedwait ( sem : * const c_void , ms : u32 ) -> i32 ;
418
+ #[ link_name = "sys_sem_timedwait " ]
419
+ pub fn sem_timedwait ( sem : * mut sem_t , abs_timeout : * const timespec ) -> i32 ;
405
420
406
421
/// Determines the id of the current thread
407
422
#[ link_name = "sys_getpid" ]
408
- pub fn getpid ( ) -> u32 ;
423
+ pub fn getpid ( ) -> pid_t ;
409
424
410
- /// cause normal termination and return `arg `
425
+ /// cause normal termination and return `status `
411
426
/// to the host system
412
427
#[ link_name = "sys_exit" ]
413
- pub fn exit ( arg : i32 ) -> !;
428
+ pub fn exit ( status : i32 ) -> !;
414
429
415
430
/// cause abnormal termination
416
431
#[ link_name = "sys_abort" ]
@@ -423,6 +438,10 @@ extern "C" {
423
438
#[ link_name = "sys_usleep" ]
424
439
pub fn usleep ( usecs : u64 ) ;
425
440
441
+ /// suspend thread execution for an interval measured in nanoseconds
442
+ #[ link_name = "sys_nanosleep" ]
443
+ pub fn nanosleep ( tp : * const timespec ) -> i32 ;
444
+
426
445
/// spawn a new thread
427
446
///
428
447
/// spawn() starts a new thread. The new thread starts execution
@@ -487,37 +506,37 @@ extern "C" {
487
506
/// `CLOCK_MONOTONIC`: clock that increments monotonically,
488
507
/// tracking the time since an arbitrary point
489
508
#[ link_name = "sys_clock_gettime" ]
490
- pub fn clock_gettime ( clock_id : u64 , tp : * mut timespec ) -> i32 ;
509
+ pub fn clock_gettime ( clock_id : clockid_t , tp : * mut timespec ) -> i32 ;
491
510
492
511
/// open and possibly create a file
493
512
///
494
513
/// The open() system call opens the file specified by `name`.
495
514
/// If the specified file does not exist, it may optionally
496
515
/// be created by open().
497
516
#[ link_name = "sys_open" ]
498
- pub fn open ( name : * const i8 , flags : i32 , mode : i32 ) -> i32 ;
517
+ pub fn open ( name : * const c_char , flags : i32 , mode : i32 ) -> i32 ;
499
518
500
519
/// open a directory
501
520
///
502
521
/// The opendir() system call opens the directory specified by `name`.
503
522
#[ link_name = "sys_opendir" ]
504
- pub fn opendir ( name : * const i8 ) -> i32 ;
523
+ pub fn opendir ( name : * const c_char ) -> i32 ;
505
524
506
525
/// delete the file it refers to `name`
507
526
#[ link_name = "sys_unlink" ]
508
- pub fn unlink ( name : * const i8 ) -> i32 ;
527
+ pub fn unlink ( name : * const c_char ) -> i32 ;
509
528
510
529
/// remove directory it refers to `name`
511
530
#[ link_name = "sys_rmdir" ]
512
- pub fn rmdir ( name : * const i8 ) -> i32 ;
531
+ pub fn rmdir ( name : * const c_char ) -> i32 ;
513
532
514
533
/// stat
515
534
#[ link_name = "sys_stat" ]
516
- pub fn stat ( name : * const i8 , stat : * mut stat ) -> i32 ;
535
+ pub fn stat ( name : * const c_char , stat : * mut stat ) -> i32 ;
517
536
518
537
/// lstat
519
538
#[ link_name = "sys_lstat" ]
520
- pub fn lstat ( name : * const i8 , stat : * mut stat ) -> i32 ;
539
+ pub fn lstat ( name : * const c_char , stat : * mut stat ) -> i32 ;
521
540
522
541
/// fstat
523
542
#[ link_name = "sys_fstat" ]
@@ -530,14 +549,21 @@ extern "C" {
530
549
#[ link_name = "sys_malloc" ]
531
550
pub fn malloc ( size : usize , align : usize ) -> * mut u8 ;
532
551
533
- #[ doc( hidden) ]
552
+ #[ link_name = "sys_alloc" ]
553
+ pub fn alloc ( size : usize , align : usize ) -> * mut u8 ;
554
+
555
+ #[ link_name = "sys_alloc_zeroed" ]
556
+ pub fn alloc_zeroed ( size : usize , align : usize ) -> * mut u8 ;
557
+
534
558
#[ link_name = "sys_realloc" ]
535
559
pub fn realloc ( ptr : * mut u8 , size : usize , align : usize , new_size : usize ) -> * mut u8 ;
536
560
537
- #[ doc( hidden) ]
538
561
#[ link_name = "sys_free" ]
539
562
pub fn free ( ptr : * mut u8 , size : usize , align : usize ) ;
540
563
564
+ #[ link_name = "sys_dealloc" ]
565
+ pub fn dealloc ( ptr : * mut u8 , size : usize , align : usize ) ;
566
+
541
567
#[ link_name = "sys_notify" ]
542
568
pub fn notify ( id : usize , count : i32 ) -> i32 ;
543
569
0 commit comments