Skip to content

Commit 0d78fe1

Browse files
committed
Auto merge of #3255 - vita-rust:vita, r=JohnTitor
Fixed vita libc definitions This fixes definitions that were incorrect in my initial PR (#3209). As with the previous one, this relies on open-source newlib implementation and doesn't use Sony internal API's or expose Sony internal data structures. This fixes: - fs API that uses `dirent` and stat - sockets - pthreads A couple of explanations - Unfortunately `dirent` in vita newlib is not very POSIX'y, before `d_name` it has a field with an internal data structure, which is of no use for std (no inodes, no file type inside), so I've just stubbed it as an `__offset`. Also, Vita doesn't expose inodes - `dirent` doesn't have it at all, and in `stat` it is always `0`. I am not sure what would be the best approach here. Maybe I should move the POSIX `dirent` to `generic.rs` and reexpose it in all targets, and redefine it in `vita/mod.rs`? - All pthread types on Vita are pointers, and the backing data structure is allocated by corresponding init functions, so their sizeof's are all 4. I also changed `pthread_attr_t` and `pthread_rwlockattr_t` to reflect their sizes and not be constant. May be in relation to rust-lang/rust#95496 it would be better to move existing thread definitions to generic, and for vita specifically make them pointer types instead of byte arrays. The fixes in std will be in rust-lang/rust#111819
2 parents eb70b7f + 5f569dc commit 0d78fe1

File tree

3 files changed

+83
-28
lines changed

3 files changed

+83
-28
lines changed

src/unix/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub type sighandler_t = ::size_t;
2929
pub type cc_t = ::c_uchar;
3030

3131
cfg_if! {
32-
if #[cfg(any(target_os = "espidf", target_os = "horizon"))] {
32+
if #[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))] {
3333
pub type uid_t = ::c_ushort;
3434
pub type gid_t = ::c_ushort;
3535
} else if #[cfg(target_os = "nto")] {

src/unix/newlib/mod.rs

+35-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
pub type blkcnt_t = i32;
22
pub type blksize_t = i32;
3-
pub type clockid_t = ::c_ulong;
43

54
cfg_if! {
6-
if #[cfg(target_os = "espidf")] {
5+
if #[cfg(target_os = "vita")] {
6+
pub type clockid_t = ::c_uint;
7+
} else {
8+
pub type clockid_t = ::c_ulong;
9+
}
10+
}
11+
12+
cfg_if! {
13+
if #[cfg(any(target_os = "espidf"))] {
714
pub type dev_t = ::c_short;
815
pub type ino_t = ::c_ushort;
916
pub type off_t = ::c_long;
17+
} else if #[cfg(any(target_os = "vita"))] {
18+
pub type dev_t = ::c_short;
19+
pub type ino_t = ::c_ushort;
20+
pub type off_t = ::c_int;
1021
} else {
1122
pub type dev_t = u32;
1223
pub type ino_t = u32;
@@ -160,8 +171,12 @@ s! {
160171
}
161172

162173
pub struct dirent {
174+
#[cfg(not(target_os = "vita"))]
163175
pub d_ino: ino_t,
176+
#[cfg(not(target_os = "vita"))]
164177
pub d_type: ::c_uchar,
178+
#[cfg(target_os = "vita")]
179+
__offset: [u8; 88],
165180
pub d_name: [::c_char; 256usize],
166181
}
167182

@@ -219,12 +234,11 @@ s! {
219234
}
220235

221236
pub struct pthread_attr_t { // Unverified
222-
__size: [u64; 7]
237+
__size: [u64; __SIZEOF_PTHREAD_ATTR_T]
223238
}
224239

225240
pub struct pthread_rwlockattr_t { // Unverified
226-
__lockkind: ::c_int,
227-
__pshared: ::c_int,
241+
__size: [u64; __SIZEOF_PTHREAD_RWLOCKATTR_T]
228242
}
229243
}
230244

