Skip to content

Add basic support for System V shm #7214

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

Closed
wants to merge 4 commits into from
Closed

Add basic support for System V shm #7214

wants to merge 4 commits into from

Conversation

Aransentin
Copy link
Contributor

System V shared memory is kinda legacy cruft, having been supplanted by POSIX shared memory. Still, it's needed for some legacy applications; most notably X11 which uses it as a performant way of sharing pixel data with clients.

I did not add the IPC_STAT structs (e.g. shmid_ds), as they are even more useless and "broken" on Linux. The structs were specified wrongly on Linux a long time ago so they are incompatible with the standard, but not changed in the kernel due to not breaking backwards compatibility with ancient libcs.

@LemonBoy
Copy link
Contributor

A basic test in os/linux/test.zig is needed, something that creates a key with shmget, fetch it with shmat and remove it with shmctl w/ IPC_RMID.

@Aransentin
Copy link
Contributor Author

A basic test in os/linux/test.zig is needed

shmget(IPC_PRIVATE, 4096, IPC_CREAT|000) = 98328
shmat(98328, NULL, 0)                   = 0x7feb5b3c9000
shmdt(0x7feb5b3c9000)                   = 0
shmctl(98328, IPC_RMID, NULL)           = 0

@Aransentin
Copy link
Contributor Author

Seems the CI server didn't like it. Hm. Hold on while I investigate.

@LemonBoy
Copy link
Contributor

shmget(IPC_PRIVATE, 4096, IPC_CREAT|000) = 98328

You're passing 0o000 as permission parameter...

@Aransentin
Copy link
Contributor Author

shmget(IPC_PRIVATE, 4096, IPC_CREAT|000) = 98328

You're passing 0o000 as permission parameter...

Yeah, I ran the test as root so I didn't notice. Fixed!

@LemonBoy
Copy link
Contributor

Hmm, I just checked a few man pages and it seems the whole SHM api is well-supported across the board.
If you add the libc definitions in lib/std/c.zig the API will be available even when the libc is linked in (using the libc functions rather than our syscall stubs) and for BSDs too. The test can be moved to lib/std/os/test.zig using std.os.system to make it cross platform (I guess wasi and windows targets should be skipped).

@Aransentin
Copy link
Contributor Author

Creating a proper wrapper in os.zig and not just having thin syscall wrappers is going to be moderately complicated; the same libc function maps to different syscalls (sys_ipc...) depending on architecture for non-recent kernels. I'll close the PR for now and get back to you with a proper implementation when I have time for it.

@Aransentin Aransentin closed this Nov 25, 2020
@LemonBoy
Copy link
Contributor

Creating a proper wrapper in os.zig and not just having thin syscall wrappers is going to be moderately complicated;

No, a wrapper in os.zig is definitely the worst possible decision (see #6600).

he same libc function maps to different syscalls (sys_ipc...) depending on architecture for non-recent kernels.

Alright, I can't find what kernel deprecated sys_ipc on the "old" arches we support (mips/i386 iirc), you may want to use that for maximum compatibility as we already do with socketcall.

The libc wrappers don't do much beside calling the right syscall, except for shmctl that you didn't implement anyway.

@Aransentin
Copy link
Contributor Author

@LemonBoy Where would you like the wrapper around linux/BSD shm (that chooses the correct syscall & translates errors) to be until the os.zig situation is resolved?

RossComputerGuy added a commit to ExpidusOS-archive/zig that referenced this pull request Mar 12, 2024
This reintroduces Linux's shared memory system calls which was in
ziglang#7214. It also adds the externs
necessary for C.
RossComputerGuy added a commit to ExpidusOS-archive/zig that referenced this pull request Mar 12, 2024
This reintroduces Linux's shared memory system calls which was in
ziglang#7214. It also adds the externs
necessary for C.
RossComputerGuy added a commit to ExpidusOS-archive/zig that referenced this pull request Mar 12, 2024
This reintroduces Linux's shared memory system calls which was in
ziglang#7214. It also adds the externs
necessary for C.
RossComputerGuy added a commit to ExpidusOS-archive/zig that referenced this pull request Mar 12, 2024
This reintroduces Linux's shared memory system calls which was in
ziglang#7214. It also adds the externs
necessary for C.
RossComputerGuy added a commit to ExpidusOS-archive/zig that referenced this pull request Mar 12, 2024
This reintroduces Linux's shared memory system calls which was in
ziglang#7214. It also adds the externs
necessary for C.
RossComputerGuy added a commit to ExpidusOS-archive/zig that referenced this pull request Mar 13, 2024
This reintroduces Linux's shared memory system calls which was in
ziglang#7214. It also adds the externs
necessary for C.
RossComputerGuy added a commit to ExpidusOS-archive/zig that referenced this pull request Mar 20, 2024
This reintroduces Linux's shared memory system calls which was in
ziglang#7214. It also adds the externs
necessary for C.
RossComputerGuy added a commit to MidstallSoftware/zig that referenced this pull request Apr 5, 2024
This reintroduces Linux's shared memory system calls which was in
ziglang#7214. It also adds the externs
necessary for C.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants