@@ -168,43 +168,105 @@ pub struct msghdr {
168168
169169#[ repr( C ) ]
170170pub struct pollfd {
171- pub fd : c_int ,
171+ pub fd : fd_t ,
172172 pub events : i16 ,
173173 pub revents : i16 ,
174174}
175175
176+ #[ cfg( target_arch = "x86" ) ]
177+ mod arch {
178+ use super :: * ;
179+
180+ pub type nlink_t = u32 ;
181+ pub type blksize_t = i32 ;
182+ pub type time_t = i32 ;
183+ pub type time_nsec_t = i32 ;
184+
185+ #[ repr( C ) ]
186+ pub struct stat {
187+ pub dev : dev_t ,
188+ __dev_padding : u32 ,
189+ __ino_truncated : u32 ,
190+
191+ pub mode : mode_t ,
192+ pub nlink : nlink_t ,
193+ pub uid : uid_t ,
194+ pub gid : gid_t ,
195+ pub rdev : dev_t ,
196+ __rdev_padding : u32 ,
197+
198+ pub size : off_t ,
199+ pub blksize : blksize_t ,
200+ pub blocks : blkcnt_t ,
201+
202+ pub atime : timespec ,
203+ pub mtime : timespec ,
204+ pub ctime : timespec ,
205+
206+ pub ino : ino_t ,
207+ }
208+ }
209+
210+ #[ cfg( target_arch = "x86_64" ) ]
211+ mod arch {
212+ use super :: * ;
213+
214+ pub type nlink_t = u64 ;
215+ pub type blksize_t = i64 ;
216+ pub type time_t = i64 ;
217+ pub type time_nsec_t = i64 ;
218+
219+ #[ repr( C ) ]
220+ pub struct stat {
221+ pub dev : dev_t ,
222+ pub ino : ino_t ,
223+ pub nlink : nlink_t ,
224+
225+ pub mode : mode_t ,
226+ pub uid : uid_t ,
227+ pub gid : gid_t ,
228+ __pad0 : u32 ,
229+ pub rdev : dev_t ,
230+ pub size : off_t ,
231+ pub blksize : blksize_t ,
232+ pub blocks : blkcnt_t ,
233+
234+ pub atime : timespec ,
235+ pub mtime : timespec ,
236+ pub ctime : timespec ,
237+ __unused : [ i64 ; 3 ] ,
238+ }
239+ }
240+
176241pub type dev_t = u64 ;
177242pub type ino_t = u64 ;
178- pub type nlink_t = u64 ;
243+ pub type nlink_t = arch :: nlink_t ;
179244pub type uid_t = u32 ;
180245pub type gid_t = u32 ;
181246pub type off_t = i64 ;
182- pub type blksize_t = i64 ;
247+ pub type blksize_t = arch :: blksize_t ;
183248pub type blkcnt_t = i64 ;
184- pub type time_t = i64 ;
249+ pub type time_t = arch:: time_t ;
250+ pub type time_nsec_t = arch:: time_nsec_t ;
185251
186252#[ repr( C ) ]
187- pub struct stat {
188- pub st_dev : dev_t ,
189- pub st_ino : ino_t ,
190- pub st_nlink : nlink_t ,
191- pub st_mode : mode_t ,
192- pub st_uid : uid_t ,
193- pub st_gid : gid_t ,
194- __pad0 : c_int ,
195- pub st_rdev : dev_t ,
196- pub st_size : off_t ,
197- pub st_blksize : blksize_t ,
198- pub st_blocks : blkcnt_t ,
199- pub st_atime : time_t ,
200- pub st_atime_nsec : i64 ,
201- pub st_mtime : time_t ,
202- pub st_mtime_nsec : i64 ,
203- pub st_ctime : time_t ,
204- pub st_ctime_nsec : i64 ,
205- __unused : [ i64 ; 3 ] ,
253+ pub struct kernel_timespec {
254+ sec : i64 ,
255+ nsec : i64 ,
206256}
207257
258+ #[ cfg( not( target_arch = "riscv32" ) ) ]
259+ #[ repr( C ) ]
260+ pub struct timespec {
261+ sec : isize ,
262+ nsec : isize ,
263+ }
264+
265+ #[ cfg( target_arch = "riscv32" ) ]
266+ pub type timespec = kernel_timespec ;
267+
268+ pub type stat = arch:: stat ;
269+
208270#[ link( name = "linux" , kind = "static" ) ]
209271unsafe extern "C" {
210272 pub fn linux_syscall_epoll_create1 ( flags : u32 ) -> usize ;
@@ -236,7 +298,7 @@ unsafe extern "C" {
236298 pub fn linux_syscall_send ( socket : fd_t , buf : * const u8 , len : usize , flags : u32 ) -> usize ;
237299 pub fn linux_syscall_recv ( socket : fd_t , buf : * mut u8 , len : usize , flags : u32 ) -> usize ;
238300
239- pub fn linux_syscall_sendmsg ( fd : fd_t , msg : * const msghdr , flags : u32 ) -> usize ;
301+ pub fn linux_syscall_sendmsg ( fd : fd_t , msg : & msghdr , flags : u32 ) -> usize ;
240302 pub fn linux_syscall_recvmsg ( fd : fd_t , msg : & mut MaybeUninit < msghdr > , flags : u32 ) -> usize ;
241303
242304 pub fn linux_syscall_socketpair (
@@ -246,7 +308,7 @@ unsafe extern "C" {
246308 socket_vector : & mut [ fd_t ; 2 ] ,
247309 ) -> usize ;
248310
249- pub fn linux_syscall_ftruncate ( fd : fd_t , length : i64 ) -> usize ;
311+ pub fn linux_syscall_ftruncate ( fd : fd_t , length : off_t ) -> usize ;
250312
251313 pub fn linux_syscall_fcntl ( fd : fd_t , cmd : i32 , arg : usize ) -> usize ;
252314
@@ -271,7 +333,7 @@ unsafe extern "C" {
271333 sockfd : fd_t ,
272334 level : i32 ,
273335 optname : u32 ,
274- optval : * mut u8 ,
336+ optval : NonNull < u8 > ,
275337 optlen : & mut socklen_t ,
276338 ) -> usize ;
277339 pub fn linux_syscall_setsockopt (
@@ -292,11 +354,11 @@ unsafe extern "C" {
292354
293355 pub fn linux_syscall_dup ( fd : fd_t ) -> usize ;
294356
295- pub fn linux_syscall_getpid ( ) -> pid_t ;
296-
297357 /// `path` must be non-null.
298358 pub fn linux_syscall_unlink ( path : * const u8 ) -> usize ;
299359
360+ pub fn linux_syscall_getpid ( ) -> pid_t ;
361+
300362 pub fn linux_helper_temp_dir ( buf : iovec ) -> usize ;
301363}
302364
@@ -458,7 +520,13 @@ pub fn getsockopt(
458520) -> Result < u32 , io:: Error > {
459521 let mut len_out = optval. len ( ) . try_into ( ) . map_err ( io:: Error :: other) ?;
460522 let rc = unsafe {
461- linux_syscall_getsockopt ( sockfd, level, optname, optval. as_mut_ptr ( ) , & mut len_out)
523+ linux_syscall_getsockopt (
524+ sockfd,
525+ level,
526+ optname,
527+ NonNull :: from ( optval) . cast :: < u8 > ( ) ,
528+ & mut len_out,
529+ )
462530 } ;
463531 check_error ( rc) ?;
464532 Ok ( len_out)
0 commit comments