@@ -241,6 +255,7 @@ align_const! {
241255
};
242256
}
243257
pub const NCCS: usize = 32;
258+
244259
cfg_if! {
245260
if #[cfg(target_os = "espidf")] {
246261
const __PTHREAD_INITIALIZER_BYTE: u8 = 0xff;
@@ -251,6 +266,17 @@ cfg_if! {
251266
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 8;
252267
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 4;
253268
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 12;
269+
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
270+
} else if #[cfg(target_os = "vita")] {
271+
const __PTHREAD_INITIALIZER_BYTE: u8 = 0xff;
272+
pub const __SIZEOF_PTHREAD_ATTR_T: usize = 4;
273+
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 4;
274+
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
275+
pub const __SIZEOF_PTHREAD_COND_T: usize = 4;
276+
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
277+
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 4;
278+
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 4;
279+
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 4;
254280
} else {
255281
const __PTHREAD_INITIALIZER_BYTE: u8 = 0;
256282
pub const __SIZEOF_PTHREAD_ATTR_T: usize = 56;
@@ -260,9 +286,10 @@ cfg_if! {
260286
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
261287
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
262288
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
289+
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
263290
}
264291
}
265-
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
292+
266293
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
267294
pub const __PTHREAD_MUTEX_HAVE_PREV: usize = 1;
268295
pub const __PTHREAD_RWLOCK_INT_FLAGS_SHARED: usize = 1;
@@ -273,6 +300,8 @@ pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2;
273300
cfg_if! {
274301
if #[cfg(any(target_os = "horizon", target_os = "espidf"))] {
275302
pub const FD_SETSIZE: usize = 64;
303+
} else if #[cfg(target_os = "vita")] {
304+
pub const FD_SETSIZE: usize = 256;
276305
} else {
277306
pub const FD_SETSIZE: usize = 1024;
278307
}

src/unix/newlib/vita/mod.rs

+47-21
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,96 @@ pub type wchar_t = u32;
66
pub type c_long = i32;
77
pub type c_ulong = u32;
88

9+
pub type sigset_t = ::c_ulong;
10+
911
s! {
1012
pub struct sockaddr {
13+
pub sa_len: u8,
1114
pub sa_family: ::sa_family_t,
1215
pub sa_data: [::c_char; 14],
1316
}
1417

1518
pub struct sockaddr_in6 {
19+
pub sin6_len: u8,
1620
pub sin6_family: ::sa_family_t,
1721
pub sin6_port: ::in_port_t,
1822
pub sin6_flowinfo: u32,
1923
pub sin6_addr: ::in6_addr,
24+
pub sin6_vport: ::in_port_t,
2025
pub sin6_scope_id: u32,
2126
}
2227

2328
pub struct sockaddr_in {
29+
pub sin_len: u8,
2430
pub sin_family: ::sa_family_t,
2531
pub sin_port: ::in_port_t,
2632
pub sin_addr: ::in_addr,
27-
pub sin_zero: [u8; 8],
33+
pub sin_vport: ::in_port_t,
34+
pub sin_zero: [u8; 6],
2835
}
2936

3037
pub struct sockaddr_un {
31-
pub sun_len: ::c_uchar,
3238
pub sun_family: ::sa_family_t,
33-
pub sun_path: [::c_char; 104usize],
39+
pub sun_path: [::c_char; 108usize],
3440
}
3541

3642
pub struct sockaddr_storage {
43+
pub ss_len: u8,
3744
pub ss_family: ::sa_family_t,
38-
pub __ss_padding: [u8; 26],
45+
pub __ss_pad1: [u8; 4],
46+
pub __ss_align: i64,
47+
pub __ss_pad2: [u8; 4],
3948
}
4049

41-
4250
pub struct sched_param {
4351
pub sched_priority: ::c_int,
4452
}
53+
54+
pub struct stat {
55+
pub st_dev: ::dev_t,
56+
pub st_ino: ::ino_t,
57+
pub st_mode: ::mode_t,
58+
pub st_nlink: ::nlink_t,
59+
pub st_uid: ::uid_t,
60+
pub st_gid: ::gid_t,
61+
pub st_rdev: ::dev_t,
62+
pub st_size: ::off_t,
63+
pub st_atime: ::time_t,
64+
pub st_mtime: ::time_t,
65+
pub st_ctime: ::time_t,
66+
pub st_blksize: ::blksize_t,
67+
pub st_blocks: ::blkcnt_t,
68+
pub st_spare4: [::c_long; 2usize],
69+
}
4570
}
4671

