uipc_sem.c (4e27d36d38f4c3b12bcc1855c5d41527d08d1ce0) uipc_sem.c (9696feebe2320c9976607df4090f91a34c6549c3)
1/*-
2 * Copyright (c) 2002 Alfred Perlstein <alfred@FreeBSD.org>
3 * Copyright (c) 2003-2005 SPARTA, Inc.
4 * Copyright (c) 2005 Robert N. M. Watson
5 * All rights reserved.
6 *
7 * This software was developed for the FreeBSD Project in part by Network
8 * Associates Laboratories, the Security Research Division of Network

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

57#include <sys/stat.h>
58#include <sys/syscall.h>
59#include <sys/syscallsubr.h>
60#include <sys/sysctl.h>
61#include <sys/sysent.h>
62#include <sys/sysproto.h>
63#include <sys/systm.h>
64#include <sys/sx.h>
1/*-
2 * Copyright (c) 2002 Alfred Perlstein <alfred@FreeBSD.org>
3 * Copyright (c) 2003-2005 SPARTA, Inc.
4 * Copyright (c) 2005 Robert N. M. Watson
5 * All rights reserved.
6 *
7 * This software was developed for the FreeBSD Project in part by Network
8 * Associates Laboratories, the Security Research Division of Network

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

57#include <sys/stat.h>
58#include <sys/syscall.h>
59#include <sys/syscallsubr.h>
60#include <sys/sysctl.h>
61#include <sys/sysent.h>
62#include <sys/sysproto.h>
63#include <sys/systm.h>
64#include <sys/sx.h>
65#include <sys/user.h>
65#include <sys/vnode.h>
66
67#include <security/mac/mac_framework.h>
68
69FEATURE(p1003_1b_semaphores, "POSIX P1003.1B semaphores support");
70/*
71 * TODO
72 *

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

125static int ksem_module_init(void);
126static int ksem_remove(char *path, Fnv32_t fnv, struct ucred *ucred);
127static int sem_modload(struct module *module, int cmd, void *arg);
128
129static fo_stat_t ksem_stat;
130static fo_close_t ksem_closef;
131static fo_chmod_t ksem_chmod;
132static fo_chown_t ksem_chown;
66#include <sys/vnode.h>
67
68#include <security/mac/mac_framework.h>
69
70FEATURE(p1003_1b_semaphores, "POSIX P1003.1B semaphores support");
71/*
72 * TODO
73 *

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

126static int ksem_module_init(void);
127static int ksem_remove(char *path, Fnv32_t fnv, struct ucred *ucred);
128static int sem_modload(struct module *module, int cmd, void *arg);
129
130static fo_stat_t ksem_stat;
131static fo_close_t ksem_closef;
132static fo_chmod_t ksem_chmod;
133static fo_chown_t ksem_chown;
134static fo_fill_kinfo_t ksem_fill_kinfo;
133
134/* File descriptor operations. */
135static struct fileops ksem_ops = {
136 .fo_read = invfo_rdwr,
137 .fo_write = invfo_rdwr,
138 .fo_truncate = invfo_truncate,
139 .fo_ioctl = invfo_ioctl,
140 .fo_poll = invfo_poll,
141 .fo_kqfilter = invfo_kqfilter,
142 .fo_stat = ksem_stat,
143 .fo_close = ksem_closef,
144 .fo_chmod = ksem_chmod,
145 .fo_chown = ksem_chown,
146 .fo_sendfile = invfo_sendfile,
135
136/* File descriptor operations. */
137static struct fileops ksem_ops = {
138 .fo_read = invfo_rdwr,
139 .fo_write = invfo_rdwr,
140 .fo_truncate = invfo_truncate,
141 .fo_ioctl = invfo_ioctl,
142 .fo_poll = invfo_poll,
143 .fo_kqfilter = invfo_kqfilter,
144 .fo_stat = ksem_stat,
145 .fo_close = ksem_closef,
146 .fo_chmod = ksem_chmod,
147 .fo_chown = ksem_chown,
148 .fo_sendfile = invfo_sendfile,
149 .fo_fill_kinfo = ksem_fill_kinfo,
147 .fo_flags = DFLAG_PASSABLE
148};
149
150FEATURE(posix_sem, "POSIX semaphores");
151
152static int
153ksem_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
154 struct thread *td)

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

247
248 ks = fp->f_data;
249 fp->f_data = NULL;
250 ksem_drop(ks);
251
252 return (0);
253}
254
150 .fo_flags = DFLAG_PASSABLE
151};
152
153FEATURE(posix_sem, "POSIX semaphores");
154
155static int
156ksem_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
157 struct thread *td)

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

