Make sysctl_kern_proc_umask execute fast path when requested pid in
curproc->p_pid or 0, avoiding unnecessary locking. Update libc consumer to skip calling getpid(). Submitted by: Pawel Biernacki <pawel.biernacki@gmail.com> Reviewed by: mjg, robak Approved by: mjg Sponsored by: Mysterious Code Ltd. Differential Revision: D12972
This commit is contained in:
parent
3fa561a45b
commit
cee09850f7
@ -356,7 +356,7 @@ getumask(void)
|
||||
* security.bsd.unprivileged_proc_debug is set to 0.
|
||||
*/
|
||||
len = sizeof(smask);
|
||||
if (sysctl((int[4]){ CTL_KERN, KERN_PROC, KERN_PROC_UMASK, getpid() },
|
||||
if (sysctl((int[4]){ CTL_KERN, KERN_PROC, KERN_PROC_UMASK, 0 },
|
||||
4, &smask, &len, NULL, 0) == 0)
|
||||
return (smask);
|
||||
|
||||
|
@ -2770,18 +2770,25 @@ sysctl_kern_proc_umask(SYSCTL_HANDLER_ARGS)
|
||||
struct proc *p;
|
||||
int error;
|
||||
u_short fd_cmask;
|
||||
pid_t pid;
|
||||
|
||||
if (namelen != 1)
|
||||
return (EINVAL);
|
||||
|
||||
error = pget((pid_t)name[0], PGET_WANTREAD, &p);
|
||||
pid = (pid_t)name[0];
|
||||
p = curproc;
|
||||
if (pid == p->p_pid || pid == 0) {
|
||||
fd_cmask = p->p_fd->fd_cmask;
|
||||
goto out;
|
||||
}
|
||||
|
||||
error = pget(pid, PGET_WANTREAD, &p);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
FILEDESC_SLOCK(p->p_fd);
|
||||
fd_cmask = p->p_fd->fd_cmask;
|
||||
FILEDESC_SUNLOCK(p->p_fd);
|
||||
PRELE(p);
|
||||
out:
|
||||
error = SYSCTL_OUT(req, &fd_cmask, sizeof(fd_cmask));
|
||||
return (error);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user