Re: SHM stuff - Reason for Oopsen discovered

From: Russell King (rmk@arm.linux.org.uk)
Date: Fri May 26 2000 - 04:42:35 EST


Christoph Rohland writes:
> > 3. Is shmctl(..., SHM_LOCK, ...) honoured? It looks like there is code
> > present to set a flag (PRV_LOCKED), and return the status of this bit to
> > usermode via SHM_STAT/IPC_STAT, but nothing to actually prevent the
> > shared memory segment being swapped.
>
> This is honoured in shm_swap.

Are you sure? PRV_LOCKED != SHM_LOCKED. Here are the definitions:

#define SHM_LOCKED 02000 /* segment will not be swapped */
#define PRV_LOCKED 0020000 /* segment will not be swapped */

In sys_shmctl, PRV_LOCKED is set/cleared for SHM_LOCK/SHM_UNLOCK:

                if(cmd==SHM_LOCK)
                        shp->shm_flags |= PRV_LOCKED;
                else
                        shp->shm_flags &= ~PRV_LOCKED;

However, shm_swap only checks the SHM_LOCKED bit, which is NOT the same as
PRV_LOCKED:

        shp = shm_get(swap_id);
        if(shp==NULL || shp->shm_flags & SHM_LOCKED) {
next_id:
                swap_idx = 0;
                if (++swap_id > shm_ids.max_id) {

Hence, setting SHM_LOCK on an ID does not set SHM_LOCKED in shp->shm_flags,
and therefore does not lock that region.
   _____
  |_____| ------------------------------------------------- ---+---+-
  | | Russell King rmk@arm.linux.org.uk --- ---
  | | | | http://www.arm.linux.org.uk/~rmk/aboutme.html / / |
  | +-+-+ --- -+-
  / | THE developer of ARM Linux |+| /|\
 / | | | --- |
    +-+-+ ------------------------------------------------- /\\\ |

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed May 31 2000 - 21:00:15 EST