2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2002 Doug Rabson
5 * Copyright (c) 1994-1995 Søren Schmidt
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer
13 * in this position and unchanged.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/param.h>
33 #include <sys/fcntl.h>
35 #include <sys/imgact.h>
36 #include <sys/limits.h>
38 #include <sys/msgbuf.h>
39 #include <sys/mutex.h>
43 #include <sys/procctl.h>
44 #include <sys/reboot.h>
45 #include <sys/random.h>
46 #include <sys/resourcevar.h>
47 #include <sys/rtprio.h>
48 #include <sys/sched.h>
51 #include <sys/syscallsubr.h>
52 #include <sys/sysctl.h>
53 #include <sys/sysent.h>
54 #include <sys/sysproto.h>
56 #include <sys/vmmeter.h>
57 #include <sys/vnode.h>
59 #include <security/audit/audit.h>
60 #include <security/mac/mac_framework.h>
63 #include <vm/vm_map.h>
64 #include <vm/swap_pager.h>
67 #include <machine/../linux32/linux.h>
68 #include <machine/../linux32/linux32_proto.h>
70 #include <machine/../linux/linux.h>
71 #include <machine/../linux/linux_proto.h>
74 #include <compat/linux/linux_common.h>
75 #include <compat/linux/linux_dtrace.h>
76 #include <compat/linux/linux_file.h>
77 #include <compat/linux/linux_mib.h>
78 #include <compat/linux/linux_mmap.h>
79 #include <compat/linux/linux_signal.h>
80 #include <compat/linux/linux_time.h>
81 #include <compat/linux/linux_util.h>
82 #include <compat/linux/linux_emul.h>
83 #include <compat/linux/linux_misc.h>
85 int stclohz; /* Statistics clock frequency */
87 static unsigned int linux_to_bsd_resource[LINUX_RLIM_NLIMITS] = {
88 RLIMIT_CPU, RLIMIT_FSIZE, RLIMIT_DATA, RLIMIT_STACK,
89 RLIMIT_CORE, RLIMIT_RSS, RLIMIT_NPROC, RLIMIT_NOFILE,
90 RLIMIT_MEMLOCK, RLIMIT_AS
94 l_long uptime; /* Seconds since boot */
95 l_ulong loads[3]; /* 1, 5, and 15 minute load averages */
96 #define LINUX_SYSINFO_LOADS_SCALE 65536
97 l_ulong totalram; /* Total usable main memory size */
98 l_ulong freeram; /* Available memory size */
99 l_ulong sharedram; /* Amount of shared memory */
100 l_ulong bufferram; /* Memory used by buffers */
101 l_ulong totalswap; /* Total swap space size */
102 l_ulong freeswap; /* swap space still available */
103 l_ushort procs; /* Number of current processes */
108 char _f[20-2*sizeof(l_long)-sizeof(l_int)]; /* padding */
111 struct l_pselect6arg {
116 static int linux_utimensat_lts_to_ts(struct l_timespec *,
118 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
119 static int linux_utimensat_lts64_to_ts(struct l_timespec64 *,
122 static int linux_common_utimensat(struct thread *, int,
123 const char *, struct timespec *, int);
124 static int linux_common_pselect6(struct thread *, l_int,
125 l_fd_set *, l_fd_set *, l_fd_set *,
126 struct timespec *, l_uintptr_t *);
127 static int linux_common_ppoll(struct thread *, struct pollfd *,
128 uint32_t, struct timespec *, l_sigset_t *,
130 static int linux_pollin(struct thread *, struct pollfd *,
131 struct pollfd *, u_int);
132 static int linux_pollout(struct thread *, struct pollfd *,
133 struct pollfd *, u_int);
136 linux_sysinfo(struct thread *td, struct linux_sysinfo_args *args)
138 struct l_sysinfo sysinfo;
142 bzero(&sysinfo, sizeof(sysinfo));
146 sysinfo.uptime = ts.tv_sec;
148 /* Use the information from the mib to get our load averages */
149 for (i = 0; i < 3; i++)
150 sysinfo.loads[i] = averunnable.ldavg[i] *
151 LINUX_SYSINFO_LOADS_SCALE / averunnable.fscale;
153 sysinfo.totalram = physmem * PAGE_SIZE;
154 sysinfo.freeram = (u_long)vm_free_count() * PAGE_SIZE;
157 * sharedram counts pages allocated to named, swap-backed objects such
158 * as shared memory segments and tmpfs files. There is no cheap way to
159 * compute this, so just leave the field unpopulated. Linux itself only
160 * started setting this field in the 3.x timeframe.
162 sysinfo.sharedram = 0;
163 sysinfo.bufferram = 0;
165 swap_pager_status(&i, &j);
166 sysinfo.totalswap = i * PAGE_SIZE;
167 sysinfo.freeswap = (i - j) * PAGE_SIZE;
169 sysinfo.procs = nprocs;
172 * Platforms supported by the emulation layer do not have a notion of
175 sysinfo.totalhigh = 0;
176 sysinfo.freehigh = 0;
178 sysinfo.mem_unit = 1;
180 return (copyout(&sysinfo, args->info, sizeof(sysinfo)));
183 #ifdef LINUX_LEGACY_SYSCALLS
185 linux_alarm(struct thread *td, struct linux_alarm_args *args)
187 struct itimerval it, old_it;
189 int error __diagused;
193 * Linux alarm() is always successful. Limit secs to INT32_MAX / 2
194 * to match kern_setitimer()'s limit to avoid error from it.
196 * XXX. Linux limit secs to INT_MAX on 32 and does not limit on 64-bit
199 if (secs > INT32_MAX / 2)
200 secs = INT32_MAX / 2;
202 it.it_value.tv_sec = secs;
203 it.it_value.tv_usec = 0;
204 timevalclear(&it.it_interval);
205 error = kern_setitimer(td, ITIMER_REAL, &it, &old_it);
206 KASSERT(error == 0, ("kern_setitimer returns %d", error));
208 if ((old_it.it_value.tv_sec == 0 && old_it.it_value.tv_usec > 0) ||
209 old_it.it_value.tv_usec >= 500000)
210 old_it.it_value.tv_sec++;
211 td->td_retval[0] = old_it.it_value.tv_sec;
217 linux_brk(struct thread *td, struct linux_brk_args *args)
219 struct vmspace *vm = td->td_proc->p_vmspace;
222 old = (uintptr_t)vm->vm_daddr + ctob(vm->vm_dsize);
223 new = (uintptr_t)args->dsend;
224 if ((caddr_t)new > vm->vm_daddr && !kern_break(td, &new))
225 td->td_retval[0] = (register_t)new;
227 td->td_retval[0] = (register_t)old;
232 #ifdef LINUX_LEGACY_SYSCALLS
234 linux_select(struct thread *td, struct linux_select_args *args)
237 struct timeval tv0, tv1, utv, *tvp;
241 * Store current time for computation of the amount of
245 if ((error = copyin(args->timeout, <v, sizeof(ltv))))
247 utv.tv_sec = ltv.tv_sec;
248 utv.tv_usec = ltv.tv_usec;
250 if (itimerfix(&utv)) {
252 * The timeval was invalid. Convert it to something
253 * valid that will act as it does under Linux.
255 utv.tv_sec += utv.tv_usec / 1000000;
256 utv.tv_usec %= 1000000;
257 if (utv.tv_usec < 0) {
259 utv.tv_usec += 1000000;
269 error = kern_select(td, args->nfds, args->readfds, args->writefds,
270 args->exceptfds, tvp, LINUX_NFDBITS);
275 if (td->td_retval[0]) {
277 * Compute how much time was left of the timeout,
278 * by subtracting the current time and the time
279 * before we started the call, and subtracting
280 * that result from the user-supplied value.
283 timevalsub(&tv1, &tv0);
284 timevalsub(&utv, &tv1);
289 ltv.tv_sec = utv.tv_sec;
290 ltv.tv_usec = utv.tv_usec;
291 if ((error = copyout(<v, args->timeout, sizeof(ltv))))
301 linux_mremap(struct thread *td, struct linux_mremap_args *args)
307 if (args->flags & ~(LINUX_MREMAP_FIXED | LINUX_MREMAP_MAYMOVE)) {
308 td->td_retval[0] = 0;
313 * Check for the page alignment.
314 * Linux defines PAGE_MASK to be FreeBSD ~PAGE_MASK.
316 if (args->addr & PAGE_MASK) {
317 td->td_retval[0] = 0;
321 args->new_len = round_page(args->new_len);
322 args->old_len = round_page(args->old_len);
324 if (args->new_len > args->old_len) {
325 td->td_retval[0] = 0;
329 if (args->new_len < args->old_len) {
330 addr = args->addr + args->new_len;
331 len = args->old_len - args->new_len;
332 error = kern_munmap(td, addr, len);
335 td->td_retval[0] = error ? 0 : (uintptr_t)args->addr;
339 #define LINUX_MS_ASYNC 0x0001
340 #define LINUX_MS_INVALIDATE 0x0002
341 #define LINUX_MS_SYNC 0x0004
344 linux_msync(struct thread *td, struct linux_msync_args *args)
347 return (kern_msync(td, args->addr, args->len,
348 args->fl & ~LINUX_MS_SYNC));
352 linux_mprotect(struct thread *td, struct linux_mprotect_args *uap)
355 return (linux_mprotect_common(td, PTROUT(uap->addr), uap->len,
360 linux_madvise(struct thread *td, struct linux_madvise_args *uap)
363 return (linux_madvise_common(td, PTROUT(uap->addr), uap->len,
368 linux_mmap2(struct thread *td, struct linux_mmap2_args *uap)
370 #if defined(LINUX_ARCHWANT_MMAP2PGOFF)
372 * For architectures with sizeof (off_t) < sizeof (loff_t) mmap is
373 * implemented with mmap2 syscall and the offset is represented in
374 * multiples of page size.
376 return (linux_mmap_common(td, PTROUT(uap->addr), uap->len, uap->prot,
377 uap->flags, uap->fd, (uint64_t)(uint32_t)uap->pgoff * PAGE_SIZE));
379 return (linux_mmap_common(td, PTROUT(uap->addr), uap->len, uap->prot,
380 uap->flags, uap->fd, uap->pgoff));
384 #ifdef LINUX_LEGACY_SYSCALLS
386 linux_time(struct thread *td, struct linux_time_args *args)
394 if (args->tm && (error = copyout(&tm, args->tm, sizeof(tm))))
396 td->td_retval[0] = tm;
401 struct l_times_argv {
404 l_clock_t tms_cutime;
405 l_clock_t tms_cstime;
409 * Glibc versions prior to 2.2.1 always use hard-coded CLK_TCK value.
410 * Since 2.2.1 Glibc uses value exported from kernel via AT_CLKTCK
411 * auxiliary vector entry.
415 #define CONVOTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK))
416 #define CONVNTCK(r) (r.tv_sec * stclohz + r.tv_usec / (1000000 / stclohz))
418 #define CONVTCK(r) (linux_kernver(td) >= LINUX_KERNVER(2,4,0) ? \
419 CONVNTCK(r) : CONVOTCK(r))
422 linux_times(struct thread *td, struct linux_times_args *args)
424 struct timeval tv, utime, stime, cutime, cstime;
425 struct l_times_argv tms;
429 if (args->buf != NULL) {
433 calcru(p, &utime, &stime);
435 calccru(p, &cutime, &cstime);
438 tms.tms_utime = CONVTCK(utime);
439 tms.tms_stime = CONVTCK(stime);
441 tms.tms_cutime = CONVTCK(cutime);
442 tms.tms_cstime = CONVTCK(cstime);
444 if ((error = copyout(&tms, args->buf, sizeof(tms))))
449 td->td_retval[0] = (int)CONVTCK(tv);
454 linux_newuname(struct thread *td, struct linux_newuname_args *args)
456 struct l_new_utsname utsname;
457 char osname[LINUX_MAX_UTSNAME];
458 char osrelease[LINUX_MAX_UTSNAME];
461 linux_get_osname(td, osname);
462 linux_get_osrelease(td, osrelease);
464 bzero(&utsname, sizeof(utsname));
465 strlcpy(utsname.sysname, osname, LINUX_MAX_UTSNAME);
466 getcredhostname(td->td_ucred, utsname.nodename, LINUX_MAX_UTSNAME);
467 getcreddomainname(td->td_ucred, utsname.domainname, LINUX_MAX_UTSNAME);
468 strlcpy(utsname.release, osrelease, LINUX_MAX_UTSNAME);
469 strlcpy(utsname.version, version, LINUX_MAX_UTSNAME);
470 for (p = utsname.version; *p != '\0'; ++p)
475 #if defined(__amd64__)
477 * On amd64, Linux uname(2) needs to return "x86_64"
478 * for both 64-bit and 32-bit applications. On 32-bit,
479 * the string returned by getauxval(AT_PLATFORM) needs
480 * to remain "i686", though.
482 #if defined(COMPAT_LINUX32)
483 if (linux32_emulate_i386)
484 strlcpy(utsname.machine, "i686", LINUX_MAX_UTSNAME);
487 strlcpy(utsname.machine, "x86_64", LINUX_MAX_UTSNAME);
488 #elif defined(__aarch64__)
489 strlcpy(utsname.machine, "aarch64", LINUX_MAX_UTSNAME);
490 #elif defined(__i386__)
491 strlcpy(utsname.machine, "i686", LINUX_MAX_UTSNAME);
494 return (copyout(&utsname, args->buf, sizeof(utsname)));
502 #ifdef LINUX_LEGACY_SYSCALLS
504 linux_utime(struct thread *td, struct linux_utime_args *args)
506 struct timeval tv[2], *tvp;
507 struct l_utimbuf lut;
511 if ((error = copyin(args->times, &lut, sizeof lut)) != 0)
513 tv[0].tv_sec = lut.l_actime;
515 tv[1].tv_sec = lut.l_modtime;
521 return (kern_utimesat(td, AT_FDCWD, args->fname, UIO_USERSPACE,
526 #ifdef LINUX_LEGACY_SYSCALLS
528 linux_utimes(struct thread *td, struct linux_utimes_args *args)
531 struct timeval tv[2], *tvp = NULL;
534 if (args->tptr != NULL) {
535 if ((error = copyin(args->tptr, ltv, sizeof ltv)) != 0)
537 tv[0].tv_sec = ltv[0].tv_sec;
538 tv[0].tv_usec = ltv[0].tv_usec;
539 tv[1].tv_sec = ltv[1].tv_sec;
540 tv[1].tv_usec = ltv[1].tv_usec;
544 return (kern_utimesat(td, AT_FDCWD, args->fname, UIO_USERSPACE,
550 linux_utimensat_lts_to_ts(struct l_timespec *l_times, struct timespec *times)
553 if (l_times->tv_nsec != LINUX_UTIME_OMIT &&
554 l_times->tv_nsec != LINUX_UTIME_NOW &&
555 (l_times->tv_nsec < 0 || l_times->tv_nsec > 999999999))
558 times->tv_sec = l_times->tv_sec;
559 switch (l_times->tv_nsec)
561 case LINUX_UTIME_OMIT:
562 times->tv_nsec = UTIME_OMIT;
564 case LINUX_UTIME_NOW:
565 times->tv_nsec = UTIME_NOW;
568 times->tv_nsec = l_times->tv_nsec;
575 linux_common_utimensat(struct thread *td, int ldfd, const char *pathname,
576 struct timespec *timesp, int lflags)
580 dfd = (ldfd == LINUX_AT_FDCWD) ? AT_FDCWD : ldfd;
582 if (lflags & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH))
585 if (timesp != NULL) {
586 /* This breaks POSIX, but is what the Linux kernel does
587 * _on purpose_ (documented in the man page for utimensat(2)),
588 * so we must follow that behaviour. */
589 if (timesp[0].tv_nsec == UTIME_OMIT &&
590 timesp[1].tv_nsec == UTIME_OMIT)
594 if (lflags & LINUX_AT_SYMLINK_NOFOLLOW)
595 flags |= AT_SYMLINK_NOFOLLOW;
596 if (lflags & LINUX_AT_EMPTY_PATH)
597 flags |= AT_EMPTY_PATH;
599 if (pathname != NULL)
600 return (kern_utimensat(td, dfd, pathname,
601 UIO_USERSPACE, timesp, UIO_SYSSPACE, flags));
606 return (kern_futimens(td, dfd, timesp, UIO_SYSSPACE));
610 linux_utimensat(struct thread *td, struct linux_utimensat_args *args)
612 struct l_timespec l_times[2];
613 struct timespec times[2], *timesp;
616 if (args->times != NULL) {
617 error = copyin(args->times, l_times, sizeof(l_times));
621 error = linux_utimensat_lts_to_ts(&l_times[0], ×[0]);
624 error = linux_utimensat_lts_to_ts(&l_times[1], ×[1]);
631 return (linux_common_utimensat(td, args->dfd, args->pathname,
632 timesp, args->flags));
635 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
637 linux_utimensat_lts64_to_ts(struct l_timespec64 *l_times, struct timespec *times)
640 /* Zero out the padding in compat mode. */
641 l_times->tv_nsec &= 0xFFFFFFFFUL;
643 if (l_times->tv_nsec != LINUX_UTIME_OMIT &&
644 l_times->tv_nsec != LINUX_UTIME_NOW &&
645 (l_times->tv_nsec < 0 || l_times->tv_nsec > 999999999))
648 times->tv_sec = l_times->tv_sec;
649 switch (l_times->tv_nsec)
651 case LINUX_UTIME_OMIT:
652 times->tv_nsec = UTIME_OMIT;
654 case LINUX_UTIME_NOW:
655 times->tv_nsec = UTIME_NOW;
658 times->tv_nsec = l_times->tv_nsec;
665 linux_utimensat_time64(struct thread *td, struct linux_utimensat_time64_args *args)
667 struct l_timespec64 l_times[2];
668 struct timespec times[2], *timesp;
671 if (args->times64 != NULL) {
672 error = copyin(args->times64, l_times, sizeof(l_times));
676 error = linux_utimensat_lts64_to_ts(&l_times[0], ×[0]);
679 error = linux_utimensat_lts64_to_ts(&l_times[1], ×[1]);
686 return (linux_common_utimensat(td, args->dfd, args->pathname,
687 timesp, args->flags));
689 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
691 #ifdef LINUX_LEGACY_SYSCALLS
693 linux_futimesat(struct thread *td, struct linux_futimesat_args *args)
696 struct timeval tv[2], *tvp = NULL;
699 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
701 if (args->utimes != NULL) {
702 if ((error = copyin(args->utimes, ltv, sizeof ltv)) != 0)
704 tv[0].tv_sec = ltv[0].tv_sec;
705 tv[0].tv_usec = ltv[0].tv_usec;
706 tv[1].tv_sec = ltv[1].tv_sec;
707 tv[1].tv_usec = ltv[1].tv_usec;
711 return (kern_utimesat(td, dfd, args->filename, UIO_USERSPACE,
717 linux_common_wait(struct thread *td, idtype_t idtype, int id, int *statusp,
718 int options, void *rup, l_siginfo_t *infop)
722 struct __wrusage wru;
723 int error, status, tmpstat, sig;
725 error = kern_wait6(td, idtype, id, &status, options,
726 rup != NULL ? &wru : NULL, &siginfo);
728 if (error == 0 && statusp) {
729 tmpstat = status & 0xffff;
730 if (WIFSIGNALED(tmpstat)) {
731 tmpstat = (tmpstat & 0xffffff80) |
732 bsd_to_linux_signal(WTERMSIG(tmpstat));
733 } else if (WIFSTOPPED(tmpstat)) {
734 tmpstat = (tmpstat & 0xffff00ff) |
735 (bsd_to_linux_signal(WSTOPSIG(tmpstat)) << 8);
736 #if defined(__aarch64__) || (defined(__amd64__) && !defined(COMPAT_LINUX32))
737 if (WSTOPSIG(status) == SIGTRAP) {
738 tmpstat = linux_ptrace_status(td,
739 siginfo.si_pid, tmpstat);
742 } else if (WIFCONTINUED(tmpstat)) {
745 error = copyout(&tmpstat, statusp, sizeof(int));
747 if (error == 0 && rup != NULL)
748 error = linux_copyout_rusage(&wru.wru_self, rup);
749 if (error == 0 && infop != NULL && td->td_retval[0] != 0) {
750 sig = bsd_to_linux_signal(siginfo.si_signo);
751 siginfo_to_lsiginfo(&siginfo, &lsi, sig);
752 error = copyout(&lsi, infop, sizeof(lsi));
758 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
760 linux_waitpid(struct thread *td, struct linux_waitpid_args *args)
762 struct linux_wait4_args wait4_args = {
764 .status = args->status,
765 .options = args->options,
769 return (linux_wait4(td, &wait4_args));
771 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
774 linux_wait4(struct thread *td, struct linux_wait4_args *args)
777 int options, id, idtype;
779 if (args->options & ~(LINUX_WUNTRACED | LINUX_WNOHANG |
780 LINUX_WCONTINUED | __WCLONE | __WNOTHREAD | __WALL))
783 /* -INT_MIN is not defined. */
784 if (args->pid == INT_MIN)
788 linux_to_bsd_waitopts(args->options, &options);
791 * For backward compatibility we implicitly add flags WEXITED
794 options |= WEXITED | WTRAPPED;
796 if (args->pid == WAIT_ANY) {
799 } else if (args->pid < 0) {
801 id = (id_t)-args->pid;
802 } else if (args->pid == 0) {
810 id = (id_t)args->pid;
813 return (linux_common_wait(td, idtype, id, args->status, options,
814 args->rusage, NULL));
818 linux_waitid(struct thread *td, struct linux_waitid_args *args)
825 if (args->options & ~(LINUX_WNOHANG | LINUX_WNOWAIT | LINUX_WEXITED |
826 LINUX_WSTOPPED | LINUX_WCONTINUED | __WCLONE | __WNOTHREAD | __WALL))
830 linux_to_bsd_waitopts(args->options, &options);
833 switch (args->idtype) {
843 if (linux_kernver(td) >= LINUX_KERNVER(5,4,0) && args->id == 0) {
848 } else if (args->id <= 0)
853 LINUX_RATELIMIT_MSG("unsupported waitid P_PIDFD idtype");
859 error = linux_common_wait(td, idtype, id, NULL, options,
860 args->rusage, args->info);
861 td->td_retval[0] = 0;
866 #ifdef LINUX_LEGACY_SYSCALLS
868 linux_mknod(struct thread *td, struct linux_mknod_args *args)
872 switch (args->mode & S_IFMT) {
875 error = kern_mkfifoat(td, AT_FDCWD, args->path, UIO_USERSPACE,
881 error = kern_mknodat(td, AT_FDCWD, args->path, UIO_USERSPACE,
882 args->mode, linux_decode_dev(args->dev));
890 args->mode |= S_IFREG;
893 error = kern_openat(td, AT_FDCWD, args->path, UIO_USERSPACE,
894 O_WRONLY | O_CREAT | O_TRUNC, args->mode);
896 kern_close(td, td->td_retval[0]);
908 linux_mknodat(struct thread *td, struct linux_mknodat_args *args)
912 dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
914 switch (args->mode & S_IFMT) {
917 error = kern_mkfifoat(td, dfd, args->filename, UIO_USERSPACE,
923 error = kern_mknodat(td, dfd, args->filename, UIO_USERSPACE,
924 args->mode, linux_decode_dev(args->dev));
932 args->mode |= S_IFREG;
935 error = kern_openat(td, dfd, args->filename, UIO_USERSPACE,
936 O_WRONLY | O_CREAT | O_TRUNC, args->mode);
938 kern_close(td, td->td_retval[0]);
949 * UGH! This is just about the dumbest idea I've ever heard!!
952 linux_personality(struct thread *td, struct linux_personality_args *args)
954 struct linux_pemuldata *pem;
955 struct proc *p = td->td_proc;
961 if (args->per != 0xffffffff)
962 pem->persona = args->per;
965 td->td_retval[0] = old;
970 l_timeval it_interval;
974 #define B2L_ITIMERVAL(bip, lip) \
975 (bip)->it_interval.tv_sec = (lip)->it_interval.tv_sec; \
976 (bip)->it_interval.tv_usec = (lip)->it_interval.tv_usec; \
977 (bip)->it_value.tv_sec = (lip)->it_value.tv_sec; \
978 (bip)->it_value.tv_usec = (lip)->it_value.tv_usec;
981 linux_setitimer(struct thread *td, struct linux_setitimer_args *uap)
984 struct l_itimerval ls;
985 struct itimerval aitv, oitv;
987 if (uap->itv == NULL) {
988 uap->itv = uap->oitv;
989 return (linux_getitimer(td, (struct linux_getitimer_args *)uap));
992 error = copyin(uap->itv, &ls, sizeof(ls));
995 B2L_ITIMERVAL(&aitv, &ls);
996 error = kern_setitimer(td, uap->which, &aitv, &oitv);
997 if (error != 0 || uap->oitv == NULL)
999 B2L_ITIMERVAL(&ls, &oitv);
1001 return (copyout(&ls, uap->oitv, sizeof(ls)));
1005 linux_getitimer(struct thread *td, struct linux_getitimer_args *uap)
1008 struct l_itimerval ls;
1009 struct itimerval aitv;
1011 error = kern_getitimer(td, uap->which, &aitv);
1014 B2L_ITIMERVAL(&ls, &aitv);
1015 return (copyout(&ls, uap->itv, sizeof(ls)));
1018 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
1020 linux_nice(struct thread *td, struct linux_nice_args *args)
1023 return (kern_setpriority(td, PRIO_PROCESS, 0, args->inc));
1025 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
1028 linux_setgroups(struct thread *td, struct linux_setgroups_args *args)
1030 struct ucred *newcred, *oldcred;
1031 l_gid_t *linux_gidset;
1036 ngrp = args->gidsetsize;
1037 if (ngrp < 0 || ngrp >= ngroups_max + 1)
1039 linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK);
1040 error = copyin(args->grouplist, linux_gidset, ngrp * sizeof(l_gid_t));
1044 crextend(newcred, ngrp + 1);
1047 oldcred = p->p_ucred;
1048 crcopy(newcred, oldcred);
1051 * cr_groups[0] holds egid. Setting the whole set from
1052 * the supplied set will cause egid to be changed too.
1053 * Keep cr_groups[0] unchanged to prevent that.
1056 if ((error = priv_check_cred(oldcred, PRIV_CRED_SETGROUPS)) != 0) {
1063 newcred->cr_ngroups = ngrp + 1;
1065 bsd_gidset = newcred->cr_groups;
1068 bsd_gidset[ngrp + 1] = linux_gidset[ngrp];
1072 newcred->cr_ngroups = 1;
1075 proc_set_cred(p, newcred);
1080 free(linux_gidset, M_LINUX);
1085 linux_getgroups(struct thread *td, struct linux_getgroups_args *args)
1088 l_gid_t *linux_gidset;
1090 int bsd_gidsetsz, ngrp, error;
1092 cred = td->td_ucred;
1093 bsd_gidset = cred->cr_groups;
1094 bsd_gidsetsz = cred->cr_ngroups - 1;
1097 * cr_groups[0] holds egid. Returning the whole set
1098 * here will cause a duplicate. Exclude cr_groups[0]
1102 if ((ngrp = args->gidsetsize) == 0) {
1103 td->td_retval[0] = bsd_gidsetsz;
1107 if (ngrp < bsd_gidsetsz)
1111 linux_gidset = malloc(bsd_gidsetsz * sizeof(*linux_gidset),
1113 while (ngrp < bsd_gidsetsz) {
1114 linux_gidset[ngrp] = bsd_gidset[ngrp + 1];
1118 error = copyout(linux_gidset, args->grouplist, ngrp * sizeof(l_gid_t));
1119 free(linux_gidset, M_LINUX);
1123 td->td_retval[0] = ngrp;
1128 linux_get_dummy_limit(l_uint resource, struct rlimit *rlim)
1131 if (linux_dummy_rlimits == 0)
1135 case LINUX_RLIMIT_LOCKS:
1136 case LINUX_RLIMIT_SIGPENDING:
1137 case LINUX_RLIMIT_MSGQUEUE:
1138 case LINUX_RLIMIT_RTTIME:
1139 rlim->rlim_cur = LINUX_RLIM_INFINITY;
1140 rlim->rlim_max = LINUX_RLIM_INFINITY;
1142 case LINUX_RLIMIT_NICE:
1143 case LINUX_RLIMIT_RTPRIO:
1153 linux_setrlimit(struct thread *td, struct linux_setrlimit_args *args)
1155 struct rlimit bsd_rlim;
1156 struct l_rlimit rlim;
1160 if (args->resource >= LINUX_RLIM_NLIMITS)
1163 which = linux_to_bsd_resource[args->resource];
1167 error = copyin(args->rlim, &rlim, sizeof(rlim));
1171 bsd_rlim.rlim_cur = (rlim_t)rlim.rlim_cur;
1172 bsd_rlim.rlim_max = (rlim_t)rlim.rlim_max;
1173 return (kern_setrlimit(td, which, &bsd_rlim));
1176 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
1178 linux_old_getrlimit(struct thread *td, struct linux_old_getrlimit_args *args)
1180 struct l_rlimit rlim;
1181 struct rlimit bsd_rlim;
1184 if (linux_get_dummy_limit(args->resource, &bsd_rlim)) {
1185 rlim.rlim_cur = bsd_rlim.rlim_cur;
1186 rlim.rlim_max = bsd_rlim.rlim_max;
1187 return (copyout(&rlim, args->rlim, sizeof(rlim)));
1190 if (args->resource >= LINUX_RLIM_NLIMITS)
1193 which = linux_to_bsd_resource[args->resource];
1197 lim_rlimit(td, which, &bsd_rlim);
1199 #ifdef COMPAT_LINUX32
1200 rlim.rlim_cur = (unsigned int)bsd_rlim.rlim_cur;
1201 if (rlim.rlim_cur == UINT_MAX)
1202 rlim.rlim_cur = INT_MAX;
1203 rlim.rlim_max = (unsigned int)bsd_rlim.rlim_max;
1204 if (rlim.rlim_max == UINT_MAX)
1205 rlim.rlim_max = INT_MAX;
1207 rlim.rlim_cur = (unsigned long)bsd_rlim.rlim_cur;
1208 if (rlim.rlim_cur == ULONG_MAX)
1209 rlim.rlim_cur = LONG_MAX;
1210 rlim.rlim_max = (unsigned long)bsd_rlim.rlim_max;
1211 if (rlim.rlim_max == ULONG_MAX)
1212 rlim.rlim_max = LONG_MAX;
1214 return (copyout(&rlim, args->rlim, sizeof(rlim)));
1216 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
1219 linux_getrlimit(struct thread *td, struct linux_getrlimit_args *args)
1221 struct l_rlimit rlim;
1222 struct rlimit bsd_rlim;
1225 if (linux_get_dummy_limit(args->resource, &bsd_rlim)) {
1226 rlim.rlim_cur = bsd_rlim.rlim_cur;
1227 rlim.rlim_max = bsd_rlim.rlim_max;
1228 return (copyout(&rlim, args->rlim, sizeof(rlim)));
1231 if (args->resource >= LINUX_RLIM_NLIMITS)
1234 which = linux_to_bsd_resource[args->resource];
1238 lim_rlimit(td, which, &bsd_rlim);
1240 rlim.rlim_cur = (l_ulong)bsd_rlim.rlim_cur;
1241 rlim.rlim_max = (l_ulong)bsd_rlim.rlim_max;
1242 return (copyout(&rlim, args->rlim, sizeof(rlim)));
1246 linux_sched_setscheduler(struct thread *td,
1247 struct linux_sched_setscheduler_args *args)
1249 struct sched_param sched_param;
1253 switch (args->policy) {
1254 case LINUX_SCHED_OTHER:
1255 policy = SCHED_OTHER;
1257 case LINUX_SCHED_FIFO:
1258 policy = SCHED_FIFO;
1260 case LINUX_SCHED_RR:
1267 error = copyin(args->param, &sched_param, sizeof(sched_param));
1271 if (linux_map_sched_prio) {
1274 if (sched_param.sched_priority != 0)
1277 sched_param.sched_priority =
1278 PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE;
1282 if (sched_param.sched_priority < 1 ||
1283 sched_param.sched_priority >= LINUX_MAX_RT_PRIO)
1287 * Map [1, LINUX_MAX_RT_PRIO - 1] to
1288 * [0, RTP_PRIO_MAX - RTP_PRIO_MIN] (rounding down).
1290 sched_param.sched_priority =
1291 (sched_param.sched_priority - 1) *
1292 (RTP_PRIO_MAX - RTP_PRIO_MIN + 1) /
1293 (LINUX_MAX_RT_PRIO - 1);
1298 tdt = linux_tdfind(td, args->pid, -1);
1302 error = kern_sched_setscheduler(td, tdt, policy, &sched_param);
1303 PROC_UNLOCK(tdt->td_proc);
1308 linux_sched_getscheduler(struct thread *td,
1309 struct linux_sched_getscheduler_args *args)
1314 tdt = linux_tdfind(td, args->pid, -1);
1318 error = kern_sched_getscheduler(td, tdt, &policy);
1319 PROC_UNLOCK(tdt->td_proc);
1323 td->td_retval[0] = LINUX_SCHED_OTHER;
1326 td->td_retval[0] = LINUX_SCHED_FIFO;
1329 td->td_retval[0] = LINUX_SCHED_RR;
1336 linux_sched_get_priority_max(struct thread *td,
1337 struct linux_sched_get_priority_max_args *args)
1339 struct sched_get_priority_max_args bsd;
1341 if (linux_map_sched_prio) {
1342 switch (args->policy) {
1343 case LINUX_SCHED_OTHER:
1344 td->td_retval[0] = 0;
1346 case LINUX_SCHED_FIFO:
1347 case LINUX_SCHED_RR:
1348 td->td_retval[0] = LINUX_MAX_RT_PRIO - 1;
1355 switch (args->policy) {
1356 case LINUX_SCHED_OTHER:
1357 bsd.policy = SCHED_OTHER;
1359 case LINUX_SCHED_FIFO:
1360 bsd.policy = SCHED_FIFO;
1362 case LINUX_SCHED_RR:
1363 bsd.policy = SCHED_RR;
1368 return (sys_sched_get_priority_max(td, &bsd));
1372 linux_sched_get_priority_min(struct thread *td,
1373 struct linux_sched_get_priority_min_args *args)
1375 struct sched_get_priority_min_args bsd;
1377 if (linux_map_sched_prio) {
1378 switch (args->policy) {
1379 case LINUX_SCHED_OTHER:
1380 td->td_retval[0] = 0;
1382 case LINUX_SCHED_FIFO:
1383 case LINUX_SCHED_RR:
1384 td->td_retval[0] = 1;
1391 switch (args->policy) {
1392 case LINUX_SCHED_OTHER:
1393 bsd.policy = SCHED_OTHER;
1395 case LINUX_SCHED_FIFO:
1396 bsd.policy = SCHED_FIFO;
1398 case LINUX_SCHED_RR:
1399 bsd.policy = SCHED_RR;
1404 return (sys_sched_get_priority_min(td, &bsd));
1407 #define REBOOT_CAD_ON 0x89abcdef
1408 #define REBOOT_CAD_OFF 0
1409 #define REBOOT_HALT 0xcdef0123
1410 #define REBOOT_RESTART 0x01234567
1411 #define REBOOT_RESTART2 0xA1B2C3D4
1412 #define REBOOT_POWEROFF 0x4321FEDC
1413 #define REBOOT_MAGIC1 0xfee1dead
1414 #define REBOOT_MAGIC2 0x28121969
1415 #define REBOOT_MAGIC2A 0x05121996
1416 #define REBOOT_MAGIC2B 0x16041998
1419 linux_reboot(struct thread *td, struct linux_reboot_args *args)
1421 struct reboot_args bsd_args;
1423 if (args->magic1 != REBOOT_MAGIC1)
1426 switch (args->magic2) {
1428 case REBOOT_MAGIC2A:
1429 case REBOOT_MAGIC2B:
1435 switch (args->cmd) {
1437 case REBOOT_CAD_OFF:
1438 return (priv_check(td, PRIV_REBOOT));
1440 bsd_args.opt = RB_HALT;
1442 case REBOOT_RESTART:
1443 case REBOOT_RESTART2:
1446 case REBOOT_POWEROFF:
1447 bsd_args.opt = RB_POWEROFF;
1452 return (sys_reboot(td, &bsd_args));
1456 linux_getpid(struct thread *td, struct linux_getpid_args *args)
1459 td->td_retval[0] = td->td_proc->p_pid;
1465 linux_gettid(struct thread *td, struct linux_gettid_args *args)
1467 struct linux_emuldata *em;
1470 KASSERT(em != NULL, ("gettid: emuldata not found.\n"));
1472 td->td_retval[0] = em->em_tid;
1478 linux_getppid(struct thread *td, struct linux_getppid_args *args)
1481 td->td_retval[0] = kern_getppid(td);
1486 linux_getgid(struct thread *td, struct linux_getgid_args *args)
1489 td->td_retval[0] = td->td_ucred->cr_rgid;
1494 linux_getuid(struct thread *td, struct linux_getuid_args *args)
1497 td->td_retval[0] = td->td_ucred->cr_ruid;
1502 linux_getsid(struct thread *td, struct linux_getsid_args *args)
1505 return (kern_getsid(td, args->pid));
1509 linux_getpriority(struct thread *td, struct linux_getpriority_args *args)
1513 error = kern_getpriority(td, args->which, args->who);
1514 td->td_retval[0] = 20 - td->td_retval[0];
1519 linux_sethostname(struct thread *td, struct linux_sethostname_args *args)
1524 name[1] = KERN_HOSTNAME;
1525 return (userland_sysctl(td, name, 2, 0, 0, 0, args->hostname,
1530 linux_setdomainname(struct thread *td, struct linux_setdomainname_args *args)
1535 name[1] = KERN_NISDOMAINNAME;
1536 return (userland_sysctl(td, name, 2, 0, 0, 0, args->name,
1541 linux_exit_group(struct thread *td, struct linux_exit_group_args *args)
1544 LINUX_CTR2(exit_group, "thread(%d) (%d)", td->td_tid,
1548 * XXX: we should send a signal to the parent if
1549 * SIGNAL_EXIT_GROUP is set. We ignore that (temporarily?)
1550 * as it doesnt occur often.
1552 exit1(td, args->error_code, 0);
1556 #define _LINUX_CAPABILITY_VERSION_1 0x19980330
1557 #define _LINUX_CAPABILITY_VERSION_2 0x20071026
1558 #define _LINUX_CAPABILITY_VERSION_3 0x20080522
1560 struct l_user_cap_header {
1565 struct l_user_cap_data {
1572 linux_capget(struct thread *td, struct linux_capget_args *uap)
1574 struct l_user_cap_header luch;
1575 struct l_user_cap_data lucd[2];
1578 if (uap->hdrp == NULL)
1581 error = copyin(uap->hdrp, &luch, sizeof(luch));
1585 switch (luch.version) {
1586 case _LINUX_CAPABILITY_VERSION_1:
1589 case _LINUX_CAPABILITY_VERSION_2:
1590 case _LINUX_CAPABILITY_VERSION_3:
1594 luch.version = _LINUX_CAPABILITY_VERSION_1;
1595 error = copyout(&luch, uap->hdrp, sizeof(luch));
1606 * The current implementation doesn't support setting
1607 * a capability (it's essentially a stub) so indicate
1608 * that no capabilities are currently set or available
1611 memset(&lucd, 0, u32s * sizeof(lucd[0]));
1612 error = copyout(&lucd, uap->datap, u32s * sizeof(lucd[0]));
1619 linux_capset(struct thread *td, struct linux_capset_args *uap)
1621 struct l_user_cap_header luch;
1622 struct l_user_cap_data lucd[2];
1625 if (uap->hdrp == NULL || uap->datap == NULL)
1628 error = copyin(uap->hdrp, &luch, sizeof(luch));
1632 switch (luch.version) {
1633 case _LINUX_CAPABILITY_VERSION_1:
1636 case _LINUX_CAPABILITY_VERSION_2:
1637 case _LINUX_CAPABILITY_VERSION_3:
1641 luch.version = _LINUX_CAPABILITY_VERSION_1;
1642 error = copyout(&luch, uap->hdrp, sizeof(luch));
1651 error = copyin(uap->datap, &lucd, u32s * sizeof(lucd[0]));
1655 /* We currently don't support setting any capabilities. */
1656 for (i = 0; i < u32s; i++) {
1657 if (lucd[i].effective || lucd[i].permitted ||
1658 lucd[i].inheritable) {
1660 "capset[%d] effective=0x%x, permitted=0x%x, "
1661 "inheritable=0x%x is not implemented", i,
1662 (int)lucd[i].effective, (int)lucd[i].permitted,
1663 (int)lucd[i].inheritable);
1672 linux_prctl(struct thread *td, struct linux_prctl_args *args)
1674 int error = 0, max_size, arg;
1675 struct proc *p = td->td_proc;
1676 char comm[LINUX_MAX_COMM_LEN];
1677 int pdeath_signal, trace_state;
1679 switch (args->option) {
1680 case LINUX_PR_SET_PDEATHSIG:
1681 if (!LINUX_SIG_VALID(args->arg2))
1683 pdeath_signal = linux_to_bsd_signal(args->arg2);
1684 return (kern_procctl(td, P_PID, 0, PROC_PDEATHSIG_CTL,
1686 case LINUX_PR_GET_PDEATHSIG:
1687 error = kern_procctl(td, P_PID, 0, PROC_PDEATHSIG_STATUS,
1691 pdeath_signal = bsd_to_linux_signal(pdeath_signal);
1692 return (copyout(&pdeath_signal,
1693 (void *)(register_t)args->arg2,
1694 sizeof(pdeath_signal)));
1696 * In Linux, this flag controls if set[gu]id processes can coredump.
1697 * There are additional semantics imposed on processes that cannot
1699 * - Such processes can not be ptraced.
1700 * - There are some semantics around ownership of process-related files
1701 * in the /proc namespace.
1703 * In FreeBSD, we can (and by default, do) disable setuid coredump
1704 * system-wide with 'sugid_coredump.' We control tracability on a
1705 * per-process basis with the procctl PROC_TRACE (=> P2_NOTRACE flag).
1706 * By happy coincidence, P2_NOTRACE also prevents coredumping. So the
1707 * procctl is roughly analogous to Linux's DUMPABLE.
1709 * So, proxy these knobs to the corresponding PROC_TRACE setting.
1711 case LINUX_PR_GET_DUMPABLE:
1712 error = kern_procctl(td, P_PID, p->p_pid, PROC_TRACE_STATUS,
1716 td->td_retval[0] = (trace_state != -1);
1718 case LINUX_PR_SET_DUMPABLE:
1720 * It is only valid for userspace to set one of these two
1721 * flags, and only one at a time.
1723 switch (args->arg2) {
1724 case LINUX_SUID_DUMP_DISABLE:
1725 trace_state = PROC_TRACE_CTL_DISABLE_EXEC;
1727 case LINUX_SUID_DUMP_USER:
1728 trace_state = PROC_TRACE_CTL_ENABLE;
1733 return (kern_procctl(td, P_PID, p->p_pid, PROC_TRACE_CTL,
1735 case LINUX_PR_GET_KEEPCAPS:
1737 * Indicate that we always clear the effective and
1738 * permitted capability sets when the user id becomes
1739 * non-zero (actually the capability sets are simply
1740 * always zero in the current implementation).
1742 td->td_retval[0] = 0;
1744 case LINUX_PR_SET_KEEPCAPS:
1746 * Ignore requests to keep the effective and permitted
1747 * capability sets when the user id becomes non-zero.
1750 case LINUX_PR_SET_NAME:
1752 * To be on the safe side we need to make sure to not
1753 * overflow the size a Linux program expects. We already
1754 * do this here in the copyin, so that we don't need to
1757 max_size = MIN(sizeof(comm), sizeof(p->p_comm));
1758 error = copyinstr((void *)(register_t)args->arg2, comm,
1761 /* Linux silently truncates the name if it is too long. */
1762 if (error == ENAMETOOLONG) {
1764 * XXX: copyinstr() isn't documented to populate the
1765 * array completely, so do a copyin() to be on the
1766 * safe side. This should be changed in case
1767 * copyinstr() is changed to guarantee this.
1769 error = copyin((void *)(register_t)args->arg2, comm,
1771 comm[max_size - 1] = '\0';
1777 strlcpy(p->p_comm, comm, sizeof(p->p_comm));
1780 case LINUX_PR_GET_NAME:
1782 strlcpy(comm, p->p_comm, sizeof(comm));
1784 error = copyout(comm, (void *)(register_t)args->arg2,
1787 case LINUX_PR_GET_SECCOMP:
1788 case LINUX_PR_SET_SECCOMP:
1790 * Same as returned by Linux without CONFIG_SECCOMP enabled.
1794 case LINUX_PR_CAPBSET_READ:
1797 * This makes too much noise with Ubuntu Focal.
1799 linux_msg(td, "unsupported prctl PR_CAPBSET_READ %d",
1804 case LINUX_PR_SET_NO_NEW_PRIVS:
1805 arg = args->arg2 == 1 ?
1806 PROC_NO_NEW_PRIVS_ENABLE : PROC_NO_NEW_PRIVS_DISABLE;
1807 error = kern_procctl(td, P_PID, p->p_pid,
1808 PROC_NO_NEW_PRIVS_CTL, &arg);
1810 case LINUX_PR_SET_PTRACER:
1811 linux_msg(td, "unsupported prctl PR_SET_PTRACER");
1815 linux_msg(td, "unsupported prctl option %d", args->option);
1824 linux_sched_setparam(struct thread *td,
1825 struct linux_sched_setparam_args *uap)
1827 struct sched_param sched_param;
1831 error = copyin(uap->param, &sched_param, sizeof(sched_param));
1835 tdt = linux_tdfind(td, uap->pid, -1);
1839 if (linux_map_sched_prio) {
1840 error = kern_sched_getscheduler(td, tdt, &policy);
1846 if (sched_param.sched_priority != 0) {
1850 sched_param.sched_priority =
1851 PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE;
1855 if (sched_param.sched_priority < 1 ||
1856 sched_param.sched_priority >= LINUX_MAX_RT_PRIO) {
1861 * Map [1, LINUX_MAX_RT_PRIO - 1] to
1862 * [0, RTP_PRIO_MAX - RTP_PRIO_MIN] (rounding down).
1864 sched_param.sched_priority =
1865 (sched_param.sched_priority - 1) *
1866 (RTP_PRIO_MAX - RTP_PRIO_MIN + 1) /
1867 (LINUX_MAX_RT_PRIO - 1);
1872 error = kern_sched_setparam(td, tdt, &sched_param);
1873 out: PROC_UNLOCK(tdt->td_proc);
1878 linux_sched_getparam(struct thread *td,
1879 struct linux_sched_getparam_args *uap)
1881 struct sched_param sched_param;
1885 tdt = linux_tdfind(td, uap->pid, -1);
1889 error = kern_sched_getparam(td, tdt, &sched_param);
1891 PROC_UNLOCK(tdt->td_proc);
1895 if (linux_map_sched_prio) {
1896 error = kern_sched_getscheduler(td, tdt, &policy);
1897 PROC_UNLOCK(tdt->td_proc);
1903 sched_param.sched_priority = 0;
1908 * Map [0, RTP_PRIO_MAX - RTP_PRIO_MIN] to
1909 * [1, LINUX_MAX_RT_PRIO - 1] (rounding up).
1911 sched_param.sched_priority =
1912 (sched_param.sched_priority *
1913 (LINUX_MAX_RT_PRIO - 1) +
1914 (RTP_PRIO_MAX - RTP_PRIO_MIN - 1)) /
1915 (RTP_PRIO_MAX - RTP_PRIO_MIN) + 1;
1919 PROC_UNLOCK(tdt->td_proc);
1921 error = copyout(&sched_param, uap->param, sizeof(sched_param));
1926 * Get affinity of a process.
1929 linux_sched_getaffinity(struct thread *td,
1930 struct linux_sched_getaffinity_args *args)
1938 tdt = linux_tdfind(td, args->pid, -1);
1942 PROC_UNLOCK(tdt->td_proc);
1944 mask = malloc(sizeof(cpuset_t), M_LINUX, M_WAITOK | M_ZERO);
1945 size = min(args->len, sizeof(cpuset_t));
1946 error = kern_cpuset_getaffinity(td, CPU_LEVEL_WHICH, CPU_WHICH_TID,
1948 if (error == ERANGE)
1951 error = copyout(mask, args->user_mask_ptr, size);
1953 td->td_retval[0] = size;
1954 free(mask, M_LINUX);
1959 * Set affinity of a process.
1962 linux_sched_setaffinity(struct thread *td,
1963 struct linux_sched_setaffinity_args *args)
1971 tdt = linux_tdfind(td, args->pid, -1);
1975 PROC_UNLOCK(tdt->td_proc);
1977 len = min(args->len, sizeof(cpuset_t));
1978 mask = malloc(sizeof(cpuset_t), M_TEMP, M_WAITOK | M_ZERO);;
1979 error = copyin(args->user_mask_ptr, mask, len);
1982 /* Linux ignore high bits */
1983 CPU_FOREACH_ISSET(cpu, mask)
1987 error = kern_cpuset_setaffinity(td, CPU_LEVEL_WHICH, CPU_WHICH_TID,
1989 if (error == EDEADLK)
1996 struct linux_rlimit64 {
2002 linux_prlimit64(struct thread *td, struct linux_prlimit64_args *args)
2004 struct rlimit rlim, nrlim;
2005 struct linux_rlimit64 lrlim;
2011 if (args->new == NULL && args->old != NULL) {
2012 if (linux_get_dummy_limit(args->resource, &rlim)) {
2013 lrlim.rlim_cur = rlim.rlim_cur;
2014 lrlim.rlim_max = rlim.rlim_max;
2015 return (copyout(&lrlim, args->old, sizeof(lrlim)));
2019 if (args->resource >= LINUX_RLIM_NLIMITS)
2022 which = linux_to_bsd_resource[args->resource];
2026 if (args->new != NULL) {
2028 * Note. Unlike FreeBSD where rlim is signed 64-bit Linux
2029 * rlim is unsigned 64-bit. FreeBSD treats negative limits
2030 * as INFINITY so we do not need a conversion even.
2032 error = copyin(args->new, &nrlim, sizeof(nrlim));
2037 flags = PGET_HOLD | PGET_NOTWEXIT;
2038 if (args->new != NULL)
2039 flags |= PGET_CANDEBUG;
2041 flags |= PGET_CANSEE;
2042 if (args->pid == 0) {
2046 error = pget(args->pid, flags, &p);
2050 if (args->old != NULL) {
2052 lim_rlimit_proc(p, which, &rlim);
2054 if (rlim.rlim_cur == RLIM_INFINITY)
2055 lrlim.rlim_cur = LINUX_RLIM_INFINITY;
2057 lrlim.rlim_cur = rlim.rlim_cur;
2058 if (rlim.rlim_max == RLIM_INFINITY)
2059 lrlim.rlim_max = LINUX_RLIM_INFINITY;
2061 lrlim.rlim_max = rlim.rlim_max;
2062 error = copyout(&lrlim, args->old, sizeof(lrlim));
2067 if (args->new != NULL)
2068 error = kern_proc_setrlimit(td, p, which, &nrlim);
2076 linux_pselect6(struct thread *td, struct linux_pselect6_args *args)
2078 struct timespec ts, *tsp;
2081 if (args->tsp != NULL) {
2082 error = linux_get_timespec(&ts, args->tsp);
2089 error = linux_common_pselect6(td, args->nfds, args->readfds,
2090 args->writefds, args->exceptfds, tsp, args->sig);
2092 if (args->tsp != NULL)
2093 linux_put_timespec(&ts, args->tsp);
2098 linux_common_pselect6(struct thread *td, l_int nfds, l_fd_set *readfds,
2099 l_fd_set *writefds, l_fd_set *exceptfds, struct timespec *tsp,
2102 struct timeval utv, tv0, tv1, *tvp;
2103 struct l_pselect6arg lpse6;
2110 error = copyin(sig, &lpse6, sizeof(lpse6));
2113 error = linux_copyin_sigset(td, PTRIN(lpse6.ss),
2114 lpse6.ss_len, &ss, &ssp);
2121 * Currently glibc changes nanosecond number to microsecond.
2122 * This mean losing precision but for now it is hardly seen.
2125 TIMESPEC_TO_TIMEVAL(&utv, tsp);
2126 if (itimerfix(&utv))
2134 error = kern_pselect(td, nfds, readfds, writefds,
2135 exceptfds, tvp, ssp, LINUX_NFDBITS);
2139 * Compute how much time was left of the timeout,
2140 * by subtracting the current time and the time
2141 * before we started the call, and subtracting
2142 * that result from the user-supplied value.
2145 timevalsub(&tv1, &tv0);
2146 timevalsub(&utv, &tv1);
2149 TIMEVAL_TO_TIMESPEC(&utv, tsp);
2154 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
2156 linux_pselect6_time64(struct thread *td,
2157 struct linux_pselect6_time64_args *args)
2159 struct timespec ts, *tsp;
2162 if (args->tsp != NULL) {
2163 error = linux_get_timespec64(&ts, args->tsp);
2170 error = linux_common_pselect6(td, args->nfds, args->readfds,
2171 args->writefds, args->exceptfds, tsp, args->sig);
2173 if (args->tsp != NULL)
2174 linux_put_timespec64(&ts, args->tsp);
2177 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
2180 linux_ppoll(struct thread *td, struct linux_ppoll_args *args)
2182 struct timespec uts, *tsp;
2185 if (args->tsp != NULL) {
2186 error = linux_get_timespec(&uts, args->tsp);
2193 error = linux_common_ppoll(td, args->fds, args->nfds, tsp,
2194 args->sset, args->ssize);
2195 if (error == 0 && args->tsp != NULL)
2196 error = linux_put_timespec(&uts, args->tsp);
2201 linux_common_ppoll(struct thread *td, struct pollfd *fds, uint32_t nfds,
2202 struct timespec *tsp, l_sigset_t *sset, l_size_t ssize)
2204 struct timespec ts0, ts1;
2205 struct pollfd stackfds[32];
2206 struct pollfd *kfds;
2211 if (kern_poll_maxfds(nfds))
2214 error = linux_copyin_sigset(td, sset, ssize, &ss, &ssp);
2222 if (nfds > nitems(stackfds))
2223 kfds = mallocarray(nfds, sizeof(*kfds), M_TEMP, M_WAITOK);
2226 error = linux_pollin(td, kfds, fds, nfds);
2230 error = kern_poll_kfds(td, kfds, nfds, tsp, ssp);
2232 error = linux_pollout(td, kfds, fds, nfds);
2234 if (error == 0 && tsp != NULL) {
2235 if (td->td_retval[0]) {
2237 timespecsub(&ts1, &ts0, &ts1);
2238 timespecsub(tsp, &ts1, tsp);
2239 if (tsp->tv_sec < 0)
2246 if (nfds > nitems(stackfds))
2251 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
2253 linux_ppoll_time64(struct thread *td, struct linux_ppoll_time64_args *args)
2255 struct timespec uts, *tsp;
2258 if (args->tsp != NULL) {
2259 error = linux_get_timespec64(&uts, args->tsp);
2265 error = linux_common_ppoll(td, args->fds, args->nfds, tsp,
2266 args->sset, args->ssize);
2267 if (error == 0 && args->tsp != NULL)
2268 error = linux_put_timespec64(&uts, args->tsp);
2271 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
2274 linux_pollin(struct thread *td, struct pollfd *fds, struct pollfd *ufds, u_int nfd)
2279 error = copyin(ufds, fds, nfd * sizeof(*fds));
2283 for (i = 0; i < nfd; i++) {
2284 if (fds->events != 0)
2285 linux_to_bsd_poll_events(td, fds->fd,
2286 fds->events, &fds->events);
2293 linux_pollout(struct thread *td, struct pollfd *fds, struct pollfd *ufds, u_int nfd)
2298 for (i = 0; i < nfd; i++) {
2299 if (fds->revents != 0) {
2300 bsd_to_linux_poll_events(fds->revents,
2304 error = copyout(&fds->revents, &ufds->revents,
2305 sizeof(ufds->revents));
2311 td->td_retval[0] = n;
2316 linux_sched_rr_get_interval_common(struct thread *td, pid_t pid,
2317 struct timespec *ts)
2323 * According to man in case the invalid pid specified
2324 * EINVAL should be returned.
2329 tdt = linux_tdfind(td, pid, -1);
2333 error = kern_sched_rr_get_interval_td(td, tdt, ts);
2334 PROC_UNLOCK(tdt->td_proc);
2339 linux_sched_rr_get_interval(struct thread *td,
2340 struct linux_sched_rr_get_interval_args *uap)
2345 error = linux_sched_rr_get_interval_common(td, uap->pid, &ts);
2348 return (linux_put_timespec(&ts, uap->interval));
2351 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
2353 linux_sched_rr_get_interval_time64(struct thread *td,
2354 struct linux_sched_rr_get_interval_time64_args *uap)
2359 error = linux_sched_rr_get_interval_common(td, uap->pid, &ts);
2362 return (linux_put_timespec64(&ts, uap->interval));
2367 * In case when the Linux thread is the initial thread in
2368 * the thread group thread id is equal to the process id.
2369 * Glibc depends on this magic (assert in pthread_getattr_np.c).
2372 linux_tdfind(struct thread *td, lwpid_t tid, pid_t pid)
2374 struct linux_emuldata *em;
2379 if (tid == 0 || tid == td->td_tid) {
2380 if (pid != -1 && td->td_proc->p_pid != pid)
2382 PROC_LOCK(td->td_proc);
2384 } else if (tid > PID_MAX)
2385 return (tdfind(tid, pid));
2388 * Initial thread where the tid equal to the pid.
2392 if (SV_PROC_ABI(p) != SV_ABI_LINUX ||
2393 (pid != -1 && tid != pid)) {
2395 * p is not a Linuxulator process.
2400 FOREACH_THREAD_IN_PROC(p, tdt) {
2402 if (tid == em->em_tid)
2411 linux_to_bsd_waitopts(int options, int *bsdopts)
2414 if (options & LINUX_WNOHANG)
2415 *bsdopts |= WNOHANG;
2416 if (options & LINUX_WUNTRACED)
2417 *bsdopts |= WUNTRACED;
2418 if (options & LINUX_WEXITED)
2419 *bsdopts |= WEXITED;
2420 if (options & LINUX_WCONTINUED)
2421 *bsdopts |= WCONTINUED;
2422 if (options & LINUX_WNOWAIT)
2423 *bsdopts |= WNOWAIT;
2425 if (options & __WCLONE)
2426 *bsdopts |= WLINUXCLONE;
2430 linux_getrandom(struct thread *td, struct linux_getrandom_args *args)
2436 if (args->flags & ~(LINUX_GRND_NONBLOCK|LINUX_GRND_RANDOM))
2438 if (args->count > INT_MAX)
2439 args->count = INT_MAX;
2441 iov.iov_base = args->buf;
2442 iov.iov_len = args->count;
2446 uio.uio_resid = iov.iov_len;
2447 uio.uio_segflg = UIO_USERSPACE;
2448 uio.uio_rw = UIO_READ;
2451 error = read_random_uio(&uio, args->flags & LINUX_GRND_NONBLOCK);
2453 td->td_retval[0] = args->count - uio.uio_resid;
2458 linux_mincore(struct thread *td, struct linux_mincore_args *args)
2461 /* Needs to be page-aligned */
2462 if (args->start & PAGE_MASK)
2464 return (kern_mincore(td, args->start, args->len, args->vec));
2467 #define SYSLOG_TAG "<6>"
2470 linux_syslog(struct thread *td, struct linux_syslog_args *args)
2472 char buf[128], *src, *dst;
2476 if (args->type != LINUX_SYSLOG_ACTION_READ_ALL) {
2477 linux_msg(td, "syslog unsupported type 0x%x", args->type);
2481 if (args->len < 6) {
2482 td->td_retval[0] = 0;
2486 error = priv_check(td, PRIV_MSGBUF);
2490 mtx_lock(&msgbuf_lock);
2491 msgbuf_peekbytes(msgbufp, NULL, 0, &seq);
2492 mtx_unlock(&msgbuf_lock);
2495 error = copyout(&SYSLOG_TAG, dst, sizeof(SYSLOG_TAG));
2496 /* The -1 is to skip the trailing '\0'. */
2497 dst += sizeof(SYSLOG_TAG) - 1;
2499 while (error == 0) {
2500 mtx_lock(&msgbuf_lock);
2501 buflen = msgbuf_peekbytes(msgbufp, buf, sizeof(buf), &seq);
2502 mtx_unlock(&msgbuf_lock);
2507 for (src = buf; src < buf + buflen && error == 0; src++) {
2511 if (dst >= args->buf + args->len)
2514 error = copyout(src, dst, 1);
2517 if (*src == '\n' && *(src + 1) != '<' &&
2518 dst + sizeof(SYSLOG_TAG) < args->buf + args->len) {
2519 error = copyout(&SYSLOG_TAG,
2520 dst, sizeof(SYSLOG_TAG));
2521 dst += sizeof(SYSLOG_TAG) - 1;
2526 td->td_retval[0] = dst - args->buf;
2531 linux_getcpu(struct thread *td, struct linux_getcpu_args *args)
2533 int cpu, error, node;
2535 cpu = td->td_oncpu; /* Make sure it doesn't change during copyout(9) */
2537 node = cpuid_to_pcpu[cpu]->pc_domain;
2539 if (args->cpu != NULL)
2540 error = copyout(&cpu, args->cpu, sizeof(l_int));
2541 if (args->node != NULL)
2542 error = copyout(&node, args->node, sizeof(l_int));
2546 #if defined(__i386__) || defined(__amd64__)
2548 linux_poll(struct thread *td, struct linux_poll_args *args)
2550 struct timespec ts, *tsp;
2552 if (args->timeout != INFTIM) {
2553 if (args->timeout < 0)
2555 ts.tv_sec = args->timeout / 1000;
2556 ts.tv_nsec = (args->timeout % 1000) * 1000000;
2561 return (linux_common_ppoll(td, args->fds, args->nfds,
2564 #endif /* __i386__ || __amd64__ */
2567 linux_seccomp(struct thread *td, struct linux_seccomp_args *args)
2571 case LINUX_SECCOMP_GET_ACTION_AVAIL:
2572 return (EOPNOTSUPP);
2575 * Ignore unknown operations, just like Linux kernel built
2576 * without CONFIG_SECCOMP.
2583 * Custom version of exec_copyin_args(), to copy out argument and environment
2584 * strings from the old process address space into the temporary string buffer.
2585 * Based on freebsd32_exec_copyin_args.
2588 linux_exec_copyin_args(struct image_args *args, const char *fname,
2589 enum uio_seg segflg, l_uintptr_t *argv, l_uintptr_t *envv)
2592 l_uintptr_t *ptr, arg;
2595 bzero(args, sizeof(*args));
2600 * Allocate demand-paged memory for the file name, argument, and
2601 * environment strings.
2603 error = exec_alloc_args(args);
2608 * Copy the file name.
2610 error = exec_args_add_fname(args, fname, segflg);
2615 * extract arguments first
2619 error = copyin(ptr++, &arg, sizeof(arg));
2625 error = exec_args_add_arg(args, argp, UIO_USERSPACE);
2631 * This comment is from Linux do_execveat_common:
2632 * When argv is empty, add an empty string ("") as argv[0] to
2633 * ensure confused userspace programs that start processing
2634 * from argv[1] won't end up walking envp.
2636 if (args->argc == 0 &&
2637 (error = exec_args_add_arg(args, "", UIO_SYSSPACE) != 0))
2641 * extract environment strings
2646 error = copyin(ptr++, &arg, sizeof(arg));
2652 error = exec_args_add_env(args, envp, UIO_USERSPACE);
2661 exec_free_args(args);
2666 linux_execve(struct thread *td, struct linux_execve_args *args)
2668 struct image_args eargs;
2673 error = linux_exec_copyin_args(&eargs, args->path, UIO_USERSPACE,
2674 args->argp, args->envp);
2676 error = linux_common_execve(td, &eargs);
2677 AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
2682 linux_up_rtprio_if(struct thread *td1, struct rtprio *rtp)
2686 pri_to_rtp(td1, &rtp2);
2687 if (rtp2.type < rtp->type ||
2688 (rtp2.type == rtp->type &&
2689 rtp2.prio < rtp->prio)) {
2690 rtp->type = rtp2.type;
2691 rtp->prio = rtp2.prio;
2695 #define LINUX_PRIO_DIVIDER RTP_PRIO_MAX / LINUX_IOPRIO_MAX
2698 linux_rtprio2ioprio(struct rtprio *rtp)
2702 switch (rtp->type) {
2704 prio = RTP_PRIO_MIN;
2705 ioprio = LINUX_IOPRIO_PRIO(LINUX_IOPRIO_CLASS_IDLE, prio);
2707 case RTP_PRIO_NORMAL:
2708 prio = rtp->prio / LINUX_PRIO_DIVIDER;
2709 ioprio = LINUX_IOPRIO_PRIO(LINUX_IOPRIO_CLASS_BE, prio);
2711 case RTP_PRIO_REALTIME:
2712 prio = rtp->prio / LINUX_PRIO_DIVIDER;
2713 ioprio = LINUX_IOPRIO_PRIO(LINUX_IOPRIO_CLASS_RT, prio);
2716 prio = RTP_PRIO_MIN;
2717 ioprio = LINUX_IOPRIO_PRIO(LINUX_IOPRIO_CLASS_NONE, prio);
2724 linux_ioprio2rtprio(int ioprio, struct rtprio *rtp)
2727 switch (LINUX_IOPRIO_PRIO_CLASS(ioprio)) {
2728 case LINUX_IOPRIO_CLASS_IDLE:
2729 rtp->prio = RTP_PRIO_MIN;
2730 rtp->type = RTP_PRIO_IDLE;
2732 case LINUX_IOPRIO_CLASS_BE:
2733 rtp->prio = LINUX_IOPRIO_PRIO_DATA(ioprio) * LINUX_PRIO_DIVIDER;
2734 rtp->type = RTP_PRIO_NORMAL;
2736 case LINUX_IOPRIO_CLASS_RT:
2737 rtp->prio = LINUX_IOPRIO_PRIO_DATA(ioprio) * LINUX_PRIO_DIVIDER;
2738 rtp->type = RTP_PRIO_REALTIME;
2745 #undef LINUX_PRIO_DIVIDER
2748 linux_ioprio_get(struct thread *td, struct linux_ioprio_get_args *args)
2760 rtp.type = RTP_PRIO_IDLE;
2761 rtp.prio = RTP_PRIO_MAX;
2762 switch (args->which) {
2763 case LINUX_IOPRIO_WHO_PROCESS:
2764 if (args->who == 0) {
2768 } else if (args->who > PID_MAX) {
2769 td1 = linux_tdfind(td, args->who, -1);
2773 p = pfind(args->who);
2776 if ((error = p_cansee(td, p))) {
2781 pri_to_rtp(td1, &rtp);
2783 FOREACH_THREAD_IN_PROC(p, td1) {
2784 linux_up_rtprio_if(td1, &rtp);
2790 case LINUX_IOPRIO_WHO_PGRP:
2791 sx_slock(&proctree_lock);
2792 if (args->who == 0) {
2793 pg = td->td_proc->p_pgrp;
2796 pg = pgfind(args->who);
2798 sx_sunlock(&proctree_lock);
2803 sx_sunlock(&proctree_lock);
2804 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
2806 if (p->p_state == PRS_NORMAL &&
2807 p_cansee(td, p) == 0) {
2808 FOREACH_THREAD_IN_PROC(p, td1) {
2809 linux_up_rtprio_if(td1, &rtp);
2817 case LINUX_IOPRIO_WHO_USER:
2819 args->who = td->td_ucred->cr_uid;
2820 sx_slock(&allproc_lock);
2821 FOREACH_PROC_IN_SYSTEM(p) {
2823 if (p->p_state == PRS_NORMAL &&
2824 p->p_ucred->cr_uid == args->who &&
2825 p_cansee(td, p) == 0) {
2826 FOREACH_THREAD_IN_PROC(p, td1) {
2827 linux_up_rtprio_if(td1, &rtp);
2833 sx_sunlock(&allproc_lock);
2841 td->td_retval[0] = linux_rtprio2ioprio(&rtp);
2849 linux_ioprio_set(struct thread *td, struct linux_ioprio_set_args *args)
2857 if ((error = linux_ioprio2rtprio(args->ioprio, &rtp)) != 0)
2859 /* Attempts to set high priorities (REALTIME) require su privileges. */
2860 if (RTP_PRIO_BASE(rtp.type) == RTP_PRIO_REALTIME &&
2861 (error = priv_check(td, PRIV_SCHED_RTPRIO)) != 0)
2866 switch (args->which) {
2867 case LINUX_IOPRIO_WHO_PROCESS:
2868 if (args->who == 0) {
2872 } else if (args->who > PID_MAX) {
2873 td1 = linux_tdfind(td, args->who, -1);
2877 p = pfind(args->who);
2880 if ((error = p_cansched(td, p))) {
2885 error = rtp_to_pri(&rtp, td1);
2887 FOREACH_THREAD_IN_PROC(p, td1) {
2888 if ((error = rtp_to_pri(&rtp, td1)) != 0)
2894 case LINUX_IOPRIO_WHO_PGRP:
2895 sx_slock(&proctree_lock);
2896 if (args->who == 0) {
2897 pg = td->td_proc->p_pgrp;
2900 pg = pgfind(args->who);
2902 sx_sunlock(&proctree_lock);
2907 sx_sunlock(&proctree_lock);
2908 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
2910 if (p->p_state == PRS_NORMAL &&
2911 p_cansched(td, p) == 0) {
2912 FOREACH_THREAD_IN_PROC(p, td1) {
2913 if ((error = rtp_to_pri(&rtp, td1)) != 0)
2923 case LINUX_IOPRIO_WHO_USER:
2925 args->who = td->td_ucred->cr_uid;
2926 sx_slock(&allproc_lock);
2927 FOREACH_PROC_IN_SYSTEM(p) {
2929 if (p->p_state == PRS_NORMAL &&
2930 p->p_ucred->cr_uid == args->who &&
2931 p_cansched(td, p) == 0) {
2932 FOREACH_THREAD_IN_PROC(p, td1) {
2933 if ((error = rtp_to_pri(&rtp, td1)) != 0)
2941 sx_sunlock(&allproc_lock);