This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
looking at a wrapper for shmat()
- From: Eyal Lebedinsky <eyal at eyal dot emu dot id dot au>
- To: "list, gcc" <gcc at gcc dot gnu dot org>, "Eigler, Frank Ch." <fche at redhat dot com>
- Date: Tue, 08 Apr 2003 19:28:17 +1000
- Subject: looking at a wrapper for shmat()
- Organization: Eyal at Home
I decided to have a stab at a proper wrapper for a few functions.
Looking at shmat() I think the version below should work (not yet
compiled or tested). However, the corresponding shmdt() is a problem.
Since it only gets tha address, I cannot really call shmctl() to
fetch the size (no shmid). How to I get past it? There probably
is a way to do an address lookup, fetch the registered size and then
supply it. This looks like taking the long way around. It would be
better if I could say "just unregister the object starting at".
So I have a question: why do we need the size in the unregister call?
Just for validation? If so then it should be acceptable to make
it optional for when it is unknown. Any opinion on this?
void *
__mf_shmat (int shmid, const void *shmaddr, int shmflg)
{
void *ptr;
ptr = shmat (shmid, shmaddr, shmflg);
if (NULL != ptr && (void *)-1 != ptr) {
int mfrc;
struct shmid_ds shbuf;
mfrc = shmctl (shmid, IPC_STAT, &shbuf);
if (0 == mfrc)
__mf_register (ptr, shbuf.shm_segsz,
__MF_TYPE_STATIC, "shmat area");
}
return (ptr);
}
int
__mf_shmdt (const void *shmaddr)
{
int rc;
int mfrc;
struct shmid_ds shbuf;
rc = shmdt (shmaddr);
mfrc = shmctl (shmid, IPC_STAT, &shbuf); /* where do we
get shmid
from? */
if (0 == mfrc)
__mf_unregister (shmaddr, shbuf.shm_segsz);
return (rc);
}
--
Eyal Lebedinsky (eyal at eyal dot emu dot id dot au) <http://samba.org/eyal/>