250
251 ks = fp->f_data;
252 fp->f_data = NULL;
253 ksem_drop(ks);
254
255 return (0);
256}
257
258static int
259ksem_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
260{
261 struct ksem *ks;
262
263 kif->kf_type = KF_TYPE_SEM;
264 ks = fp->f_data;
265 mtx_lock(&sem_lock);
266 kif->kf_un.kf_sem.kf_sem_value = ks->ks_value;
267 kif->kf_un.kf_sem.kf_sem_mode = S_IFREG | ks->ks_mode; /* XXX */
268 mtx_unlock(&sem_lock);
269 if (ks->ks_path != NULL) {
270 sx_slock(&ksem_dict_lock);
271 if (ks->ks_path != NULL)
272 strlcpy(kif->kf_path, ks->ks_path, sizeof(kif->kf_path));
273 sx_sunlock(&ksem_dict_lock);
274 }
275 return (0);
276}
277
255/*
256 * ksem object management including creation and reference counting
257 * routines.
258 */
259static struct ksem *
260ksem_alloc(struct ucred *ucred, mode_t mode, unsigned int value)
261{
262 struct ksem *ks;

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

383 free(map, M_KSEM);
384 return (0);
385 }
386 }
387
388 return (ENOENT);
389}
390
278/*
279 * ksem object management including creation and reference counting
280 * routines.
281 */
282static struct ksem *
283ksem_alloc(struct ucred *ucred, mode_t mode, unsigned int value)
284{
285 struct ksem *ks;

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

406 free(map, M_KSEM);
407 return (0);
408 }
409 }
410
411 return (ENOENT);
412}
413
391static void
392ksem_info_impl(struct ksem *ks, char *path, size_t size, uint32_t *value)
393{
394
395 if (ks->ks_path == NULL)
396 return;
397 sx_slock(&ksem_dict_lock);
398 if (ks->ks_path != NULL)
399 strlcpy(path, ks->ks_path, size);
400 if (value != NULL)
401 *value = ks->ks_value;
402 sx_sunlock(&ksem_dict_lock);
403}
404
405static int
406ksem_create_copyout_semid(struct thread *td, semid_t *semidp, int fd,
407 int compat32)
408{
409 semid_t semid;
410#ifdef COMPAT_FREEBSD32
411 int32_t semid32;
412#endif

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

978
979 mtx_init(&sem_lock, "sem", NULL, MTX_DEF);
980 mtx_init(&ksem_count_lock, "ksem count", NULL, MTX_DEF);
981 sx_init(&ksem_dict_lock, "ksem dictionary");
982 ksem_dictionary = hashinit(1024, M_KSEM, &ksem_hash);
983 p31b_setcfg(CTL_P1003_1B_SEMAPHORES, 200112L);
984 p31b_setcfg(CTL_P1003_1B_SEM_NSEMS_MAX, SEM_MAX);
985 p31b_setcfg(CTL_P1003_1B_SEM_VALUE_MAX, SEM_VALUE_MAX);
414static int
415ksem_create_copyout_semid(struct thread *td, semid_t *semidp, int fd,
416 int compat32)
417{
418 semid_t semid;
419#ifdef COMPAT_FREEBSD32
420 int32_t semid32;
421#endif

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

987
988 mtx_init(&sem_lock, "sem", NULL, MTX_DEF);
989 mtx_init(&ksem_count_lock, "ksem count", NULL, MTX_DEF);
990 sx_init(&ksem_dict_lock, "ksem dictionary");
991 ksem_dictionary = hashinit(1024, M_KSEM, &ksem_hash);
992 p31b_setcfg(CTL_P1003_1B_SEMAPHORES, 200112L);
993 p31b_setcfg(CTL_P1003_1B_SEM_NSEMS_MAX, SEM_MAX);
994 p31b_setcfg(CTL_P1003_1B_SEM_VALUE_MAX, SEM_VALUE_MAX);
986 ksem_info = ksem_info_impl;
987
988 error = syscall_helper_register(ksem_syscalls);
989 if (error)
990 return (error);
991#ifdef COMPAT_FREEBSD32
992 error = syscall32_helper_register(ksem32_syscalls);
993 if (error)
994 return (error);

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

1000ksem_module_destroy(void)
1001{
1002
1003#ifdef COMPAT_FREEBSD32
1004 syscall32_helper_unregister(ksem32_syscalls);
1005#endif
1006 syscall_helper_unregister(ksem_syscalls);
1007
995
996 error = syscall_helper_register(ksem_syscalls);
997 if (error)
998 return (error);
999#ifdef COMPAT_FREEBSD32
1000 error = syscall32_helper_register(ksem32_syscalls);
1001 if (error)
1002 return (error);

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

1008ksem_module_destroy(void)
1009{
1010
1011#ifdef COMPAT_FREEBSD32
1012 syscall32_helper_unregister(ksem32_syscalls);
1013#endif
1014 syscall_helper_unregister(ksem_syscalls);
1015
1008 ksem_info = NULL;
1009 p31b_setcfg(CTL_P1003_1B_SEMAPHORES, 0);
1010 hashdestroy(ksem_dictionary, M_KSEM, ksem_hash);
1011 sx_destroy(&ksem_dict_lock);
1012 mtx_destroy(&ksem_count_lock);
1013 mtx_destroy(&sem_lock);
1014 p31b_unsetcfg(CTL_P1003_1B_SEM_VALUE_MAX);
1015 p31b_unsetcfg(CTL_P1003_1B_SEM_NSEMS_MAX);
1016}

--- 42 unchanged lines hidden ---
1016 p31b_setcfg(CTL_P1003_1B_SEMAPHORES, 0);
1017 hashdestroy(ksem_dictionary, M_KSEM, ksem_hash);
1018 sx_destroy(&ksem_dict_lock);
1019 mtx_destroy(&ksem_count_lock);
1020 mtx_destroy(&sem_lock);
1021 p31b_unsetcfg(CTL_P1003_1B_SEM_VALUE_MAX);
1022 p31b_unsetcfg(CTL_P1003_1B_SEM_NSEMS_MAX);
1023}

--- 42 unchanged lines hidden ---