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 support for shared memory operations for solaris/illumos #1584

Merged
merged 4 commits into from Nov 28, 2019
Merged
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
65 changes: 65 additions & 0 deletions src/unix/solarish/mod.rs
Expand Up @@ -34,6 +34,7 @@ pub type nl_item = ::c_int;
pub type mqd_t = *mut ::c_void;
pub type id_t = ::c_int;
pub type idtype_t = ::c_uint;
pub type shmatt_t = ::c_ulong;

pub type door_attr_t = ::c_uint;
pub type door_id_t = ::c_ulonglong;
Expand All @@ -57,6 +58,16 @@ s! {
pub imr_interface: in_addr,
}

pub struct ipc_perm {
pub uid: ::uid_t,
pub gid: ::gid_t,
pub cuid: ::uid_t,
pub cgid: ::gid_t,
pub mode: ::mode_t,
pub seq: ::c_uint,
pub key: ::key_t,
}

pub struct sockaddr {
pub sa_family: sa_family_t,
pub sa_data: [::c_char; 14],
Expand Down Expand Up @@ -206,6 +217,33 @@ s! {
pub ai_next: *mut addrinfo,
}

pub struct shmid_ds {
pub shm_perm: ipc_perm,
pub shm_segsz: ::size_t,
#[cfg(target_os = "illumos")]
pub shm_amp: *mut ::c_void,
#[cfg(target_os = "solaris")]
pub shm_flags: ::uintptr_t,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no shm_flags in illumos. This is also at the location where shm_amp would be for illumos. In addition, shm_gransize and shm_allocated are not defined on illumos, and the padding appears to be incorrect for illumos.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/sys/shm.h#L88-L115 shows the illumos definition (as @bgermann said, currently there is no 32-bit support for rust on illumos, so it's probably not necessary to add the 32-bit versions -- if that were to ever happen, it'd probably better be done as its own change since many more things would need to be updated).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IPC_* values are ok -- for likely historical reasons lost to time, the values are defined in octal on illumos (but appear to match what you have)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes, so forget about that.

pub shm_lkcnt: ::c_ushort,
pub shm_lpid: ::pid_t,
pub shm_cpid: ::pid_t,
pub shm_nattch: ::shmatt_t,
pub shm_cnattch: ::c_ulong,
pub shm_atime: ::time_t,
pub shm_dtime: ::time_t,
pub shm_ctime: ::time_t,
#[cfg(target_os = "illumos")]
pub shm_pad4: [i64; 4],
#[cfg(target_os = "solaris")]
pub shm_amp: *mut ::c_void,
#[cfg(target_os = "solaris")]
pub shm_gransize: u64,
#[cfg(target_os = "solaris")]
pub shm_allocated: u64,
#[cfg(target_os = "solaris")]
pub shm_pad4: [i64; 1],
}

pub struct sigset_t {
bits: [u32; 4],
}
Expand Down Expand Up @@ -981,6 +1019,7 @@ pub const MAP_PRIVATE: ::c_int = 0x0002;
pub const MAP_FIXED: ::c_int = 0x0010;
pub const MAP_NORESERVE: ::c_int = 0x40;
pub const MAP_ANON: ::c_int = 0x0100;
pub const MAP_ANONYMOUS: ::c_int = 0x0100;
pub const MAP_RENAME: ::c_int = 0x20;
pub const MAP_ALIGN: ::c_int = 0x200;
pub const MAP_TEXT: ::c_int = 0x400;
Expand Down Expand Up @@ -1352,6 +1391,16 @@ pub const IFF_VIRTUAL: ::c_longlong = 0x2000000000; // Cannot send/receive pkts
pub const IFF_DUPLICATE: ::c_longlong = 0x4000000000; // Local address in use
pub const IFF_IPMP: ::c_longlong = 0x8000000000; // IPMP IP interface

// sys/ipc.h:
pub const IPC_ALLOC: ::c_int = 0x8000;
pub const IPC_CREAT: ::c_int = 0x200;
pub const IPC_EXCL: ::c_int = 0x400;
pub const IPC_NOWAIT: ::c_int = 0x800;
pub const IPC_PRIVATE: key_t = 0;
pub const IPC_RMID: ::c_int = 10;
pub const IPC_SET: ::c_int = 11;
pub const IPC_SEAT: ::c_int = 12;

pub const SHUT_RD: ::c_int = 0;
pub const SHUT_WR: ::c_int = 1;
pub const SHUT_RDWR: ::c_int = 2;
Expand Down Expand Up @@ -2011,6 +2060,22 @@ extern "C" {
advice: ::c_int,
) -> ::c_int;

pub fn shmat(
shmid: ::c_int,
shmaddr: *const ::c_void,
shmflg: ::c_int,
) -> *mut ::c_void;

pub fn shmctl(
shmid: ::c_int,
cmd: ::c_int,
buf: *mut ::shmid_ds,
) -> ::c_int;

pub fn shmdt(shmaddr: *const ::c_void) -> ::c_int;

pub fn shmget(key: key_t, size: ::size_t, shmflg: ::c_int) -> ::c_int;

pub fn shm_open(
name: *const ::c_char,
oflag: ::c_int,
Expand Down