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 
  14 void ipc_init (void);
  15 extern "C" int sys_ipc (uint call, int first, int second, int third, void *ptr); 
  16 
  17 #ifdef CONFIG_SYSVIPC
  18 
  19 int ipcperms (struct ipc_perm *ipcp, short flag);
  20 extern void sem_init (void), msg_init (void), shm_init (void);
  21 extern int sys_semget (key_t key, int nsems, int semflg);
  22 extern int sys_semop (int semid, struct sembuf *sops, unsigned nsops);
  23 extern int sys_semctl (int semid, int semnum, int cmd, void *arg);
  24 extern int sys_msgget (key_t key, int msgflg);
  25 extern int sys_msgsnd (int msqid, struct msgbuf *msgp, int msgsz, int msgflg);
  26 extern int sys_msgrcv (int msqid, struct msgbuf *msgp, int msgsz, long msgtyp,
  27                        int msgflg);
  28 extern int sys_msgctl (int msqid, int cmd, struct msqid_ds *buf);
  29 extern int sys_shmctl (int shmid, int cmd, struct shmid_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 
  34 void ipc_init (void)
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36         sem_init();
  37         msg_init();
  38         shm_init();
  39         return;
  40 }
  41 
  42 /* 
  43  * Check user, group, other permissions for access
  44  * to ipc resources. return 0 if allowed
  45  */
  46 int ipcperms (struct ipc_perm *ipcp, short flag)
     /* [previous][next][first][last][top][bottom][index][help] */
  47 {
  48         int i, perm = 0007, euid = current->euid, egid;
  49         
  50         if (suser())
  51                 return 0;
  52         if (euid == ipcp->cuid || euid == ipcp->uid) 
  53                 perm = 0700;
  54         else {
  55                 for (i = 0; (egid = current->groups[i]) != NOGROUP; i++)
  56                         if ((egid == ipcp->cgid) || (egid == ipcp->gid)) { 
  57                                 perm = 0070; 
  58                                 break;
  59                         }
  60         }
  61         if (!(flag & perm) || flag & perm & ~ipcp->mode)
  62                 return -1;
  63         return 0;
  64 }
  65 
  66 extern "C" int sys_ipc (uint call, int first, int second, int third, void *ptr) 
     /* [previous][next][first][last][top][bottom][index][help] */
  67 {
  68         
  69         if (call <= SEMCTL)
  70                 switch (call) {
  71                 case SEMOP:
  72                         return sys_semop (first, (struct sembuf *)ptr, second);
  73                 case SEMGET:
  74                         return sys_semget (first, second, third);
  75                 case SEMCTL:
  76                         return sys_semctl (first, second, third, ptr);
  77                 default:
  78                         return -EINVAL;
  79                 }
  80         if (call <= MSGCTL) 
  81                 switch (call) {
  82                 case MSGSND:
  83                         return sys_msgsnd (first, (struct msgbuf *) ptr, 
  84                                            second, third);
  85                 case MSGRCV: {
  86                         struct ipc_kludge tmp; 
  87                         if (!ptr)
  88                                 return -EINVAL;
  89                         memcpy_fromfs (&tmp,(struct ipc_kludge *) ptr, 
  90                                        sizeof (tmp));
  91                         return sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp,
  92                                                 third);
  93                         }
  94                 case MSGGET:
  95                         return sys_msgget ((key_t) first, second);
  96                 case MSGCTL:
  97                         return sys_msgctl (first, second, 
  98                                                 (struct msqid_ds *) ptr);
  99                 default:
 100                         return -EINVAL;
 101                 }
 102         if (call <= SHMCTL) 
 103                 switch (call) {
 104                 case SHMAT: /* returning shmaddr > 2G will screw up */
 105                         return sys_shmat (first, (char *) ptr, second, 
 106                                                         (ulong *) third);
 107                 case SHMDT: 
 108                         return sys_shmdt ((char *)ptr);
 109                 case SHMGET:
 110                         return sys_shmget (first, second, third);
 111                 case SHMCTL:
 112                         return sys_shmctl (first, second, 
 113                                                 (struct shmid_ds *) ptr);
 114                 default:
 115                         return -EINVAL;
 116                 }
 117         return -EINVAL;
 118 }
 119 
 120 #else /* not CONFIG_SYSVIPC */
 121 
 122 extern "C" int sys_ipc (uint call, int first, int second, int third, void *ptr) 
     /* [previous][next][first][last][top][bottom][index][help] */
 123 {
 124     return -ENOSYS;
 125 }
 126 
 127 int shm_fork (struct task_struct *p1, struct task_struct *p2)
     /* [previous][next][first][last][top][bottom][index][help] */
 128 {
 129     return 0;
 130 }
 131 
 132 void sem_exit (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 133 {
 134     return;
 135 }
 136 
 137 void shm_exit (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 138 {
 139     return;
 140 }
 141 
 142 int shm_swap (int prio)
     /* [previous][next][first][last][top][bottom][index][help] */
 143 {
 144     return 0;
 145 }
 146 
 147 void shm_no_page (unsigned long *ptent)
     /* [previous][next][first][last][top][bottom][index][help] */
 148 {
 149     return;
 150 }
 151 
 152 #endif /* CONFIG_SYSVIPC */

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