This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

looking at a wrapper for shmat()


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/>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]