Skip to content

Commit

Permalink
Fixed vita libc definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
nikarh committed May 26, 2023
1 parent eb70b7f commit 5f569dc
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub type sighandler_t = ::size_t;
pub type cc_t = ::c_uchar;

cfg_if! {
if #[cfg(any(target_os = "espidf", target_os = "horizon"))] {
if #[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))] {
pub type uid_t = ::c_ushort;
pub type gid_t = ::c_ushort;
} else if #[cfg(target_os = "nto")] {
Expand Down
41 changes: 35 additions & 6 deletions src/unix/newlib/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
pub type blkcnt_t = i32;
pub type blksize_t = i32;
pub type clockid_t = ::c_ulong;

cfg_if! {
if #[cfg(target_os = "espidf")] {
if #[cfg(target_os = "vita")] {
pub type clockid_t = ::c_uint;
} else {
pub type clockid_t = ::c_ulong;
}
}

cfg_if! {
if #[cfg(any(target_os = "espidf"))] {
pub type dev_t = ::c_short;
pub type ino_t = ::c_ushort;
pub type off_t = ::c_long;
} else if #[cfg(any(target_os = "vita"))] {
pub type dev_t = ::c_short;
pub type ino_t = ::c_ushort;
pub type off_t = ::c_int;
} else {
pub type dev_t = u32;
pub type ino_t = u32;
Expand Down Expand Up @@ -160,8 +171,12 @@ s! {
}

pub struct dirent {
#[cfg(not(target_os = "vita"))]
pub d_ino: ino_t,
#[cfg(not(target_os = "vita"))]
pub d_type: ::c_uchar,
#[cfg(target_os = "vita")]
__offset: [u8; 88],
pub d_name: [::c_char; 256usize],
}

Expand Down Expand Up @@ -219,12 +234,11 @@ s! {
}

pub struct pthread_attr_t { // Unverified
__size: [u64; 7]
__size: [u64; __SIZEOF_PTHREAD_ATTR_T]
}

pub struct pthread_rwlockattr_t { // Unverified
__lockkind: ::c_int,
__pshared: ::c_int,
__size: [u64; __SIZEOF_PTHREAD_RWLOCKATTR_T]
}
}

Expand All @@ -241,6 +255,7 @@ align_const! {
};
}
pub const NCCS: usize = 32;

cfg_if! {
if #[cfg(target_os = "espidf")] {
const __PTHREAD_INITIALIZER_BYTE: u8 = 0xff;
Expand All @@ -251,6 +266,17 @@ cfg_if! {
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 8;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 4;
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 12;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
} else if #[cfg(target_os = "vita")] {
const __PTHREAD_INITIALIZER_BYTE: u8 = 0xff;
pub const __SIZEOF_PTHREAD_ATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_COND_T: usize = 4;
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 4;
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 4;
} else {
const __PTHREAD_INITIALIZER_BYTE: u8 = 0;
pub const __SIZEOF_PTHREAD_ATTR_T: usize = 56;
Expand All @@ -260,9 +286,10 @@ cfg_if! {
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
}
}
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;

pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
pub const __PTHREAD_MUTEX_HAVE_PREV: usize = 1;
pub const __PTHREAD_RWLOCK_INT_FLAGS_SHARED: usize = 1;
Expand All @@ -273,6 +300,8 @@ pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2;
cfg_if! {
if #[cfg(any(target_os = "horizon", target_os = "espidf"))] {
pub const FD_SETSIZE: usize = 64;
} else if #[cfg(target_os = "vita")] {
pub const FD_SETSIZE: usize = 256;
} else {
pub const FD_SETSIZE: usize = 1024;
}
Expand Down
68 changes: 47 additions & 21 deletions src/unix/newlib/vita/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,96 @@ pub type wchar_t = u32;
pub type c_long = i32;
pub type c_ulong = u32;

pub type sigset_t = ::c_ulong;

