<div dir="ltr">Hi everyone,<div><br></div><div>This week I have implemented the shared memory support in userland. I used the actual kernel implementation and moved all structures and functions needed by daemon in userspace.</div>
<div><br></div><div>Each shm function is described below:<br></div><div><div style="font-family:arial,sans-serif;font-size:13px">- <i>shmget:</i></div><div style="font-family:arial,sans-serif;font-size:13px"> - userland</div>
<div style="font-family:arial,sans-serif;font-size:13px"> - sends a message to the daemon with key, size and shmflags;</div><div style="font-family:arial,sans-serif;font-size:13px"> - the daemon will search for the existing segment<br>
</div><div style="font-family:arial,sans-serif;font-size:13px"> - if the segment already exists, some checks are made on permissions, size, flags and the segment id is returned<i><br></i></div><div style="font-family:arial,sans-serif;font-size:13px">
- else allocates a new segment</div><div style="font-family:arial,sans-serif;font-size:13px"> - the daemon replies with the segment identifier</div><div style="font-family:arial,sans-serif;font-size:13px"> - kernel</div>
<div style="font-family:arial,sans-serif;font-size:13px"> - tells the kernel to allocate a new vm_object_t if the segment does not exist<br></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
- <i>shmctl</i></div><div style="font-family:arial,sans-serif;font-size:13px"> - userland</div><div style="font-family:arial,sans-serif;font-size:13px"> - IPC_STAT - sends a request to the daemon and waits for information needed; daemon has all information so it only sends them through pipe;</div>
<div style="font-family:arial,sans-serif;font-size:13px"> - IPC_SET - sends request to the daemon and waits for the error code;</div><div style="font-family:arial,sans-serif;font-size:13px"> - IPC_RMID - sends request to the daemon and waits for the error code;</div>
<div style="font-family:arial,sans-serif;font-size:13px"> - kernel</div><div style="font-family:arial,sans-serif;font-size:13px"> - for IPC_SET and IPC_RMID, the daemon informs kernel about the state of the segment; The kernel is informed because shmat calls directly ioctl, without the daemon intervention.</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">- <i>shmat</i> - calls ioctl() function that will do mostly the same operations as the current shm implementation (permission checks, add the <i>vm_object_t</i> in the process address space); the driver mmap announces the daemon that another process mapps the shared memory object;</div>
<div style="font-family:arial,sans-serif;font-size:13px"><i>- shmdt</i> - same as in <i>shmat</i> case</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div></div><div style="font-family:arial,sans-serif;font-size:13px">
Because, in the actual kernel implementation, more threads can access same data, some states describing each segment are used. I kept those because I think the daemon must use a poll of threads to handle the clients requests for performances reasons.</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Tomorrow I will do a code refactoring (including splitting daemon, library and client code), following that next days I will start implement support for semaphores.</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Thanks,</div><div style="font-family:arial,sans-serif;font-size:13px">Larisa</div></div>