Back to index

glibc  2.9
bp-semctl.h
Go to the documentation of this file.
00001 /* Bounded-pointer checking macros for C.
00002    Copyright (C) 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Greg McGary <greg@mcgary.org>
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef _bp_semctl_h_
00022 #define _bp_semctl_h_ 1
00023 
00024 #if __BOUNDED_POINTERS__
00025 
00026 # define CHECK_SEMCTL(ARGP, SEMID, CMD) check_semctl (ARGP, SEMID, CMD)
00027 
00028 union semun *__unbounded
00029 check_semctl (union semun *arg, int semid, int cmd)
00030 {
00031   int ipc64 = (cmd & __IPC_64);
00032 
00033   switch (cmd & ~__IPC_64)
00034     {
00035     case IPC_STAT:
00036     case IPC_SET:
00037       (void) CHECK_1 (arg->buf);
00038       break;
00039 
00040     case GETALL:
00041     case SETALL:
00042       {
00043        struct semid_ds ds;
00044        union semun un = { .buf = &ds };
00045        unsigned int length = ~0;
00046 
00047        /* It's unfortunate that we need to make a recursive
00048           system call to get the size of the semaphore set...  */
00049        if (semctl (semid, 0, IPC_STAT | ipc64, un) == 0)
00050          length = ds.sem_nsems;
00051        (void) CHECK_N (arg->array, length);
00052        break;
00053       }
00054 
00055     case IPC_INFO:
00056       (void) CHECK_1 (arg->__buf);
00057       break;
00058     }
00059 
00060   return __ptrvalue (arg);
00061 }
00062 
00063 #else
00064 # define CHECK_SEMCTL(ARGP, SEMID, CMD) (ARGP)
00065 #endif
00066 
00067 #endif /* _bp_semctl_h_ */