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

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