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. shm_fork
  6. sem_exit
  7. shm_exit
  8. shm_swap
  9. 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); 
  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, void *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_shmctl (int shmid, int cmd, struct shmid_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 
  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) 
     /* [previous][next][first][last][top][bottom][index][help] */
  66 {
  67         
  68         if (call <= SEMCTL)
  69                 switch (call) {
  70                 case SEMOP:
  71                         return sys_semop (first, (struct sembuf *)ptr, second);
  72                 case SEMGET:
  73                         return sys_semget (first, second, third);
  74                 case SEMCTL:
  75                         return sys_semctl (first, second, third, ptr);
  76                 default:
  77                         return -EINVAL;
  78                 }
  79         if (call <= MSGCTL) 
  80                 switch (call) {
  81                 case MSGSND:
  82                         return sys_msgsnd (first, (struct msgbuf *) ptr, 
  83                                            second, third);
  84                 case MSGRCV: {
  85                         struct ipc_kludge tmp; 
  86                         if (!ptr)
  87                                 return -EINVAL;
  88                         memcpy_fromfs (&tmp,(struct ipc_kludge *) ptr, 
  89                                        sizeof (tmp));
  90                         return sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp,
  91                                                 third);
  92                         }
  93                 case MSGGET:
  94                         return sys_msgget ((key_t) first, second);
  95                 case MSGCTL:
  96                         return sys_msgctl (first, second, 
  97                                                 (struct msqid_ds *) ptr);
  98                 default:
  99                         return -EINVAL;
 100                 }
 101         if (call <= SHMCTL) 
 102                 switch (call) {
 103                 case SHMAT: /* returning shmaddr > 2G will screw up */
 104                         return sys_shmat (first, (char *) ptr, second, 
 105                                                         (ulong *) third);
 106                 case SHMDT: 
 107                         return sys_shmdt ((char *)ptr);
 108                 case SHMGET:
 109                         return sys_shmget (first, second, third);
 110                 case SHMCTL:
 111                         return sys_shmctl (first, second, 
 112                                                 (struct shmid_ds *) ptr);
 113                 default:
 114                         return -EINVAL;
 115                 }
 116         return -EINVAL;
 117 }
 118 
 119 #else /* not CONFIG_SYSVIPC */
 120 
 121 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr) 
     /* [previous][next][first][last][top][bottom][index][help] */
 122 {
 123     return -ENOSYS;
 124 }
 125 
 126 int shm_fork (struct task_struct *p1, struct task_struct *p2)
     /* [previous][next][first][last][top][bottom][index][help] */
 127 {
 128     return 0;
 129 }
 130 
 131 void sem_exit (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 132 {
 133     return;
 134 }
 135 
 136 void shm_exit (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 137 {
 138     return;
 139 }
 140 
 141 int shm_swap (int prio)
     /* [previous][next][first][last][top][bottom][index][help] */
 142 {
 143     return 0;
 144 }
 145 
 146 void shm_no_page (unsigned long *ptent)
     /* [previous][next][first][last][top][bottom][index][help] */
 147 {
 148     return;
 149 }
 150 
 151 #endif /* CONFIG_SYSVIPC */

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