linux-old/ipc/util.c
<<
>>
Prefs
   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
  15void ipc_init (void);
  16asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr); 
  17
  18#ifdef CONFIG_SYSVIPC
  19
  20int ipcperms (struct ipc_perm *ipcp, short flag);
  21extern void sem_init (void), msg_init (void), shm_init (void);
  22extern int sys_semget (key_t key, int nsems, int semflg);
  23extern int sys_semop (int semid, struct sembuf *sops, unsigned nsops);
  24extern int sys_semctl (int semid, int semnum, int cmd, void *arg);
  25extern int sys_msgget (key_t key, int msgflg);
  26extern int sys_msgsnd (int msqid, struct msgbuf *msgp, int msgsz, int msgflg);
  27extern int sys_msgrcv (int msqid, struct msgbuf *msgp, int msgsz, long msgtyp,
  28                       int msgflg);
  29extern int sys_msgctl (int msqid, int cmd, struct msqid_ds *buf);
  30extern int sys_shmctl (int shmid, int cmd, struct shmid_ds *buf);
  31extern int sys_shmget (key_t key, int size, int flag);
  32extern int sys_shmat (int shmid, char *shmaddr, int shmflg, ulong *addr);
  33extern int sys_shmdt (char *shmaddr);
  34
  35void ipc_init (void)
  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 */
  47int ipcperms (struct ipc_perm *ipcp, short flag)
  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
  65asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr) 
  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
 121asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr) 
 122{
 123    return -ENOSYS;
 124}
 125
 126int shm_fork (struct task_struct *p1, struct task_struct *p2)
 127{
 128    return 0;
 129}
 130
 131void sem_exit (void)
 132{
 133    return;
 134}
 135
 136void shm_exit (void)
 137{
 138    return;
 139}
 140
 141int shm_swap (int prio)
 142{
 143    return 0;
 144}
 145
 146void shm_no_page (unsigned long *ptent)
 147{
 148    return;
 149}
 150
 151#endif /* CONFIG_SYSVIPC */
 152
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.