Skip to content

Commit 8b58e8d

Browse files
committed
Auto merge of #3284 - pheki:add-vita-definitions, r=JohnTitor
Add missing PS Vita definitions, fix some unused ones This PR improves vita's newlib support for std by adding some missing definitions and fixing some duplicated ones (e.g. `EAI_NONAME` from `src/unix/newlib/vita/mod.rs` was not being used as it was already defined on `src/unix/newlib/mod.rs`) Previous work: #3209 #3255 cc `@nikarh`
2 parents c393de3 + 3c0b407 commit 8b58e8d

File tree

4 files changed

+102
-40
lines changed

4 files changed

+102
-40
lines changed

src/unix/mod.rs

+19-11
Original file line numberDiff line numberDiff line change
@@ -678,17 +678,6 @@ extern "C" {
678678
value: *const ::c_void,
679679
option_len: socklen_t,
680680
) -> ::c_int;
681-
#[cfg_attr(
682-
all(target_os = "macos", target_arch = "x86"),
683-
link_name = "socketpair$UNIX2003"
684-
)]
685-
#[cfg_attr(target_os = "illumos", link_name = "__xnet_socketpair")]
686-
pub fn socketpair(
687-
domain: ::c_int,
688-
type_: ::c_int,
689-
protocol: ::c_int,
690-
socket_vector: *mut ::c_int,
691-
) -> ::c_int;
692681
#[cfg(not(all(
693682
libc_cfg_target_vendor,
694683
target_arch = "powerpc",
@@ -1408,6 +1397,25 @@ extern "C" {
14081397
pub fn lockf(fd: ::c_int, cmd: ::c_int, len: ::off_t) -> ::c_int;
14091398

14101399
}
1400+
1401+
cfg_if! {
1402+
if #[cfg(not(target_os = "vita"))] {
1403+
extern "C" {
1404+
#[cfg_attr(
1405+
all(target_os = "macos", target_arch = "x86"),
1406+
link_name = "socketpair$UNIX2003"
1407+
)]
1408+
#[cfg_attr(target_os = "illumos", link_name = "__xnet_socketpair")]
1409+
pub fn socketpair(
1410+
domain: ::c_int,
1411+
type_: ::c_int,
1412+
protocol: ::c_int,
1413+
socket_vector: *mut ::c_int,
1414+
) -> ::c_int;
1415+
}
1416+
}
1417+
}
1418+
14111419
cfg_if! {
14121420
if #[cfg(not(any(target_os = "emscripten",
14131421
target_os = "android",

src/unix/newlib/dirent.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
s! {
2+
pub struct dirent {
3+
pub d_ino: ::ino_t,
4+
pub d_type: ::c_uchar,
5+
pub d_name: [::c_char; 256usize],
6+
}
7+
}

src/unix/newlib/mod.rs

+43-27
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
pub type blkcnt_t = i32;
22
pub type blksize_t = i32;
33

4-
cfg_if! {
5-
if #[cfg(target_os = "vita")] {
6-
pub type clockid_t = ::c_uint;
7-
} else {
8-
pub type clockid_t = ::c_ulong;
9-
}
10-
}
4+
pub type clockid_t = ::c_ulong;
115