s! {
pub struct sockaddr {
pub sa_len: u8,
pub sa_family: ::sa_family_t,
pub sa_data: [::c_char; 14],
}

pub struct sockaddr_in6 {
pub sin6_len: u8,
pub sin6_family: ::sa_family_t,
pub sin6_port: ::in_port_t,
pub sin6_flowinfo: u32,
pub sin6_addr: ::in6_addr,
pub sin6_vport: ::in_port_t,
pub sin6_scope_id: u32,
}

pub struct sockaddr_in {
pub sin_len: u8,
pub sin_family: ::sa_family_t,
pub sin_port: ::in_port_t,
pub sin_addr: ::in_addr,
pub sin_zero: [u8; 8],
pub sin_vport: ::in_port_t,
pub sin_zero: [u8; 6],
}

pub struct sockaddr_un {
pub sun_len: ::c_uchar,
pub sun_family: ::sa_family_t,
pub sun_path: [::c_char; 104usize],
pub sun_path: [::c_char; 108usize],
}

pub struct sockaddr_storage {
pub ss_len: u8,
pub ss_family: ::sa_family_t,
pub __ss_padding: [u8; 26],
pub __ss_pad1: [u8; 4],
pub __ss_align: i64,
pub __ss_pad2: [u8; 4],
}


pub struct sched_param {
pub sched_priority: ::c_int,
}

pub struct stat {
pub st_dev: ::dev_t,
pub st_ino: ::ino_t,
pub st_mode: ::mode_t,
pub st_nlink: ::nlink_t,
pub st_uid: ::uid_t,
pub st_gid: ::gid_t,
pub st_rdev: ::dev_t,
pub st_size: ::off_t,
pub st_atime: ::time_t,
pub st_mtime: ::time_t,
pub st_ctime: ::time_t,
pub st_blksize: ::blksize_t,
pub st_blocks: ::blkcnt_t,
pub st_spare4: [::c_long; 2usize],
}
}

pub const AF_UNIX: ::c_int = 1;
pub const AF_INET6: ::c_int = 23;
pub const AF_INET6: ::c_int = 24;

pub const FIONBIO: ::c_ulong = 0x8004667e;
pub const FIONBIO: ::c_ulong = 1;

pub const POLLIN: ::c_short = 1;
pub const POLLPRI: ::c_short = 2;
pub const POLLOUT: ::c_short = 4;
pub const POLLERR: ::c_short = 8;
pub const POLLHUP: ::c_short = 16;
pub const POLLNVAL: ::c_short = 32;
pub const POLLIN: ::c_short = 0x0001;
pub const POLLPRI: ::c_short = POLLIN;
pub const POLLOUT: ::c_short = 0x0004;
pub const POLLERR: ::c_short = 0x0008;
pub const POLLHUP: ::c_short = 0x0010;
pub const POLLNVAL: ::c_short = 0x0020;

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

pub const SOL_SOCKET: ::c_int = 0xffff;
pub const SO_NONBLOCK: ::c_int = 0x1100;

pub const MSG_OOB: ::c_int = 0x1;
pub const MSG_PEEK: ::c_int = 0x2;
pub const MSG_DONTROUTE: ::c_int = 0x4;
pub const MSG_WAITALL: ::c_int = 0x8;
pub const MSG_DONTWAIT: ::c_int = 0x10;
pub const MSG_NOSIGNAL: ::c_int = 0x20;
pub const MSG_TRUNC: ::c_int = 0x0100;
pub const MSG_CTRUNC: ::c_int = 0x0200;
pub const MSG_EOR: ::c_int = 0x8;
pub const MSG_TRUNC: ::c_int = 0x10;
pub const MSG_CTRUNC: ::c_int = 0x20;
pub const MSG_WAITALL: ::c_int = 0x40;
pub const MSG_DONTWAIT: ::c_int = 0x80;
pub const MSG_BCAST: ::c_int = 0x100;
pub const MSG_MCAST: ::c_int = 0x200;

pub const UTIME_OMIT: c_long = -1;
pub const AT_FDCWD: ::c_int = -2;
Expand Down Expand Up @@ -111,7 +139,7 @@ pub const EAI_OVERFLOW: ::c_int = -12;

pub const _SC_PAGESIZE: ::c_int = 8;
pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 51;
pub const PTHREAD_STACK_MIN: ::size_t = 200;
pub const PTHREAD_STACK_MIN: ::size_t = 32 * 1024;

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

pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int;
}

pub use crate::unix::newlib::generic::{sigset_t, stat};

0 comments on commit 5f569dc

Please sign in to comment.