Skip to content

std.os.linux: resurrect shm #19266

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RossComputerGuy
Copy link
Contributor

This reintroduces Linux's shared memory system calls which was in #7214. It also adds the externs necessary for C.

@nektro
Copy link
Contributor

nektro commented Mar 12, 2024

  • the types used are very wrong
  • the constants should be in a namespace
  • the functions should not use @bitcast

(was going to enumerate the way the types were different but it ended up as 9 comments and thought that would be over-bearing)

@RossComputerGuy
Copy link
Contributor Author

@nektro I've resolved the last two points you made. Not sure what to do about the types though.

@nektro
Copy link
Contributor

nektro commented Mar 12, 2024

std.c should use c_int/c_uint
shmdt should accept *const anyopaque
shmctl's buf accepts a struct ptr, not a byte one
shmid should be unsigned
returning usize then accepting u32 feels sus

@RossComputerGuy
Copy link
Contributor Author

RossComputerGuy commented Mar 12, 2024

Ok, I've updated shmdt and shmid. Made a few of the std.c changes. Not sure what you're meaning about the shmctl buffer.
Edit: found the header for shm stuff, gonna look at that for the C stuff and port the struct over.

@RossComputerGuy RossComputerGuy force-pushed the feat/linux-shm branch 3 times, most recently from 4d73a92 to 9960431 Compare March 13, 2024 02:24
@RossComputerGuy RossComputerGuy marked this pull request as ready for review March 13, 2024 14:34
@andrewrk andrewrk self-requested a review March 14, 2024 01:45
@andrewrk
Copy link
Member

@RossComputerGuy can you share the steps you used to come up with this patch?

@RossComputerGuy
Copy link
Contributor Author

@andrewrk I used the original implementation and then updated it by looking at the header files which define the methods and stuff. I then ran std tests on my system to see if the shm test passes.

This reintroduces Linux's shared memory system calls which was in
ziglang#7214. It also adds the externs
necessary for C.
@andrewrk
Copy link
Member

andrewrk commented May 9, 2024

A core zig team member will need to check this work. We've unfortunately seen a lot of mistakes in the ABI bits from contributors.

@Aransentin
Copy link
Contributor

Note that if you want to do SHM for X11 it actually supports the modern POSIX shared memory too, it's just that the 1.2 version of MIT-SHM that introduced it is entirely undocumented. You'd have to take a peek at the libXCB source code instead or the like.

@RossComputerGuy
Copy link
Contributor Author

Note that if you want to do SHM for X11

Trying to do Wayland shm.

@Aransentin
Copy link
Contributor

Note that if you want to do SHM for X11

Trying to do Wayland shm.

Seems to be POSIX shared memory on Wayland as well, though? https://wayland-book.com/surfaces/shared-memory.html

@ifreund
Copy link
Member

ifreund commented Jun 18, 2024

Trying to do Wayland shm.

You don't want these syscalls for Wayland shared memory for software rendering buffers (wl_shm). You want memfd_create() on operating systems that support it and something shm_open() equivalent on operating systems that don't (see e.g. https://github.com/emersion/hello-wayland/blob/5f3a35def81116f0a74fcaf5a421d66c6700482d/shm.c)

@RossComputerGuy
Copy link
Contributor Author

Oh it might been that I needed this for something else but I don't remember.

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.

5 participants