Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/uipc_shm.c
Show First 20 Lines • Show All 827 Lines • ▼ Show 20 Lines | if (userpath == SHM_ANON) { | ||||
/* A read-only anonymous object is pointless. */ | /* A read-only anonymous object is pointless. */ | ||||
if ((flags & O_ACCMODE) == O_RDONLY) { | if ((flags & O_ACCMODE) == O_RDONLY) { | ||||
fdclose(td, fp, fd); | fdclose(td, fp, fd); | ||||
fdrop(fp, td); | fdrop(fp, td); | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
shmfd = shm_alloc(td->td_ucred, cmode); | shmfd = shm_alloc(td->td_ucred, cmode); | ||||
shmfd->shm_seals = initial_seals; | shmfd->shm_seals = initial_seals; | ||||
shmfd->shm_flags = shmflags; | |||||
} else { | } else { | ||||
error = shm_copyin_path(td, userpath, &path); | error = shm_copyin_path(td, userpath, &path); | ||||
if (error != 0) { | if (error != 0) { | ||||
fdclose(td, fp, fd); | fdclose(td, fp, fd); | ||||
fdrop(fp, td); | fdrop(fp, td); | ||||
return (error); | return (error); | ||||
} | } | ||||
AUDIT_ARG_UPATH1_CANON(path); | AUDIT_ARG_UPATH1_CANON(path); | ||||
fnv = fnv_32_str(path, FNV1_32_INIT); | fnv = fnv_32_str(path, FNV1_32_INIT); | ||||
sx_xlock(&shm_dict_lock); | sx_xlock(&shm_dict_lock); | ||||
shmfd = shm_lookup(path, fnv); | shmfd = shm_lookup(path, fnv); | ||||
if (shmfd == NULL) { | if (shmfd == NULL) { | ||||
/* Object does not yet exist, create it if requested. */ | /* Object does not yet exist, create it if requested. */ | ||||
if (flags & O_CREAT) { | if (flags & O_CREAT) { | ||||
#ifdef MAC | #ifdef MAC | ||||
error = mac_posixshm_check_create(td->td_ucred, | error = mac_posixshm_check_create(td->td_ucred, | ||||
path); | path); | ||||
if (error == 0) { | if (error == 0) { | ||||
#endif | #endif | ||||
shmfd = shm_alloc(td->td_ucred, cmode); | shmfd = shm_alloc(td->td_ucred, cmode); | ||||
shmfd->shm_seals = initial_seals; | shmfd->shm_seals = initial_seals; | ||||
shmfd->shm_flags = shmflags; | |||||
shm_insert(path, fnv, shmfd); | shm_insert(path, fnv, shmfd); | ||||
#ifdef MAC | #ifdef MAC | ||||
} | } | ||||
#endif | #endif | ||||
} else { | } else { | ||||
free(path, M_SHMFD); | free(path, M_SHMFD); | ||||
error = ENOENT; | error = ENOENT; | ||||
} | } | ||||
Show All 27 Lines | #endif | ||||
* to allow additional seals. | * to allow additional seals. | ||||
*/ | */ | ||||
if ((shmfd->shm_seals & F_SEAL_SEAL) != 0 && | if ((shmfd->shm_seals & F_SEAL_SEAL) != 0 && | ||||
initial_seals != 0) | initial_seals != 0) | ||||
error = EPERM; | error = EPERM; | ||||
else if ((flags & (O_CREAT | O_EXCL)) == | else if ((flags & (O_CREAT | O_EXCL)) == | ||||
(O_CREAT | O_EXCL)) | (O_CREAT | O_EXCL)) | ||||
error = EEXIST; | error = EEXIST; | ||||
else if (shmflags != 0 && shmflags != shmfd->shm_flags) | |||||
error = EINVAL; | |||||
else { | else { | ||||
#ifdef MAC | #ifdef MAC | ||||
error = mac_posixshm_check_open(td->td_ucred, | error = mac_posixshm_check_open(td->td_ucred, | ||||
shmfd, FFLAGS(flags & O_ACCMODE)); | shmfd, FFLAGS(flags & O_ACCMODE)); | ||||
if (error == 0) | if (error == 0) | ||||
#endif | #endif | ||||
error = shm_access(shmfd, td->td_ucred, | error = shm_access(shmfd, td->td_ucred, | ||||
FFLAGS(flags & O_ACCMODE)); | FFLAGS(flags & O_ACCMODE)); | ||||
Show All 33 Lines | #endif | ||||
if (error) { | if (error) { | ||||
fdclose(td, fp, fd); | fdclose(td, fp, fd); | ||||
fdrop(fp, td); | fdrop(fp, td); | ||||
return (error); | return (error); | ||||
} | } | ||||
} | } | ||||
shmfd->shm_flags = shmflags; | |||||
finit(fp, FFLAGS(flags & O_ACCMODE), DTYPE_SHM, shmfd, &shm_ops); | finit(fp, FFLAGS(flags & O_ACCMODE), DTYPE_SHM, shmfd, &shm_ops); | ||||
td->td_retval[0] = fd; | td->td_retval[0] = fd; | ||||
fdrop(fp, td); | fdrop(fp, td); | ||||
return (0); | return (0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 626 Lines • Show Last 20 Lines |