Deleted Added
full compact
sysv_sem.c (220399) sysv_sem.c (223825)
1/*-
2 * Implementation of SVID semaphores
3 *
4 * Author: Daniel Boulet
5 *
6 * This software is provided ``AS IS'' without any warranties of any kind.
7 */
8/*-

--- 23 unchanged lines hidden (view full) ---

32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38
39#include <sys/cdefs.h>
1/*-
2 * Implementation of SVID semaphores
3 *
4 * Author: Daniel Boulet
5 *
6 * This software is provided ``AS IS'' without any warranties of any kind.
7 */
8/*-

--- 23 unchanged lines hidden (view full) ---

32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38
39#include <sys/cdefs.h>
40__FBSDID("$FreeBSD: head/sys/kern/sysv_sem.c 220399 2011-04-06 19:08:50Z trasz $");
40__FBSDID("$FreeBSD: head/sys/kern/sysv_sem.c 223825 2011-07-06 20:06:44Z trasz $");
41
42#include "opt_compat.h"
43#include "opt_sysvipc.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/sysproto.h>
48#include <sys/eventhandler.h>

--- 877 unchanged lines hidden (view full) ---

926 if ((sema[semid].u.sem_perm.mode & SEM_ALLOC) == 0)
927 break;
928 }
929 if (semid == seminfo.semmni) {
930 DPRINTF(("no more semid_kernel's available\n"));
931 error = ENOSPC;
932 goto done2;
933 }
41
42#include "opt_compat.h"
43#include "opt_sysvipc.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/sysproto.h>
48#include <sys/eventhandler.h>

--- 877 unchanged lines hidden (view full) ---

926 if ((sema[semid].u.sem_perm.mode & SEM_ALLOC) == 0)
927 break;
928 }
929 if (semid == seminfo.semmni) {
930 DPRINTF(("no more semid_kernel's available\n"));
931 error = ENOSPC;
932 goto done2;
933 }
934#ifdef RACCT
934 PROC_LOCK(td->td_proc);
935 error = racct_add(td->td_proc, RACCT_NSEM, nsems);
936 PROC_UNLOCK(td->td_proc);
937 if (error != 0) {
938 error = ENOSPC;
939 goto done2;
940 }
935 PROC_LOCK(td->td_proc);
936 error = racct_add(td->td_proc, RACCT_NSEM, nsems);
937 PROC_UNLOCK(td->td_proc);
938 if (error != 0) {
939 error = ENOSPC;
940 goto done2;
941 }
942#endif
941 DPRINTF(("semid %d is available\n", semid));
942 mtx_lock(&sema_mtx[semid]);
943 KASSERT((sema[semid].u.sem_perm.mode & SEM_ALLOC) == 0,
944 ("Lost semaphore %d", semid));
945 sema[semid].u.sem_perm.key = key;
946 sema[semid].u.sem_perm.cuid = cred->cr_uid;
947 sema[semid].u.sem_perm.uid = cred->cr_uid;
948 sema[semid].u.sem_perm.cgid = cred->cr_gid;

--- 69 unchanged lines hidden (view full) ---

1018 /* Allocate memory for sem_ops */
1019 if (nsops <= SMALL_SOPS)
1020 sops = small_sops;
1021 else if (nsops > seminfo.semopm) {
1022 DPRINTF(("too many sops (max=%d, nsops=%d)\n", seminfo.semopm,
1023 nsops));
1024 return (E2BIG);
1025 } else {
943 DPRINTF(("semid %d is available\n", semid));
944 mtx_lock(&sema_mtx[semid]);
945 KASSERT((sema[semid].u.sem_perm.mode & SEM_ALLOC) == 0,
946 ("Lost semaphore %d", semid));
947 sema[semid].u.sem_perm.key = key;
948 sema[semid].u.sem_perm.cuid = cred->cr_uid;
949 sema[semid].u.sem_perm.uid = cred->cr_uid;
950 sema[semid].u.sem_perm.cgid = cred->cr_gid;

--- 69 unchanged lines hidden (view full) ---

1020 /* Allocate memory for sem_ops */
1021 if (nsops <= SMALL_SOPS)
1022 sops = small_sops;
1023 else if (nsops > seminfo.semopm) {
1024 DPRINTF(("too many sops (max=%d, nsops=%d)\n", seminfo.semopm,
1025 nsops));
1026 return (E2BIG);
1027 } else {
1028#ifdef RACCT
1026 PROC_LOCK(td->td_proc);
1027 if (nsops > racct_get_available(td->td_proc, RACCT_NSEMOP)) {
1028 PROC_UNLOCK(td->td_proc);
1029 return (E2BIG);
1030 }
1031 PROC_UNLOCK(td->td_proc);
1029 PROC_LOCK(td->td_proc);
1030 if (nsops > racct_get_available(td->td_proc, RACCT_NSEMOP)) {
1031 PROC_UNLOCK(td->td_proc);
1032 return (E2BIG);
1033 }
1034 PROC_UNLOCK(td->td_proc);
1035#endif
1032
1033 sops = malloc(nsops * sizeof(*sops), M_TEMP, M_WAITOK);
1034 }
1035 if ((error = copyin(uap->sops, sops, nsops * sizeof(sops[0]))) != 0) {
1036 DPRINTF(("error = %d from copyin(%p, %p, %d)\n", error,
1037 uap->sops, sops, nsops * sizeof(sops[0])));
1038 if (sops != small_sops)
1039 free(sops, M_SEM);

--- 630 unchanged lines hidden ---
1036
1037 sops = malloc(nsops * sizeof(*sops), M_TEMP, M_WAITOK);
1038 }
1039 if ((error = copyin(uap->sops, sops, nsops * sizeof(sops[0]))) != 0) {
1040 DPRINTF(("error = %d from copyin(%p, %p, %d)\n", error,
1041 uap->sops, sops, nsops * sizeof(sops[0])));
1042 if (sops != small_sops)
1043 free(sops, M_SEM);

--- 630 unchanged lines hidden ---