MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ksem_create

Function ksem_create

freebsd/kern/uipc_sem.c:464–589  ·  view source on GitHub ↗

Other helper routines. */

Source from the content-addressed store, hash-verified

462
463/* Other helper routines. */
464static int
465ksem_create(struct thread *td, const char *name, semid_t *semidp, mode_t mode,
466 unsigned int value, int flags, int compat32)
467{
468 struct pwddesc *pdp;
469 struct ksem *ks;
470 struct file *fp;
471 char *path;
472 const char *pr_path;
473 size_t pr_pathlen;
474 Fnv32_t fnv;
475 int error, fd;
476
477 AUDIT_ARG_FFLAGS(flags);
478 AUDIT_ARG_MODE(mode);
479 AUDIT_ARG_VALUE(value);
480
481 if (value > SEM_VALUE_MAX)
482 return (EINVAL);
483
484 pdp = td->td_proc->p_pd;
485 mode = (mode & ~pdp->pd_cmask) & ACCESSPERMS;
486 error = falloc(td, &fp, &fd, O_CLOEXEC);
487 if (error) {
488 if (name == NULL)
489 error = ENOSPC;
490 return (error);
491 }
492
493 /*
494 * Go ahead and copyout the file descriptor now. This is a bit
495 * premature, but it is a lot easier to handle errors as opposed
496 * to later when we've possibly created a new semaphore, etc.
497 */
498 error = ksem_create_copyout_semid(td, semidp, fd, compat32);
499 if (error) {
500 fdclose(td, fp, fd);
501 fdrop(fp, td);
502 return (error);
503 }
504
505 if (name == NULL) {
506 /* Create an anonymous semaphore. */
507 ks = ksem_alloc(td->td_ucred, mode, value);
508 if (ks == NULL)
509 error = ENOSPC;
510 else
511 ks->ks_flags |= KS_ANONYMOUS;
512 } else {
513 path = malloc(MAXPATHLEN, M_KSEM, M_WAITOK);
514 pr_path = td->td_ucred->cr_prison->pr_path;
515
516 /* Construct a full pathname for jailed callers. */
517 pr_pathlen = strcmp(pr_path, "/") == 0 ? 0
518 : strlcpy(path, pr_path, MAXPATHLEN);
519 error = copyinstr(name, path + pr_pathlen,
520 MAXPATHLEN - pr_pathlen, NULL);
521

Callers 4

sys_ksem_initFunction · 0.85
sys_ksem_openFunction · 0.85
freebsd32_ksem_initFunction · 0.85
freebsd32_ksem_openFunction · 0.85

Calls 14

fdcloseFunction · 0.85
ksem_allocFunction · 0.85
mallocFunction · 0.85
strcmpFunction · 0.85
fnv_32_strFunction · 0.85
ksem_lookupFunction · 0.85
ksem_insertFunction · 0.85
mac_posixsem_check_openFunction · 0.85
ksem_accessFunction · 0.85
ksem_holdFunction · 0.85
finitFunction · 0.85
freeFunction · 0.70

Tested by

no test coverage detected