Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add constants and structs for vsock on macos #3258

Merged
merged 1 commit into from Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions libc-test/build.rs
Expand Up @@ -283,6 +283,7 @@ fn test_apple(target: &str) {
"sys/uio.h",
"sys/un.h",
"sys/utsname.h",
"sys/vsock.h",
"sys/wait.h",
"sys/xattr.h",
"syslog.h",
Expand Down
66 changes: 66 additions & 0 deletions src/unix/bsd/apple/mod.rs
Expand Up @@ -1381,6 +1381,15 @@ s_no_extra_traits! {
pub struct os_unfair_lock_s {
_os_unfair_lock_opaque: u32,
}

#[cfg_attr(libc_packedN, repr(packed(1)))]
pub struct sockaddr_vm {
pub svm_len: ::c_uchar,
pub svm_family: ::sa_family_t,
pub svm_reserved1: ::c_ushort,
pub svm_port: ::c_uint,
pub svm_cid: ::c_uint,
}
}

impl siginfo_t {
Expand Down Expand Up @@ -2683,6 +2692,52 @@ cfg_if! {
self._os_unfair_lock_opaque.hash(state);
}
}

impl PartialEq for sockaddr_vm {
fn eq(&self, other: &sockaddr_vm) -> bool {
self.svm_len == other.svm_len
&& self.svm_family == other.svm_family
&& self.svm_reserved1 == other.svm_reserved1
&& self.svm_port == other.svm_port
&& self.svm_cid == other.svm_cid
}
}

impl Eq for sockaddr_vm {}

impl ::fmt::Debug for sockaddr_vm {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
let svm_len = self.svm_len;
let svm_family = self.svm_family;
let svm_reserved1 = self.svm_reserved1;
let svm_port = self.svm_port;
let svm_cid = self.svm_cid;

f.debug_struct("sockaddr_vm")
.field("svm_len",&svm_len)
.field("svm_family",&svm_family)
.field("svm_reserved1",&svm_reserved1)
.field("svm_port",&svm_port)
.field("svm_cid",&svm_cid)
.finish()
}
}

impl ::hash::Hash for sockaddr_vm {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
let svm_len = self.svm_len;
let svm_family = self.svm_family;
let svm_reserved1 = self.svm_reserved1;
let svm_port = self.svm_port;
let svm_cid = self.svm_cid;

svm_len.hash(state);
svm_family.hash(state);
svm_reserved1.hash(state);
svm_port.hash(state);
svm_cid.hash(state);
}
}
}
}

Expand Down Expand Up @@ -3644,6 +3699,9 @@ pub const AF_SYSTEM: ::c_int = 32;
pub const AF_NETBIOS: ::c_int = 33;
pub const AF_PPP: ::c_int = 34;
pub const pseudo_AF_HDRCMPLT: ::c_int = 35;
pub const AF_IEEE80211: ::c_int = 37;
pub const AF_UTUN: ::c_int = 38;
pub const AF_VSOCK: ::c_int = 40;
pub const AF_SYS_CONTROL: ::c_int = 2;

pub const SYSPROTO_EVENT: ::c_int = 1;
Expand Down Expand Up @@ -3685,6 +3743,7 @@ pub const PF_NATM: ::c_int = AF_NATM;
pub const PF_SYSTEM: ::c_int = AF_SYSTEM;
pub const PF_NETBIOS: ::c_int = AF_NETBIOS;
pub const PF_PPP: ::c_int = AF_PPP;
pub const PF_VSOCK: ::c_int = AF_VSOCK;

pub const NET_RT_DUMP: ::c_int = 1;
pub const NET_RT_FLAGS: ::c_int = 2;
Expand Down Expand Up @@ -5002,6 +5061,13 @@ pub const SSTOP: u32 = 4;
/// Awaiting collection by parent.
pub const SZOMB: u32 = 5;

// sys/vsock.h
pub const VMADDR_CID_ANY: ::c_uint = 0xFFFFFFFF;
pub const VMADDR_CID_HYPERVISOR: ::c_uint = 0;
pub const VMADDR_CID_RESERVED: ::c_uint = 1;
pub const VMADDR_CID_HOST: ::c_uint = 2;
pub const VMADDR_PORT_ANY: ::c_uint = 0xFFFFFFFF;

cfg_if! {
if #[cfg(libc_const_extern_fn)] {
const fn __DARWIN_ALIGN32(p: usize) -> usize {
Expand Down