Shared memory allocator that works with both POSIX and SYSV SHM. More details follow below.
README
I have adapted the original Solaris's libmtmalloc(3) to handle allocations in
different shared memory segments. The code is re-released under the CDDL
license. See the tests subdirectory for examples of usage. Also see comments
preceding shmt_manage() and shmt_unmanage() functions in the shmtmalloc.c
file. The library works both with SYSV and POSIX shared memory. The downside
is that the shared memory segment cannot grow (but see TODO).
Another change that I made is that the allocator now returns blocks aligned to
16 bytes. Such alignment is required by the SSE instruction set as well as
the cmpxchg16b instruction.
I hope you find this code useful, but the standard disclaimer (should be also covered by the CDDL license): this code comes with NO WARRANTY WHATSOEVER.
TODO
More tests to exercise the fork() and parallel behaviour.
Write a decent Makefile.
Hooks to grow the shared memory segment (useful with shm_open API where the
program can use ftruncate() + mmap() to extend the shared memory pool.) But
how is this to be done? SYSV memory segments cannot grow. The program which
creates the shared memory segment might store the POSIX SHM name in the
super_data, as well as the last allocated offset. Thus, any participating
process which has access to super_data can reopen the SHM object and grow it
as neccessary. Using MAP_FIXED in mmap(), we can also smoothly continue to
increase the current break value.