From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 References: In-Reply-To: From: Charles Forsyth Date: Thu, 25 Apr 2019 15:25:37 +0100 Message-ID: To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary="0000000000002ab62905875b98dc" Subject: Re: [9fans] POSIX shared memory (shm_open) Topicbox-Message-UUID: fdbc6ca6-ead9-11e9-9d60-3106f5b1d025 --0000000000002ab62905875b98dc Content-Type: text/plain; charset="UTF-8" There's some support for sharing memory segments in segattach(2) and between unrelated processes with segment(3). On Wed, 24 Apr 2019 at 16:23, Lassi Kortela wrote: > Hello, > > Can the POSIX shared memory API be emulated on Plan 9 with reasonable > effort? I didn't find any mention of 'shm_open' in Plan 9 source. > > To recap, the API works as follows: > > - shm_open(path) to open or create an shm object, get a file descriptor > - shm_unlink(path) to remove the shm object from the path namespace > - ftruncate(fd) to actually allocate n bytes for the shm object > - fstat(fd) returns the size of the object in the st_size field > - mmap(fd) to get a pointer to use the shared memory > > The shm fd works like other Unix fds (can be sent to an unrelated > process over a Unix-domain socket, persists over fork(), and can persist > over exec() if the close-on-exec flag is cleared). The kernel garbage > collects the shm object after the last fd pointing to it is closed. > > I made the shim to provide a > "shm_open() without a pathname" on various Unix flavors. I'm wondering > if Plan 9 support could be easily added. > > I should mention that I have never used Plan 9, just read some of the > source and documentation. > > Regards, > Lassi > > --0000000000002ab62905875b98dc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
There's some support for sharing memory segments in se= gattach(2) and between unrelated processes with segment(3).

On Wed, 24 Apr 2= 019 at 16:23, Lassi Kortela <lassi@las= si.io> wrote:
Hello,

Can the POSIX shared memory API be emulated on Plan 9 with reasonable
effort? I didn't find any mention of 'shm_open' in Plan 9 sourc= e.

To recap, the API works as follows:

- shm_open(path) to open or create an shm object, get a file descriptor
- shm_unlink(path) to remove the shm object from the path namespace
- ftruncate(fd) to actually allocate n bytes for the shm object
- fstat(fd) returns the size of the object in the st_size field
- mmap(fd) to get a pointer to use the shared memory

The shm fd works like other Unix fds (can be sent to an unrelated
process over a Unix-domain socket, persists over fork(), and can persist over exec() if the close-on-exec flag is cleared). The kernel garbage
collects the shm object after the last fd pointing to it is closed.

I made the shim <https://github.com/lassik/shm_open_anon> to provide a
"shm_open() without a pathname" on various Unix flavors. I'm = wondering
if Plan 9 support could be easily added.

I should mention that I have never used Plan 9, just read some of the
source and documentation.

Regards,
Lassi

--0000000000002ab62905875b98dc--