126
cfg_if! {
137
if #[cfg(any(target_os = "espidf"))] {
@@ -170,16 +164,6 @@ s! {
170164
pub sa_flags: ::c_int,
171165
}
172166

173-
pub struct dirent {
174-
#[cfg(not(target_os = "vita"))]
175-
pub d_ino: ino_t,
176-
#[cfg(not(target_os = "vita"))]
177-
pub d_type: ::c_uchar,
178-
#[cfg(target_os = "vita")]
179-
__offset: [u8; 88],
180-
pub d_name: [::c_char; 256usize],
181-
}
182-
183167
pub struct stack_t {
184168
pub ss_sp: *mut ::c_void,
185169
pub ss_flags: ::c_int,
@@ -546,8 +530,16 @@ pub const IFF_LINK2: ::c_int = 0x4000; // per link layer defined bit
546530
pub const IFF_ALTPHYS: ::c_int = IFF_LINK2; // use alternate physical connection
547531
pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast
548532

549-
pub const TCP_NODELAY: ::c_int = 8193;
550-
pub const TCP_MAXSEG: ::c_int = 8194;
533+
cfg_if! {
534+
if #[cfg(target_os = "vita")] {
535+
pub const TCP_NODELAY: ::c_int = 1;
536+
pub const TCP_MAXSEG: ::c_int = 2;
537+
} else {
538+
pub const TCP_NODELAY: ::c_int = 8193;
539+
pub const TCP_MAXSEG: ::c_int = 8194;
540+
}
541+
}
542+
551543
pub const TCP_NOPUSH: ::c_int = 4;
552544
pub const TCP_NOOPT: ::c_int = 8;
553545
pub const TCP_KEEPIDLE: ::c_int = 256;
@@ -561,13 +553,25 @@ cfg_if! {
561553
pub const IP_TOS: ::c_int = 3;
562554
}
563555
}
564-
pub const IP_TTL: ::c_int = 8;
556+
cfg_if! {
557+
if #[cfg(target_os = "vita")] {
558+
pub const IP_TTL: ::c_int = 4;
559+
} else {
560+
pub const IP_TTL: ::c_int = 8;
561+
}
562+
}
565563
pub const IP_MULTICAST_IF: ::c_int = 9;
566564
pub const IP_MULTICAST_TTL: ::c_int = 10;
567565
pub const IP_MULTICAST_LOOP: ::c_int = 11;
568-
pub const IP_ADD_MEMBERSHIP: ::c_int = 11;
569-
pub const IP_DROP_MEMBERSHIP: ::c_int = 12;
570-
566+
cfg_if! {
567+
if #[cfg(target_os = "vita")] {
568+
pub const IP_ADD_MEMBERSHIP: ::c_int = 12;
569+
pub const IP_DROP_MEMBERSHIP: ::c_int = 13;
570+
} else {
571+
pub const IP_ADD_MEMBERSHIP: ::c_int = 11;
572+
pub const IP_DROP_MEMBERSHIP: ::c_int = 12;
573+
}
574+
}
571575
pub const IPV6_UNICAST_HOPS: ::c_int = 4;
572576
pub const IPV6_MULTICAST_IF: ::c_int = 9;
573577
pub const IPV6_MULTICAST_HOPS: ::c_int = 10;
@@ -598,10 +602,15 @@ pub const NI_NAMEREQD: ::c_int = 4;
598602
pub const NI_NUMERICSERV: ::c_int = 0;
599603
pub const NI_DGRAM: ::c_int = 0;
600604

601-
pub const EAI_FAMILY: ::c_int = -303;
602-
pub const EAI_MEMORY: ::c_int = -304;
603-
pub const EAI_NONAME: ::c_int = -305;
604-
pub const EAI_SOCKTYPE: ::c_int = -307;
605+
cfg_if! {
606+
// Defined in vita/mod.rs for "vita"
607+
if #[cfg(not(target_os = "vita"))] {
608+
pub const EAI_FAMILY: ::c_int = -303;
609+
pub const EAI_MEMORY: ::c_int = -304;
610+
pub const EAI_NONAME: ::c_int = -305;
611+
pub const EAI_SOCKTYPE: ::c_int = -307;
612+
}
613+
}
605614

606615
pub const EXIT_SUCCESS: ::c_int = 0;
607616
pub const EXIT_FAILURE: ::c_int = 1;
@@ -777,6 +786,13 @@ cfg_if! {
777786
}
778787
}
779788