4772
pub const AF_UNIX: ::c_int = 1;
48-
pub const AF_INET6: ::c_int = 23;
73+
pub const AF_INET6: ::c_int = 24;
4974

50-
pub const FIONBIO: ::c_ulong = 0x8004667e;
75+
pub const FIONBIO: ::c_ulong = 1;
5176

52-
pub const POLLIN: ::c_short = 1;
53-
pub const POLLPRI: ::c_short = 2;
54-
pub const POLLOUT: ::c_short = 4;
55-
pub const POLLERR: ::c_short = 8;
56-
pub const POLLHUP: ::c_short = 16;
57-
pub const POLLNVAL: ::c_short = 32;
77+
pub const POLLIN: ::c_short = 0x0001;
78+
pub const POLLPRI: ::c_short = POLLIN;
79+
pub const POLLOUT: ::c_short = 0x0004;
80+
pub const POLLERR: ::c_short = 0x0008;
81+
pub const POLLHUP: ::c_short = 0x0010;
82+
pub const POLLNVAL: ::c_short = 0x0020;
5883

5984
pub const RTLD_DEFAULT: *mut ::c_void = 0 as *mut ::c_void;
6085

6186
pub const SOL_SOCKET: ::c_int = 0xffff;
87+
pub const SO_NONBLOCK: ::c_int = 0x1100;
6288

6389
pub const MSG_OOB: ::c_int = 0x1;
6490
pub const MSG_PEEK: ::c_int = 0x2;
6591
pub const MSG_DONTROUTE: ::c_int = 0x4;
66-
pub const MSG_WAITALL: ::c_int = 0x8;
67-
pub const MSG_DONTWAIT: ::c_int = 0x10;
68-
pub const MSG_NOSIGNAL: ::c_int = 0x20;
69-
pub const MSG_TRUNC: ::c_int = 0x0100;
70-
pub const MSG_CTRUNC: ::c_int = 0x0200;
92+
pub const MSG_EOR: ::c_int = 0x8;
93+
pub const MSG_TRUNC: ::c_int = 0x10;
94+
pub const MSG_CTRUNC: ::c_int = 0x20;
95+
pub const MSG_WAITALL: ::c_int = 0x40;
96+
pub const MSG_DONTWAIT: ::c_int = 0x80;
97+
pub const MSG_BCAST: ::c_int = 0x100;
98+
pub const MSG_MCAST: ::c_int = 0x200;
7199

72100
pub const UTIME_OMIT: c_long = -1;
73101
pub const AT_FDCWD: ::c_int = -2;
@@ -111,7 +139,7 @@ pub const EAI_OVERFLOW: ::c_int = -12;
111139

112140
pub const _SC_PAGESIZE: ::c_int = 8;
113141
pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 51;
114-
pub const PTHREAD_STACK_MIN: ::size_t = 200;
142+
pub const PTHREAD_STACK_MIN: ::size_t = 32 * 1024;
115143

116144
extern "C" {
117145
pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int;
@@ -171,5 +199,3 @@ extern "C" {
171199

172200
pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int;
173201
}
174-
175-
pub use crate::unix::newlib::generic::{sigset_t, stat};

0 commit comments

Comments
 (0)