2 * Copyright (c) 1994-1995 Søren Schmidt
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software withough specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * $FreeBSD: src/sys/compat/linux/linux_misc.c,v 1.85.2.9 2002/09/24 08:11:41 mdodd Exp $
29 * $DragonFly: src/sys/emulation/linux/linux_misc.c,v 1.39 2007/06/26 19:31:03 dillon Exp $
32 #include "opt_compat.h"
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/fcntl.h>
37 #include <sys/imgact_aout.h>
38 #include <sys/kernel.h>
39 #include <sys/kern_syscall.h>
42 #include <sys/mount.h>
46 #include <sys/nlookup.h>
47 #include <sys/blist.h>
48 #include <sys/reboot.h>
49 #include <sys/resourcevar.h>
50 #include <sys/signalvar.h>
52 #include <sys/sysctl.h>
53 #include <sys/sysproto.h>
55 #include <sys/unistd.h>
56 #include <sys/vmmeter.h>
57 #include <sys/vnode.h>
60 #include <sys/signal2.h>
61 #include <sys/thread2.h>
62 #include <sys/mplock2.h>
66 #include <vm/vm_kern.h>
67 #include <vm/vm_map.h>
68 #include <vm/vm_extern.h>
69 #include <vm/vm_object.h>
70 #include <vm/vm_zone.h>
71 #include <vm/swap_pager.h>
73 #include <machine/frame.h>
74 #include <machine/limits.h>
75 #include <machine/psl.h>
76 #include <machine/sysarch.h>
78 #include <machine/segments.h>
81 #include <sys/sched.h>
83 #include <emulation/linux/linux_sysproto.h>
84 #include <arch_linux/linux.h>
85 #include <arch_linux/linux_proto.h>
86 #include "linux_mib.h"
87 #include "linux_util.h"
88 #include "linux_emuldata.h"
89 #include "i386/linux.h"
91 #define BSD_TO_LINUX_SIGNAL(sig) \
92 (((sig) <= LINUX_SIGTBLSZ) ? bsd_to_linux_signal[_SIG_IDX(sig)] : sig)
94 static unsigned int linux_to_bsd_resource
[LINUX_RLIM_NLIMITS
] = {
95 RLIMIT_CPU
, RLIMIT_FSIZE
, RLIMIT_DATA
, RLIMIT_STACK
,
96 RLIMIT_CORE
, RLIMIT_RSS
, RLIMIT_NPROC
, RLIMIT_NOFILE
,
101 l_long uptime
; /* Seconds since boot */
102 l_ulong loads
[3]; /* 1, 5, and 15 minute load averages */
103 l_ulong totalram
; /* Total usable main memory size */
104 l_ulong freeram
; /* Available memory size */
105 l_ulong sharedram
; /* Amount of shared memory */
106 l_ulong bufferram
; /* Memory used by buffers */
107 l_ulong totalswap
; /* Total swap space size */
108 l_ulong freeswap
; /* swap space still available */
109 l_ushort procs
; /* Number of current processes */
110 char _f
[22]; /* Pads structure to 64 bytes */
114 sys_linux_madvise(struct linux_madvise_args
*args
)
123 sys_linux_sysinfo(struct linux_sysinfo_args
*args
)
125 struct l_sysinfo sysinfo
;
131 /* Uptime is copied out of print_uptime() in kern_shutdown.c */
134 if (ts
.tv_sec
>= 86400) {
138 if (i
|| ts
.tv_sec
>= 3600) {
142 if (i
|| ts
.tv_sec
>= 60) {
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
];
152 sysinfo
.totalram
= Maxmem
* PAGE_SIZE
;
153 sysinfo
.freeram
= sysinfo
.totalram
- vmstats
.v_wire_count
* PAGE_SIZE
;
156 sysinfo
.sharedram
= 0;
157 for (object
= TAILQ_FIRST(&vm_object_list
); object
!= NULL
;
158 object
= TAILQ_NEXT(object
, object_list
)) {
159 if (object
->type
== OBJT_MARKER
)
161 if (object
->shadow_count
> 1)
162 sysinfo
.sharedram
+= object
->resident_page_count
;
165 sysinfo
.sharedram
*= PAGE_SIZE
;
166 sysinfo
.bufferram
= 0;
168 if (swapblist
== NULL
) {
169 sysinfo
.totalswap
= 0;
170 sysinfo
.freeswap
= 0;
172 sysinfo
.totalswap
= swapblist
->bl_blocks
* 1024;
173 sysinfo
.freeswap
= swapblist
->bl_root
->u
.bmu_avail
* PAGE_SIZE
;
177 sysinfo
.procs
= 20; /* Hack */
179 error
= copyout(&sysinfo
, (caddr_t
)args
->info
, sizeof(sysinfo
));
187 sys_linux_alarm(struct linux_alarm_args
*args
)
189 struct thread
*td
= curthread
;
190 struct proc
*p
= td
->td_proc
;
191 struct itimerval it
, old_it
;
196 kprintf(ARGS(alarm
, "%u"), args
->secs
);
199 if (args
->secs
> 100000000)
202 it
.it_value
.tv_sec
= (long)args
->secs
;
203 it
.it_value
.tv_usec
= 0;
204 it
.it_interval
.tv_sec
= 0;
205 it
.it_interval
.tv_usec
= 0;
208 old_it
= p
->p_realtimer
;
210 if (timevalisset(&old_it
.it_value
))
211 callout_stop(&p
->p_ithandle
);
212 if (it
.it_value
.tv_sec
!= 0) {
213 callout_reset(&p
->p_ithandle
, tvtohz_high(&it
.it_value
),
215 timevaladd(&it
.it_value
, &tv
);
220 if (timevalcmp(&old_it
.it_value
, &tv
, >)) {
221 timevalsub(&old_it
.it_value
, &tv
);
222 if (old_it
.it_value
.tv_usec
!= 0)
223 old_it
.it_value
.tv_sec
++;
224 args
->sysmsg_result
= old_it
.it_value
.tv_sec
;
233 sys_linux_brk(struct linux_brk_args
*args
)
235 struct thread
*td
= curthread
;
236 struct proc
*p
= td
->td_proc
;
238 vm_offset_t
new, old
;
239 struct obreak_args bsd_args
;
245 kprintf(ARGS(brk
, "%p"), (void *)args
->dsend
);
247 old
= (vm_offset_t
)vm
->vm_daddr
+ ctob(vm
->vm_dsize
);
248 new = (vm_offset_t
)args
->dsend
;
249 bsd_args
.sysmsg_result
= 0;
250 bsd_args
.nsize
= (char *) new;
251 bsd_args
.sysmsg_result
= 0;
252 if (((caddr_t
)new > vm
->vm_daddr
) && !sys_obreak(&bsd_args
))
253 args
->sysmsg_result
= (long)new;
255 args
->sysmsg_result
= (long)old
;
265 sys_linux_uselib(struct linux_uselib_args
*args
)
267 struct thread
*td
= curthread
;
269 struct nlookupdata nd
;
274 unsigned long file_offset
;
276 unsigned long bss_size
;
283 error
= linux_copyin_path(args
->library
, &path
, LINUX_PATH_EXISTS
);
288 kprintf(ARGS(uselib
, "%s"), path
);
296 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
297 nd
.nl_flags
|= NLC_EXEC
;
299 error
= nlookup(&nd
);
301 error
= cache_vget(&nd
.nl_nch
, nd
.nl_cred
, LK_EXCLUSIVE
, &vp
);
305 * From here on down, we have a locked vnode that must be unlocked.
310 if (vp
->v_writecount
) {
316 error
= VOP_GETATTR(vp
, &attr
);
320 if ((vp
->v_mount
->mnt_flag
& MNT_NOEXEC
) ||
321 ((attr
.va_mode
& 0111) == 0) || (attr
.va_type
!= VREG
)) {
327 if (attr
.va_size
== 0) {
332 error
= VOP_OPEN(vp
, FREAD
, td
->td_ucred
, NULL
);
337 * Lock no longer needed
342 /* Pull in executable header into kernel_map */
343 error
= vm_mmap(&kernel_map
, (vm_offset_t
*)&a_out
, PAGE_SIZE
,
344 VM_PROT_READ
, VM_PROT_READ
, 0, (caddr_t
)vp
, 0);
348 /* Is it a Linux binary ? */
349 if (((a_out
->a_magic
>> 16) & 0xff) != 0x64) {
355 * While we are here, we should REALLY do some more checks
358 /* Set file/virtual offset based on a.out variant. */
359 switch ((int)(a_out
->a_magic
& 0xffff)) {
360 case 0413: /* ZMAGIC */
363 case 0314: /* QMAGIC */
371 bss_size
= round_page(a_out
->a_bss
);
373 /* Check various fields in header for validity/bounds. */
374 if (a_out
->a_text
& PAGE_MASK
|| a_out
->a_data
& PAGE_MASK
) {
379 /* text + data can't exceed file size */
380 if (a_out
->a_data
+ a_out
->a_text
> attr
.va_size
) {
386 * text/data/bss must not exceed limits
387 * XXX - this is not complete. it should check current usage PLUS
388 * the resources needed by this library.
390 if (a_out
->a_text
> maxtsiz
||
391 a_out
->a_data
+ bss_size
> p
->p_rlimit
[RLIMIT_DATA
].rlim_cur
) {
396 /* prevent more writers */
397 vsetflags(vp
, VTEXT
);
400 * Check if file_offset page aligned. Currently we cannot handle
401 * misalinged file offsets, and so we read in the entire image
404 if (file_offset
& PAGE_MASK
) {
406 kprintf("uselib: Non page aligned binary %lu\n", file_offset
);
408 /* Map text+data read/write/execute */
410 /* a_entry is the load address and is page aligned */
411 vmaddr
= trunc_page(a_out
->a_entry
);
413 /* get anon user mapping, read+write+execute */
414 error
= vm_map_find(&p
->p_vmspace
->vm_map
, NULL
, 0,
415 &vmaddr
, a_out
->a_text
+ a_out
->a_data
,
417 FALSE
, VM_MAPTYPE_NORMAL
,
418 VM_PROT_ALL
, VM_PROT_ALL
,
423 /* map file into kernel_map */
424 error
= vm_mmap(&kernel_map
, &buffer
,
425 round_page(a_out
->a_text
+ a_out
->a_data
+ file_offset
),
426 VM_PROT_READ
, VM_PROT_READ
, 0, (caddr_t
)vp
,
427 trunc_page(file_offset
));
431 /* copy from kernel VM space to user space */
432 error
= copyout((caddr_t
)(uintptr_t)(buffer
+ file_offset
),
433 (caddr_t
)vmaddr
, a_out
->a_text
+ a_out
->a_data
);
435 /* release temporary kernel space */
436 vm_map_remove(&kernel_map
, buffer
, buffer
+
437 round_page(a_out
->a_text
+ a_out
->a_data
+ file_offset
));
443 kprintf("uselib: Page aligned binary %lu\n", file_offset
);
446 * for QMAGIC, a_entry is 20 bytes beyond the load address
447 * to skip the executable header
449 vmaddr
= trunc_page(a_out
->a_entry
);
452 * Map it all into the process's space as a single
453 * copy-on-write "data" segment.
455 error
= vm_mmap(&p
->p_vmspace
->vm_map
, &vmaddr
,
456 a_out
->a_text
+ a_out
->a_data
, VM_PROT_ALL
, VM_PROT_ALL
,
457 MAP_PRIVATE
| MAP_FIXED
, (caddr_t
)vp
, file_offset
);
462 kprintf("mem=%08lx = %08lx %08lx\n", (long)vmaddr
, ((long*)vmaddr
)[0],
466 /* Calculate BSS start address */
467 vmaddr
= trunc_page(a_out
->a_entry
) + a_out
->a_text
+
470 /* allocate some 'anon' space */
471 error
= vm_map_find(&p
->p_vmspace
->vm_map
, NULL
, 0,
474 FALSE
, VM_MAPTYPE_NORMAL
,
475 VM_PROT_ALL
, VM_PROT_ALL
,
482 /* Unlock/release vnode */
488 /* Release the kernel mapping. */
490 vm_map_remove(&kernel_map
, (vm_offset_t
)a_out
,
491 (vm_offset_t
)a_out
+ PAGE_SIZE
);
495 linux_free_path(&path
);
503 sys_linux_select(struct linux_select_args
*args
)
505 struct select_args bsa
;
506 struct timeval tv0
, tv1
, utv
, *tvp
;
512 kprintf(ARGS(select
, "%d, %p, %p, %p, %p"), args
->nfds
,
513 (void *)args
->readfds
, (void *)args
->writefds
,
514 (void *)args
->exceptfds
, (void *)args
->timeout
);
518 bsa
.sysmsg_result
= 0;
520 bsa
.in
= args
->readfds
;
521 bsa
.ou
= args
->writefds
;
522 bsa
.ex
= args
->exceptfds
;
523 bsa
.tv
= (struct timeval
*)args
->timeout
;
526 * Store current time for computation of the amount of
530 if ((error
= copyin((caddr_t
)args
->timeout
, &utv
,
535 kprintf(LMSG("incoming timeout (%ld/%ld)"),
536 utv
.tv_sec
, utv
.tv_usec
);
539 if (itimerfix(&utv
)) {
541 * The timeval was invalid. Convert it to something
542 * valid that will act as it does under Linux.
544 sg
= stackgap_init();
545 tvp
= stackgap_alloc(&sg
, sizeof(utv
));
546 utv
.tv_sec
+= utv
.tv_usec
/ 1000000;
547 utv
.tv_usec
%= 1000000;
548 if (utv
.tv_usec
< 0) {
550 utv
.tv_usec
+= 1000000;
554 if ((error
= copyout(&utv
, tvp
, sizeof(utv
))))
561 error
= sys_select(&bsa
);
562 args
->sysmsg_result
= bsa
.sysmsg_result
;
565 kprintf(LMSG("real select returns %d"), error
);
569 * See fs/select.c in the Linux kernel. Without this,
570 * Maelstrom doesn't work.
572 if (error
== ERESTART
)
578 if (args
->sysmsg_result
) {
580 * Compute how much time was left of the timeout,
581 * by subtracting the current time and the time
582 * before we started the call, and subtracting
583 * that result from the user-supplied value.
586 timevalsub(&tv1
, &tv0
);
587 timevalsub(&utv
, &tv1
);
594 kprintf(LMSG("outgoing timeout (%ld/%ld)"),
595 utv
.tv_sec
, utv
.tv_usec
);
597 if ((error
= copyout(&utv
, (caddr_t
)args
->timeout
,
605 kprintf(LMSG("select_out -> %d"), error
);
614 sys_linux_mremap(struct linux_mremap_args
*args
)
616 struct munmap_args bsd_args
;
621 kprintf(ARGS(mremap
, "%p, %08lx, %08lx, %08lx"),
623 (unsigned long)args
->old_len
,
624 (unsigned long)args
->new_len
,
625 (unsigned long)args
->flags
);
627 if (args
->flags
& ~(LINUX_MREMAP_FIXED
| LINUX_MREMAP_MAYMOVE
)) {
628 args
->sysmsg_resultp
= NULL
;
633 * Check for the page alignment.
634 * Linux defines PAGE_MASK to be FreeBSD ~PAGE_MASK.
636 if (args
->addr
& PAGE_MASK
) {
637 args
->sysmsg_resultp
= NULL
;
641 args
->new_len
= round_page(args
->new_len
);
642 args
->old_len
= round_page(args
->old_len
);
644 if (args
->new_len
> args
->old_len
) {
645 args
->sysmsg_result
= 0;
649 if (args
->new_len
< args
->old_len
) {
650 bsd_args
.sysmsg_result
= 0;
651 bsd_args
.addr
= (caddr_t
)(args
->addr
+ args
->new_len
);
652 bsd_args
.len
= args
->old_len
- args
->new_len
;
653 error
= sys_munmap(&bsd_args
);
656 args
->sysmsg_resultp
= error
? NULL
: (void *)args
->addr
;
660 #define LINUX_MS_ASYNC 0x0001
661 #define LINUX_MS_INVALIDATE 0x0002
662 #define LINUX_MS_SYNC 0x0004
668 sys_linux_msync(struct linux_msync_args
*args
)
670 struct msync_args bsd_args
;
673 bsd_args
.addr
= (caddr_t
)args
->addr
;
674 bsd_args
.len
= args
->len
;
675 bsd_args
.flags
= args
->fl
& ~LINUX_MS_SYNC
;
676 bsd_args
.sysmsg_result
= 0;
678 error
= sys_msync(&bsd_args
);
679 args
->sysmsg_result
= bsd_args
.sysmsg_result
;
687 sys_linux_time(struct linux_time_args
*args
)
695 kprintf(ARGS(time
, "*"));
700 if (args
->tm
&& (error
= copyout(&tm
, (caddr_t
)args
->tm
, sizeof(tm
))))
702 args
->sysmsg_lresult
= tm
;
706 struct l_times_argv
{
713 #define CLK_TCK 100 /* Linux uses 100 */
715 #define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK))
721 sys_linux_times(struct linux_times_args
*args
)
723 struct thread
*td
= curthread
;
724 struct proc
*p
= td
->td_proc
;
726 struct l_times_argv tms
;
732 kprintf(ARGS(times
, "*"));
739 tms
.tms_utime
= CONVTCK(ru
.ru_utime
);
740 tms
.tms_stime
= CONVTCK(ru
.ru_stime
);
742 tms
.tms_cutime
= CONVTCK(p
->p_cru
.ru_utime
);
743 tms
.tms_cstime
= CONVTCK(p
->p_cru
.ru_stime
);
745 if ((error
= copyout(&tms
, (caddr_t
)args
->buf
, sizeof(tms
))))
749 args
->sysmsg_result
= (int)CONVTCK(tv
);
757 sys_linux_newuname(struct linux_newuname_args
*args
)
759 struct thread
*td
= curthread
;
760 struct l_new_utsname utsname
;
761 char *osrelease
, *osname
;
764 if (ldebug(newuname
))
765 kprintf(ARGS(newuname
, "*"));
769 osname
= linux_get_osname(td
);
770 osrelease
= linux_get_osrelease(td
);
772 bzero(&utsname
, sizeof(utsname
));
773 strncpy(utsname
.sysname
, osname
, LINUX_MAX_UTSNAME
-1);
774 strncpy(utsname
.nodename
, hostname
, LINUX_MAX_UTSNAME
-1);
775 strncpy(utsname
.release
, osrelease
, LINUX_MAX_UTSNAME
-1);
776 strncpy(utsname
.version
, version
, LINUX_MAX_UTSNAME
-1);
777 strncpy(utsname
.machine
, machine
, LINUX_MAX_UTSNAME
-1);
778 strncpy(utsname
.domainname
, domainname
, LINUX_MAX_UTSNAME
-1);
781 return (copyout(&utsname
, (caddr_t
)args
->buf
, sizeof(utsname
)));
784 /* XXX: why would this be i386-only? most of these are wrong! */
785 #if defined(__i386__)
795 sys_linux_utime(struct linux_utime_args
*args
)
797 struct timeval tv
[2];
798 struct l_utimbuf lut
;
799 struct nlookupdata nd
;
803 error
= linux_copyin_path(args
->fname
, &path
, LINUX_PATH_EXISTS
);
808 kprintf(ARGS(utime
, "%s, *"), path
);
812 error
= copyin(args
->times
, &lut
, sizeof(lut
));
815 tv
[0].tv_sec
= lut
.l_actime
;
817 tv
[1].tv_sec
= lut
.l_modtime
;
821 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
823 error
= kern_utimes(&nd
, args
->times
? tv
: NULL
);
827 linux_free_path(&path
);
832 sys_linux_utimes(struct linux_utimes_args
*args
)
835 struct timeval tv
[2], *tvp
= NULL
;
836 struct nlookupdata nd
;
840 error
= linux_copyin_path(args
->fname
, &path
, LINUX_PATH_EXISTS
);
845 kprintf(ARGS(utimes
, "%s, *"), path
);
849 error
= copyin(args
->tptr
, ltv
, sizeof(ltv
));
852 tv
[0].tv_sec
= ltv
[0].tv_sec
;
853 tv
[0].tv_usec
= ltv
[0].tv_usec
;
854 tv
[1].tv_sec
= ltv
[1].tv_sec
;
855 tv
[1].tv_usec
= ltv
[1].tv_usec
;
859 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
861 error
= kern_utimes(&nd
, tvp
);
865 linux_free_path(&path
);
870 sys_linux_futimesat(struct linux_futimesat_args
*args
)
873 struct timeval tv
[2], *tvp
= NULL
;
875 struct nlookupdata nd
;
879 error
= linux_copyin_path(args
->fname
, &path
, LINUX_PATH_EXISTS
);
883 if (ldebug(futimesat
))
884 kprintf(ARGS(futimesat
, "%s, *"), path
);
887 error
= copyin(args
->tptr
, ltv
, sizeof(ltv
));
890 tv
[0].tv_sec
= ltv
[0].tv_sec
;
891 tv
[0].tv_usec
= ltv
[0].tv_usec
;
892 tv
[1].tv_sec
= ltv
[1].tv_sec
;
893 tv
[1].tv_usec
= ltv
[1].tv_usec
;
896 dfd
= (args
->dfd
== LINUX_AT_FDCWD
) ? AT_FDCWD
: args
->dfd
;
898 error
= nlookup_init_at(&nd
, &fp
, dfd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
900 error
= kern_utimes(&nd
, tvp
);
901 nlookup_done_at(&nd
, fp
);
904 linux_free_path(&path
);
910 sys_linux_utimensat(struct linux_utimensat_args
*args
)
912 struct l_timespec ltv
[2];
913 struct timeval tv
[2], *tvp
= NULL
;
915 struct nlookupdata nd
;
917 int dfd
, flags
, error
= 0;
919 if (args
->flag
& ~LINUX_AT_SYMLINK_NOFOLLOW
)
922 if (args
->dfd
== LINUX_AT_FDCWD
&& args
->fname
== NULL
)
926 error
= linux_copyin_path(args
->fname
, &path
, LINUX_PATH_EXISTS
);
931 if (ldebug(utimensat
))
932 kprintf(ARGS(utimensat
, "%s, *"), path
);
935 error
= copyin(args
->tptr
, ltv
, sizeof(ltv
));
939 if (ltv
[0].tv_sec
== LINUX_UTIME_NOW
) {
941 } else if (ltv
[0].tv_sec
== LINUX_UTIME_OMIT
) {
942 /* XXX: this is not right, but will do for now */
945 tv
[0].tv_sec
= ltv
[0].tv_sec
;
946 /* XXX: we lose precision here, as we don't have ns */
947 tv
[0].tv_usec
= ltv
[0].tv_nsec
/1000;
949 if (ltv
[1].tv_sec
== LINUX_UTIME_NOW
) {
951 } else if (ltv
[1].tv_sec
== LINUX_UTIME_OMIT
) {
952 /* XXX: this is not right, but will do for now */
955 tv
[1].tv_sec
= ltv
[1].tv_sec
;
956 /* XXX: we lose precision here, as we don't have ns */
957 tv
[1].tv_usec
= ltv
[1].tv_nsec
/1000;
962 dfd
= (args
->dfd
== LINUX_AT_FDCWD
) ? AT_FDCWD
: args
->dfd
;
963 flags
= (args
->flag
& LINUX_AT_SYMLINK_NOFOLLOW
) ? 0 : NLC_FOLLOW
;
967 error
= nlookup_init_at(&nd
, &fp
, dfd
, path
, UIO_SYSSPACE
, flags
);
969 error
= kern_utimes(&nd
, tvp
);
970 nlookup_done_at(&nd
, fp
);
972 /* Thank you, Linux, for another non-standard "feature" */
973 KKASSERT(dfd
!= AT_FDCWD
);
974 error
= kern_futimes(dfd
, tvp
);
979 linux_free_path(&path
);
983 #endif /* __i386__ */
985 #define __WCLONE 0x80000000
991 sys_linux_waitpid(struct linux_waitpid_args
*args
)
993 int error
, options
, status
;
997 kprintf(ARGS(waitpid
, "%d, %p, %d"),
998 args
->pid
, (void *)args
->status
, args
->options
);
1000 options
= args
->options
& (WNOHANG
| WUNTRACED
);
1001 /* WLINUXCLONE should be equal to __WCLONE, but we make sure */
1002 if (args
->options
& __WCLONE
)
1003 options
|= WLINUXCLONE
;
1005 error
= kern_wait(args
->pid
, args
->status
? &status
: NULL
, options
,
1006 NULL
, &args
->sysmsg_result
);
1008 if (error
== 0 && args
->status
) {
1010 if (WIFSIGNALED(status
))
1011 status
= (status
& 0xffffff80) |
1012 BSD_TO_LINUX_SIGNAL(WTERMSIG(status
));
1013 else if (WIFSTOPPED(status
))
1014 status
= (status
& 0xffff00ff) |
1015 (BSD_TO_LINUX_SIGNAL(WSTOPSIG(status
)) << 8);
1016 error
= copyout(&status
, args
->status
, sizeof(status
));
1026 sys_linux_wait4(struct linux_wait4_args
*args
)
1028 struct thread
*td
= curthread
;
1029 struct lwp
*lp
= td
->td_lwp
;
1030 struct rusage rusage
;
1031 int error
, options
, status
;
1035 kprintf(ARGS(wait4
, "%d, %p, %d, %p"),
1036 args
->pid
, (void *)args
->status
, args
->options
,
1037 (void *)args
->rusage
);
1039 options
= args
->options
& (WNOHANG
| WUNTRACED
);
1040 /* WLINUXCLONE should be equal to __WCLONE, but we make sure */
1041 if (args
->options
& __WCLONE
)
1042 options
|= WLINUXCLONE
;
1044 error
= kern_wait(args
->pid
, args
->status
? &status
: NULL
, options
,
1045 args
->rusage
? &rusage
: NULL
, &args
->sysmsg_result
);
1048 lwp_delsig(lp
, SIGCHLD
);
1050 if (error
== 0 && args
->status
) {
1052 if (WIFSIGNALED(status
))
1053 status
= (status
& 0xffffff80) |
1054 BSD_TO_LINUX_SIGNAL(WTERMSIG(status
));
1055 else if (WIFSTOPPED(status
))
1056 status
= (status
& 0xffff00ff) |
1057 (BSD_TO_LINUX_SIGNAL(WSTOPSIG(status
)) << 8);
1058 error
= copyout(&status
, args
->status
, sizeof(status
));
1060 if (error
== 0 && args
->rusage
)
1061 error
= copyout(&rusage
, args
->rusage
, sizeof(rusage
));
1070 sys_linux_mknod(struct linux_mknod_args
*args
)
1072 struct nlookupdata nd
;
1076 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_CREATE
);
1081 kprintf(ARGS(mknod
, "%s, %d, %d"),
1082 path
, args
->mode
, args
->dev
);
1085 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, 0);
1087 if (args
->mode
& S_IFIFO
) {
1088 error
= kern_mkfifo(&nd
, args
->mode
);
1090 error
= kern_mknod(&nd
, args
->mode
,
1098 linux_free_path(&path
);
1103 sys_linux_mknodat(struct linux_mknodat_args
*args
)
1105 struct nlookupdata nd
;
1110 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_CREATE
);
1115 kprintf(ARGS(mknod
, "%s, %d, %d"),
1116 path
, args
->mode
, args
->dev
);
1119 dfd
= (args
->dfd
== LINUX_AT_FDCWD
) ? AT_FDCWD
: args
->dfd
;
1120 error
= nlookup_init_at(&nd
, &fp
, dfd
, path
, UIO_SYSSPACE
, 0);
1122 if (args
->mode
& S_IFIFO
) {
1123 error
= kern_mkfifo(&nd
, args
->mode
);
1125 error
= kern_mknod(&nd
, args
->mode
,
1130 nlookup_done_at(&nd
, fp
);
1133 linux_free_path(&path
);
1138 * UGH! This is just about the dumbest idea I've ever heard!!
1143 sys_linux_personality(struct linux_personality_args
*args
)
1146 if (ldebug(personality
))
1147 kprintf(ARGS(personality
, "%d"), args
->per
);
1152 /* Yes Jim, it's still a Linux... */
1153 args
->sysmsg_result
= 0;
1158 * Wrappers for get/setitimer for debugging..
1163 sys_linux_setitimer(struct linux_setitimer_args
*args
)
1165 struct setitimer_args bsa
;
1166 struct itimerval foo
;
1170 if (ldebug(setitimer
))
1171 kprintf(ARGS(setitimer
, "%p, %p"),
1172 (void *)args
->itv
, (void *)args
->oitv
);
1174 bsa
.which
= args
->which
;
1175 bsa
.itv
= (struct itimerval
*)args
->itv
;
1176 bsa
.oitv
= (struct itimerval
*)args
->oitv
;
1177 bsa
.sysmsg_result
= 0;
1179 if ((error
= copyin((caddr_t
)args
->itv
, &foo
, sizeof(foo
))))
1182 if (ldebug(setitimer
)) {
1183 kprintf("setitimer: value: sec: %ld, usec: %ld\n",
1184 foo
.it_value
.tv_sec
, foo
.it_value
.tv_usec
);
1185 kprintf("setitimer: interval: sec: %ld, usec: %ld\n",
1186 foo
.it_interval
.tv_sec
, foo
.it_interval
.tv_usec
);
1190 error
= sys_setitimer(&bsa
);
1191 args
->sysmsg_result
= bsa
.sysmsg_result
;
1199 sys_linux_getitimer(struct linux_getitimer_args
*args
)
1201 struct getitimer_args bsa
;
1204 if (ldebug(getitimer
))
1205 kprintf(ARGS(getitimer
, "%p"), (void *)args
->itv
);
1207 bsa
.which
= args
->which
;
1208 bsa
.itv
= (struct itimerval
*)args
->itv
;
1209 bsa
.sysmsg_result
= 0;
1210 error
= sys_getitimer(&bsa
);
1211 args
->sysmsg_result
= bsa
.sysmsg_result
;
1219 sys_linux_nice(struct linux_nice_args
*args
)
1221 struct setpriority_args bsd_args
;
1224 bsd_args
.which
= PRIO_PROCESS
;
1225 bsd_args
.who
= 0; /* current process */
1226 bsd_args
.prio
= args
->inc
;
1227 bsd_args
.sysmsg_result
= 0;
1228 error
= sys_setpriority(&bsd_args
);
1229 args
->sysmsg_result
= bsd_args
.sysmsg_result
;
1237 sys_linux_setgroups(struct linux_setgroups_args
*args
)
1239 struct thread
*td
= curthread
;
1240 struct proc
*p
= td
->td_proc
;
1241 struct ucred
*newcred
, *oldcred
;
1242 l_gid_t linux_gidset
[NGROUPS
];
1246 ngrp
= args
->gidsetsize
;
1247 oldcred
= td
->td_ucred
;
1250 * cr_groups[0] holds egid. Setting the whole set from
1251 * the supplied set will cause egid to be changed too.
1252 * Keep cr_groups[0] unchanged to prevent that.
1255 if ((error
= priv_check_cred(oldcred
, PRIV_CRED_SETGROUPS
, 0)) != 0)
1258 if ((u_int
)ngrp
>= NGROUPS
)
1262 newcred
= crdup(oldcred
);
1264 error
= copyin((caddr_t
)args
->grouplist
, linux_gidset
,
1265 ngrp
* sizeof(l_gid_t
));
1272 newcred
->cr_ngroups
= ngrp
+ 1;
1274 bsd_gidset
= newcred
->cr_groups
;
1277 bsd_gidset
[ngrp
+ 1] = linux_gidset
[ngrp
];
1281 newcred
->cr_ngroups
= 1;
1285 oldcred
= p
->p_ucred
; /* reload, deal with threads race */
1286 p
->p_ucred
= newcred
;
1296 sys_linux_getgroups(struct linux_getgroups_args
*args
)
1298 struct thread
*td
= curthread
;
1300 l_gid_t linux_gidset
[NGROUPS
];
1302 int bsd_gidsetsz
, ngrp
, error
;
1304 cred
= td
->td_ucred
;
1305 bsd_gidset
= cred
->cr_groups
;
1306 bsd_gidsetsz
= cred
->cr_ngroups
- 1;
1309 * cr_groups[0] holds egid. Returning the whole set
1310 * here will cause a duplicate. Exclude cr_groups[0]
1314 if ((ngrp
= args
->gidsetsize
) == 0) {
1315 args
->sysmsg_result
= bsd_gidsetsz
;
1319 if ((u_int
)ngrp
< bsd_gidsetsz
)
1323 while (ngrp
< bsd_gidsetsz
) {
1324 linux_gidset
[ngrp
] = bsd_gidset
[ngrp
+ 1];
1328 if ((error
= copyout(linux_gidset
, args
->grouplist
,
1329 ngrp
* sizeof(l_gid_t
)))) {
1333 args
->sysmsg_result
= ngrp
;
1341 sys_linux_setrlimit(struct linux_setrlimit_args
*args
)
1343 struct l_rlimit linux_rlim
;
1349 if (ldebug(setrlimit
))
1350 kprintf(ARGS(setrlimit
, "%d, %p"),
1351 args
->resource
, (void *)args
->rlim
);
1353 if (args
->resource
>= LINUX_RLIM_NLIMITS
)
1355 which
= linux_to_bsd_resource
[args
->resource
];
1359 error
= copyin(args
->rlim
, &linux_rlim
, sizeof(linux_rlim
));
1362 rlim
.rlim_cur
= (rlim_t
)linux_rlim
.rlim_cur
;
1363 rlim
.rlim_max
= (rlim_t
)linux_rlim
.rlim_max
;
1365 error
= kern_setrlimit(which
, &rlim
);
1374 sys_linux_old_getrlimit(struct linux_old_getrlimit_args
*args
)
1376 struct l_rlimit linux_rlim
;
1382 if (ldebug(old_getrlimit
))
1383 kprintf(ARGS(old_getrlimit
, "%d, %p"),
1384 args
->resource
, (void *)args
->rlim
);
1386 if (args
->resource
>= LINUX_RLIM_NLIMITS
)
1388 which
= linux_to_bsd_resource
[args
->resource
];
1392 error
= kern_getrlimit(which
, &rlim
);
1395 linux_rlim
.rlim_cur
= (l_ulong
)rlim
.rlim_cur
;
1396 if (linux_rlim
.rlim_cur
== ULONG_MAX
)
1397 linux_rlim
.rlim_cur
= LONG_MAX
;
1398 linux_rlim
.rlim_max
= (l_ulong
)rlim
.rlim_max
;
1399 if (linux_rlim
.rlim_max
== ULONG_MAX
)
1400 linux_rlim
.rlim_max
= LONG_MAX
;
1401 error
= copyout(&linux_rlim
, args
->rlim
, sizeof(linux_rlim
));
1410 sys_linux_getrlimit(struct linux_getrlimit_args
*args
)
1412 struct l_rlimit linux_rlim
;
1418 if (ldebug(getrlimit
))
1419 kprintf(ARGS(getrlimit
, "%d, %p"),
1420 args
->resource
, (void *)args
->rlim
);
1422 if (args
->resource
>= LINUX_RLIM_NLIMITS
)
1424 which
= linux_to_bsd_resource
[args
->resource
];
1428 error
= kern_getrlimit(which
, &rlim
);
1431 linux_rlim
.rlim_cur
= (l_ulong
)rlim
.rlim_cur
;
1432 linux_rlim
.rlim_max
= (l_ulong
)rlim
.rlim_max
;
1433 error
= copyout(&linux_rlim
, args
->rlim
, sizeof(linux_rlim
));
1442 sys_linux_sched_setscheduler(struct linux_sched_setscheduler_args
*args
)
1444 struct sched_setscheduler_args bsd
;
1448 if (ldebug(sched_setscheduler
))
1449 kprintf(ARGS(sched_setscheduler
, "%d, %d, %p"),
1450 args
->pid
, args
->policy
, (const void *)args
->param
);
1453 switch (args
->policy
) {
1454 case LINUX_SCHED_OTHER
:
1455 bsd
.policy
= SCHED_OTHER
;
1457 case LINUX_SCHED_FIFO
:
1458 bsd
.policy
= SCHED_FIFO
;
1460 case LINUX_SCHED_RR
:
1461 bsd
.policy
= SCHED_RR
;
1467 bsd
.pid
= args
->pid
;
1468 bsd
.param
= (struct sched_param
*)args
->param
;
1469 bsd
.sysmsg_result
= 0;
1471 error
= sys_sched_setscheduler(&bsd
);
1472 args
->sysmsg_result
= bsd
.sysmsg_result
;
1480 sys_linux_sched_getscheduler(struct linux_sched_getscheduler_args
*args
)
1482 struct sched_getscheduler_args bsd
;
1486 if (ldebug(sched_getscheduler
))
1487 kprintf(ARGS(sched_getscheduler
, "%d"), args
->pid
);
1490 bsd
.sysmsg_result
= 0;
1491 bsd
.pid
= args
->pid
;
1492 error
= sys_sched_getscheduler(&bsd
);
1493 args
->sysmsg_result
= bsd
.sysmsg_result
;
1495 switch (args
->sysmsg_result
) {
1497 args
->sysmsg_result
= LINUX_SCHED_OTHER
;
1500 args
->sysmsg_result
= LINUX_SCHED_FIFO
;
1503 args
->sysmsg_result
= LINUX_SCHED_RR
;
1513 sys_linux_sched_get_priority_max(struct linux_sched_get_priority_max_args
*args
)
1515 struct sched_get_priority_max_args bsd
;
1519 if (ldebug(sched_get_priority_max
))
1520 kprintf(ARGS(sched_get_priority_max
, "%d"), args
->policy
);
1523 switch (args
->policy
) {
1524 case LINUX_SCHED_OTHER
:
1525 bsd
.policy
= SCHED_OTHER
;
1527 case LINUX_SCHED_FIFO
:
1528 bsd
.policy
= SCHED_FIFO
;
1530 case LINUX_SCHED_RR
:
1531 bsd
.policy
= SCHED_RR
;
1536 bsd
.sysmsg_result
= 0;
1538 error
= sys_sched_get_priority_max(&bsd
);
1539 args
->sysmsg_result
= bsd
.sysmsg_result
;
1547 sys_linux_sched_get_priority_min(struct linux_sched_get_priority_min_args
*args
)
1549 struct sched_get_priority_min_args bsd
;
1553 if (ldebug(sched_get_priority_min
))
1554 kprintf(ARGS(sched_get_priority_min
, "%d"), args
->policy
);
1557 switch (args
->policy
) {
1558 case LINUX_SCHED_OTHER
:
1559 bsd
.policy
= SCHED_OTHER
;
1561 case LINUX_SCHED_FIFO
:
1562 bsd
.policy
= SCHED_FIFO
;
1564 case LINUX_SCHED_RR
:
1565 bsd
.policy
= SCHED_RR
;
1570 bsd
.sysmsg_result
= 0;
1572 error
= sys_sched_get_priority_min(&bsd
);
1573 args
->sysmsg_result
= bsd
.sysmsg_result
;
1577 #define REBOOT_CAD_ON 0x89abcdef
1578 #define REBOOT_CAD_OFF 0
1579 #define REBOOT_HALT 0xcdef0123
1580 #define REBOOT_RESTART 0x01234567
1581 #define REBOOT_RESTART2 0xA1B2C3D4
1582 #define REBOOT_POWEROFF 0x4321FEDC
1583 #define REBOOT_MAGIC1 0xfee1dead
1584 #define REBOOT_MAGIC2 0x28121969
1585 #define REBOOT_MAGIC2A 0x05121996
1586 #define REBOOT_MAGIC2B 0x16041998
1592 sys_linux_reboot(struct linux_reboot_args
*args
)
1594 struct reboot_args bsd_args
;
1599 kprintf(ARGS(reboot
, "0x%x"), args
->cmd
);
1602 if ((args
->magic1
!= REBOOT_MAGIC1
) ||
1603 ((args
->magic2
!= REBOOT_MAGIC2
) &&
1604 (args
->magic2
!= REBOOT_MAGIC2A
) &&
1605 (args
->magic2
!= REBOOT_MAGIC2B
)))
1608 switch (args
->cmd
) {
1610 case REBOOT_CAD_OFF
:
1611 return (priv_check(curthread
, PRIV_REBOOT
));
1614 bsd_args
.opt
= RB_HALT
;
1616 case REBOOT_RESTART
:
1617 case REBOOT_RESTART2
:
1620 case REBOOT_POWEROFF
:
1621 bsd_args
.opt
= RB_POWEROFF
;
1628 bsd_args
.sysmsg_result
= 0;
1630 error
= sys_reboot(&bsd_args
);
1631 args
->sysmsg_result
= bsd_args
.sysmsg_result
;
1636 * The FreeBSD native getpid(2), getgid(2) and getuid(2) also modify
1637 * p->p_retval[1] when COMPAT_43 or COMPAT_SUNOS is defined. This
1638 * globbers registers that are assumed to be preserved. The following
1639 * lightweight syscalls fixes this. See also linux_getgid16() and
1640 * linux_getuid16() in linux_uid16.c.
1642 * linux_getpid() - MP SAFE
1643 * linux_getgid() - MP SAFE
1644 * linux_getuid() - MP SAFE
1651 sys_linux_getpid(struct linux_getpid_args
*args
)
1653 struct linux_emuldata
*em
;
1654 struct proc
*p
= curproc
;
1658 em
= emuldata_get(p
);
1659 if (em
== NULL
) /* this should never happen */
1660 args
->sysmsg_result
= p
->p_pid
;
1662 args
->sysmsg_result
= em
->s
->group_pid
;
1663 kprintf("curproc %s requested getpid, return pid = %d\n", curproc
->p_comm
, em
->s
->group_pid
);
1673 sys_linux_getppid(struct linux_getppid_args
*args
)
1675 struct linux_emuldata
*em
;
1676 struct proc
*parent
;
1681 em
= emuldata_get(curproc
);
1682 KKASSERT(em
!= NULL
);
1684 p
= pfind(em
->s
->group_pid
);
1685 /* We are not allowed to fail */
1690 if (parent
->p_sysent
== &elf_linux_sysvec
) {
1691 em
= emuldata_get(parent
);
1692 args
->sysmsg_result
= em
->s
->group_pid
;
1693 kprintf("(a) curproc %s requested getppid, return pid = %d\n", curproc
->p_comm
, em
->s
->group_pid
);
1695 args
->sysmsg_result
= parent
->p_pid
;
1696 kprintf("(b) curproc %s requested getppid, return pid = %d\n", curproc
->p_comm
, em
->s
->group_pid
);
1708 sys_linux_getgid(struct linux_getgid_args
*args
)
1710 struct thread
*td
= curthread
;
1712 args
->sysmsg_result
= td
->td_ucred
->cr_rgid
;
1720 sys_linux_getuid(struct linux_getuid_args
*args
)
1722 struct thread
*td
= curthread
;
1724 args
->sysmsg_result
= td
->td_ucred
->cr_ruid
;
1732 sys_linux_getsid(struct linux_getsid_args
*args
)
1734 struct getsid_args bsd
;
1737 bsd
.sysmsg_result
= 0;
1738 bsd
.pid
= args
->pid
;
1739 error
= sys_getsid(&bsd
);
1740 args
->sysmsg_result
= bsd
.sysmsg_result
;
1748 linux_nosys(struct nosys_args
*args
)
1755 sys_linux_mq_open(struct linux_mq_open_args
*args
)
1757 struct mq_open_args moa
;
1761 if (args
->oflag
& LINUX_O_RDONLY
)
1763 if (args
->oflag
& LINUX_O_WRONLY
)
1765 if (args
->oflag
& LINUX_O_RDWR
)
1768 if (args
->oflag
& LINUX_O_NONBLOCK
)
1769 oflag
|= O_NONBLOCK
;
1770 if (args
->oflag
& LINUX_O_CREAT
)
1772 if (args
->oflag
& LINUX_O_EXCL
)
1775 moa
.name
= args
->name
;
1777 moa
.mode
= args
->mode
;
1778 moa
.attr
= args
->attr
;
1780 error
= sys_mq_open(&moa
);
1786 sys_linux_mq_getsetattr(struct linux_mq_getsetattr_args
*args
)
1788 struct mq_getattr_args gaa
;
1789 struct mq_setattr_args saa
;
1792 gaa
.mqdes
= args
->mqd
;
1793 gaa
.mqstat
= args
->oattr
;
1795 saa
.mqdes
= args
->mqd
;
1796 saa
.mqstat
= args
->attr
;
1797 saa
.mqstat
= args
->oattr
;
1799 if (args
->attr
!= NULL
) {
1800 error
= sys_mq_setattr(&saa
);
1802 error
= sys_mq_getattr(&gaa
);
1809 * Get affinity of a process.
1812 sys_linux_sched_getaffinity(struct linux_sched_getaffinity_args
*args
)
1820 if (ldebug(sched_getaffinity
))
1821 kprintf(ARGS(sched_getaffinity
, "%d, %d, *"), args
->pid
,
1824 if (args
->len
< sizeof(cpumask_t
))
1827 if ((error
= priv_check(curthread
, PRIV_SCHED_CPUSET
)) != 0)
1830 /* Get the mplock to ensure that the proc is not running */
1832 if (args
->pid
== 0) {
1835 p
= pfind(args
->pid
);
1842 lp
= FIRST_LWP_IN_PROC(p
);
1844 * XXX: if lwp_cpumask is ever changed to support more than
1845 * 32 processors, this needs to be changed to a bcopy.
1847 mask
= lp
->lwp_cpumask
;
1848 if ((error
= copyout(&mask
, args
->user_mask_ptr
, sizeof(cpumask_t
))))
1854 args
->sysmsg_iresult
= sizeof(cpumask_t
);
1860 * Set affinity of a process.
1863 sys_linux_sched_setaffinity(struct linux_sched_setaffinity_args
*args
)
1866 if (ldebug(sched_setaffinity
))
1867 kprintf(ARGS(sched_setaffinity
, "%d, %d, *"), args
->pid
,
1871 * From Linux man page:
1872 * sched_setaffinity() sets the CPU affinity mask of the process
1873 * whose ID is pid to the value specified by mask. If pid is zero,
1874 * then the calling process is used. The argument cpusetsize is
1875 * the length (in bytes) of the data pointed to by mask. Normally
1876 * this argument would be specified as sizeof(cpu_set_t).
1878 * If the process specified by pid is not currently running on one
1879 * of the CPUs specified in mask, then that process is migrated to
1880 * one of the CPUs specified in mask.
1883 * About our implementation: I don't think that it is too important
1884 * to have a working implementation, but if it was ever needed,
1885 * the best approach would be to implement the whole mechanism
1886 * properly in kern_usched.
1887 * The idea has to be to change the affinity mask AND migrate the
1888 * lwp to one of the new valid CPUs for the lwp, in case the current
1889 * CPU isn't anymore in the affinity mask passed in.
1890 * For now, we'll just signal success even if we didn't do anything.
1896 sys_linux_gettid(struct linux_gettid_args
*args
)
1898 args
->sysmsg_iresult
= curproc
->p_pid
;
1903 sys_linux_getcpu(struct linux_getcpu_args
*args
)
1905 struct globaldata
*gd
;
1910 error
= copyout(&gd
->gd_cpuid
, args
->pcpu
, sizeof(gd
->gd_cpuid
));
1914 * XXX: this should be the NUMA node, but since we don't implement it,
1915 * just return 0 for it.
1917 error
= copyout(&node
, args
->pnode
, sizeof(node
));