789+
cfg_if! {
790+
if #[cfg(not(target_os = "vita"))] {
791+
mod dirent;
792+
pub use self::dirent::*;
793+
}
794+
}
795+
780796
cfg_if! {
781797
if #[cfg(libc_align)] {
782798
#[macro_use]

src/unix/newlib/vita/mod.rs

+33-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ pub type c_ulong = u32;
99
pub type sigset_t = ::c_ulong;
1010

1111
s! {
12+
pub struct msghdr {
13+
pub msg_name: *mut ::c_void,
14+
pub msg_namelen: ::socklen_t,
15+
pub msg_iov: *mut ::iovec,
16+
pub msg_iovlen: ::c_int,
17+
pub msg_control: *mut ::c_void,
18+
pub msg_controllen: ::socklen_t,
19+
pub msg_flags: ::c_int,
20+
}
21+
1222
pub struct sockaddr {
1323
pub sa_len: u8,
1424
pub sa_family: ::sa_family_t,
@@ -35,16 +45,17 @@ s! {
3545
}
3646

3747
pub struct sockaddr_un {
48+
pub ss_len: u8,
3849
pub sun_family: ::sa_family_t,
3950
pub sun_path: [::c_char; 108usize],
4051
}
4152

4253
pub struct sockaddr_storage {
4354
pub ss_len: u8,
4455
pub ss_family: ::sa_family_t,
45-
pub __ss_pad1: [u8; 4],
56+
pub __ss_pad1: [u8; 2],
4657
pub __ss_align: i64,
47-
pub __ss_pad2: [u8; 4],
58+
pub __ss_pad2: [u8; 116],
4859
}
4960

5061
pub struct sched_param {
@@ -67,16 +78,31 @@ s! {
6778
pub st_blocks: ::blkcnt_t,
6879
pub st_spare4: [::c_long; 2usize],
6980
}
81+
82+
#[repr(align(8))]
83+
pub struct dirent {
84+
__offset: [u8; 88],
85+
pub d_name: [::c_char; 256usize],
86+
__pad: [u8; 8],
87+
}
7088
}
7189

7290
pub const AF_UNIX: ::c_int = 1;
7391
pub const AF_INET6: ::c_int = 24;
7492

93+
pub const SOCK_RAW: ::c_int = 3;
94+
pub const SOCK_RDM: ::c_int = 4;
95+
pub const SOCK_SEQPACKET: ::c_int = 5;
96+
7597
pub const FIONBIO: ::c_ulong = 1;
7698

7799
pub const POLLIN: ::c_short = 0x0001;
78100
pub const POLLPRI: ::c_short = POLLIN;
79101
pub const POLLOUT: ::c_short = 0x0004;
102+
pub const POLLRDNORM: ::c_short = POLLIN;
103+
pub const POLLRDBAND: ::c_short = POLLIN;
104+
pub const POLLWRNORM: ::c_short = POLLOUT;
105+
pub const POLLWRBAND: ::c_short = POLLOUT;
80106
pub const POLLERR: ::c_short = 0x0008;
81107
pub const POLLHUP: ::c_short = 0x0010;
82108
pub const POLLNVAL: ::c_short = 0x0020;
@@ -141,11 +167,16 @@ pub const _SC_PAGESIZE: ::c_int = 8;
141167
pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 51;
142168
pub const PTHREAD_STACK_MIN: ::size_t = 32 * 1024;
143169

170+
pub const IP_HDRINCL: ::c_int = 2;
171+
144172
extern "C" {
145173
pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int;
146174
pub fn writev(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t;
147175
pub fn readv(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t;
148176

177+
pub fn sendmsg(s: ::c_int, msg: *const ::msghdr, flags: ::c_int) -> ::ssize_t;
178+
pub fn recvmsg(s: ::c_int, msg: *mut ::msghdr, flags: ::c_int) -> ::ssize_t;
179+
149180
pub fn pthread_create(
150181
native: *mut ::pthread_t,
151182
attr: *const ::pthread_attr_t,

0 commit comments

Comments
 (0)