root/ipc/util.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ipc_init
  2. ipcperms
  3. sys_ipc
  4. sys_ipc
  5. sem_exit
  6. shm_swap
  7. shm_no_page

   1 /*
   2  * linux/ipc/util.c
   3  * Copyright (C) 1992 Krishna Balasubramanian
   4  */
   5 
   6 #include <linux/config.h>
   7 #include <linux/errno.h>
   8 #include <asm/segment.h>
   9 #include <linux/sched.h>
  10 #include <linux/mm.h>
  11 #include <linux/sem.h>
  12 #include <linux/msg.h>
  13 #include <linux/shm.h>
  14 #include <linux/stat.h>
  15 
  16 void ipc_init (void);
  17 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth);
  18 
  19 #ifdef CONFIG_SYSVIPC
  20 
  21 int ipcperms (struct ipc_perm *ipcp, short flag);
  22 extern void sem_init (void), msg_init (void), shm_init (void);
  23 extern int sys_semget (key_t key, int nsems, int semflg);
  24 extern int sys_semop (int semid, struct sembuf *sops, unsigned nsops);
  25 extern int sys_semctl (int semid, int semnum, int cmd, union semun arg);
  26 extern int sys_msgget (key_t key, int msgflg);
  27 extern int sys_msgsnd (int msqid, struct msgbuf *msgp, int msgsz, int msgflg);
  28 extern int sys_msgrcv (int msqid, struct msgbuf *msgp, int msgsz, long msgtyp,
  29                        int msgflg);
  30 extern int sys_msgctl (int msqid, int cmd, struct msqid_ds *buf);
  31 extern int sys_shmget (key_t key, int size, int flag);
  32 extern int sys_shmat (int shmid, char *shmaddr, int shmflg, ulong *addr);
  33 extern int sys_shmdt (char *shmaddr);
  34 extern int sys_shmctl (int shmid, int cmd, struct shmid_ds *buf);
  35 
  36 void ipc_init (void)
     /* [previous][next][first][last][top][bottom][index][help] */
  37 {
  38         sem_init();
  39         msg_init();
  40         shm_init();
  41         return;
  42 }
  43 
  44 /* 
  45  * Check user, group, other permissions for access
  46  * to ipc resources. return 0 if allowed
  47  */
  48 int ipcperms (struct ipc_perm *ipcp, short flag)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {       /* flag will most probably be 0 or S_...UGO from <linux/stat.h> */
  50         int requested_mode, granted_mode;
  51 
  52         if (suser())
  53                 return 0;
  54         requested_mode = (flag >> 6) | (flag >> 3) | flag;
  55         granted_mode = ipcp->mode;
  56         if (current->euid == ipcp->cuid || current->euid == ipcp->uid)
  57                 granted_mode >>= 6;
  58         else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
  59                 granted_mode >>= 3;
  60         /* is there some bit set in requested_mode but not in granted_mode? */
  61         if (requested_mode & ~granted_mode & 0007)
  62                 return -1;
  63         return 0;
  64 }
  65 
  66 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth)
     /* [previous][next][first][last][top][bottom][index][help] */
  67 {
  68         int version;
  69 
  70         version = call >> 16; /* hack for backward compatibility */
  71         call &= 0xffff;
  72 
  73         if (call <= SEMCTL)
  74                 switch (call) {
  75                 case SEMOP:
  76                         return sys_semop (first, (struct sembuf *)ptr, second);
  77                 case SEMGET:
  78                         return sys_semget (first, second, third);
  79                 case SEMCTL: {
  80                         union semun fourth;
  81                         int err;
  82                         if (!ptr)
  83                                 return -EINVAL;
  84                         if ((err = verify_area (VERIFY_READ, ptr, sizeof(long))))
  85                                 return err;
  86                         fourth.__pad = (void *) get_fs_long(ptr);
  87                         return sys_semctl (first, second, third, fourth);
  88                         }
  89                 default:
  90                         return -EINVAL;
  91                 }
  92         if (call <= MSGCTL) 
  93                 switch (call) {
  94                 case MSGSND:
  95                         return sys_msgsnd (first, (struct msgbuf *) ptr, 
  96                                            second, third);
  97                 case MSGRCV:
  98                         switch (version) {
  99                         case 0: {
 100                                 struct ipc_kludge tmp;
 101                                 int err;
 102                                 if (!ptr)
 103                                         return -EINVAL;
 104                                 if ((err = verify_area (VERIFY_READ, ptr, sizeof(tmp))))
 105                                         return err;
 106                                 memcpy_fromfs (&tmp,(struct ipc_kludge *) ptr,
 107                                                sizeof (tmp));
 108                                 return sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp, third);
 109                                 }
 110                         case 1: default:
 111                                 return sys_msgrcv (first, (struct msgbuf *) ptr, second, fifth, third);
 112                         }
 113                 case MSGGET:
 114                         return sys_msgget ((key_t) first, second);
 115                 case MSGCTL:
 116                         return sys_msgctl (first, second, (struct msqid_ds *) ptr);
 117                 default:
 118                         return -EINVAL;
 119                 }
 120         if (call <= SHMCTL) 
 121                 switch (call) {
 122                 case SHMAT:
 123                         switch (version) {
 124                         case 0: default: {
 125                                 ulong raddr;
 126                                 int err;
 127                                 if ((err = verify_area(VERIFY_WRITE, (ulong*) third, sizeof(ulong))))
 128                                         return err;
 129                                 err = sys_shmat (first, (char *) ptr, second, &raddr);
 130                                 if (err)
 131                                         return err;
 132                                 put_fs_long (raddr, (ulong *) third);
 133                                 return 0;
 134                                 }
 135                         case 1: /* iBCS2 emulator entry point */
 136                                 if (get_fs() != get_ds())
 137                                         return -EINVAL;
 138                                 return sys_shmat (first, (char *) ptr, second, (ulong *) third);
 139                         }
 140                 case SHMDT: 
 141                         return sys_shmdt ((char *)ptr);
 142                 case SHMGET:
 143                         return sys_shmget (first, second, third);
 144                 case SHMCTL:
 145                         return sys_shmctl (first, second, (struct shmid_ds *) ptr);
 146                 default:
 147                         return -EINVAL;
 148                 }
 149         return -EINVAL;
 150 }
 151 
 152 #else /* not CONFIG_SYSVIPC */
 153 
 154 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth) 
     /* [previous][next][first][last][top][bottom][index][help] */
 155 {
 156     return -ENOSYS;
 157 }
 158 
 159 void sem_exit (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 160 {
 161     return;
 162 }
 163 
 164 int shm_swap (int prio)
     /* [previous][next][first][last][top][bottom][index][help] */
 165 {
 166     return 0;
 167 }
 168 
 169 void shm_no_page (unsigned long *ptent)
     /* [previous][next][first][last][top][bottom][index][help] */
 170 {
 171     return;
 172 }
 173 
 174 #endif /* CONFIG_SYSVIPC */

/* [previous][next][first][last][top][bottom][index][help] */