xref: /freebsd/sys/amd64/linux32/linux32_machdep.c (revision 0c785f06020f3b02e34c97eb27fecd3af8eb2a7b)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2004 Tim J. Robbins
5  * Copyright (c) 2002 Doug Rabson
6  * Copyright (c) 2000 Marcel Moolenaar
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer
14  *    in this position and unchanged.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/param.h>
34 #include <sys/fcntl.h>
35 #include <sys/imgact.h>
36 #include <sys/limits.h>
37 #include <sys/lock.h>
38 #include <sys/malloc.h>
39 #include <sys/mutex.h>
40 #include <sys/priv.h>
41 #include <sys/proc.h>
42 #include <sys/reg.h>
43 #include <sys/syscallsubr.h>
44 
45 #include <machine/frame.h>
46 #include <machine/md_var.h>
47 #include <machine/pcb.h>
48 #include <machine/psl.h>
49 #include <machine/segments.h>
50 #include <machine/specialreg.h>
51 #include <x86/ifunc.h>
52 
53 #include <vm/pmap.h>
54 #include <vm/vm.h>
55 #include <vm/vm_map.h>
56 
57 #include <security/audit/audit.h>
58 
59 #include <compat/freebsd32/freebsd32_util.h>
60 #include <amd64/linux32/linux.h>
61 #include <amd64/linux32/linux32_proto.h>
62 #include <compat/linux/linux_emul.h>
63 #include <compat/linux/linux_fork.h>
64 #include <compat/linux/linux_ipc.h>
65 #include <compat/linux/linux_misc.h>
66 #include <compat/linux/linux_mmap.h>
67 #include <compat/linux/linux_signal.h>
68 #include <compat/linux/linux_util.h>
69 
70 static void	bsd_to_linux_rusage(struct rusage *ru, struct l_rusage *lru);
71 
72 struct l_old_select_argv {
73 	l_int		nfds;
74 	l_uintptr_t	readfds;
75 	l_uintptr_t	writefds;
76 	l_uintptr_t	exceptfds;
77 	l_uintptr_t	timeout;
78 } __packed;
79 
80 static void
81 bsd_to_linux_rusage(struct rusage *ru, struct l_rusage *lru)
82 {
83 
84 	lru->ru_utime.tv_sec = ru->ru_utime.tv_sec;
85 	lru->ru_utime.tv_usec = ru->ru_utime.tv_usec;
86 	lru->ru_stime.tv_sec = ru->ru_stime.tv_sec;
87 	lru->ru_stime.tv_usec = ru->ru_stime.tv_usec;
88 	lru->ru_maxrss = ru->ru_maxrss;
89 	lru->ru_ixrss = ru->ru_ixrss;
90 	lru->ru_idrss = ru->ru_idrss;
91 	lru->ru_isrss = ru->ru_isrss;
92 	lru->ru_minflt = ru->ru_minflt;
93 	lru->ru_majflt = ru->ru_majflt;
94 	lru->ru_nswap = ru->ru_nswap;
95 	lru->ru_inblock = ru->ru_inblock;
96 	lru->ru_oublock = ru->ru_oublock;
97 	lru->ru_msgsnd = ru->ru_msgsnd;
98 	lru->ru_msgrcv = ru->ru_msgrcv;
99 	lru->ru_nsignals = ru->ru_nsignals;
100 	lru->ru_nvcsw = ru->ru_nvcsw;
101 	lru->ru_nivcsw = ru->ru_nivcsw;
102 }
103 
104 int
105 linux_copyout_rusage(struct rusage *ru, void *uaddr)
106 {
107 	struct l_rusage lru;
108 
109 	bsd_to_linux_rusage(ru, &lru);
110 
111 	return (copyout(&lru, uaddr, sizeof(struct l_rusage)));
112 }
113 
114 CTASSERT(sizeof(struct l_iovec32) == 8);
115 
116 int
117 linux32_copyinuio(struct l_iovec32 *iovp, l_ulong iovcnt, struct uio **uiop)
118 {
119 	struct l_iovec32 iov32;
120 	struct iovec *iov;
121 	struct uio *uio;
122 	uint32_t iovlen;
123 	int error, i;
124 
125 	*uiop = NULL;
126 	if (iovcnt > UIO_MAXIOV)
127 		return (EINVAL);
128 	iovlen = iovcnt * sizeof(struct iovec);
129 	uio = malloc(iovlen + sizeof(*uio), M_IOV, M_WAITOK);
130 	iov = (struct iovec *)(uio + 1);
131 	for (i = 0; i < iovcnt; i++) {
132 		error = copyin(&iovp[i], &iov32, sizeof(struct l_iovec32));
133 		if (error) {
134 			free(uio, M_IOV);
135 			return (error);
136 		}
137 		iov[i].iov_base = PTRIN(iov32.iov_base);
138 		iov[i].iov_len = iov32.iov_len;
139 	}
140 	uio->uio_iov = iov;
141 	uio->uio_iovcnt = iovcnt;
142 	uio->uio_segflg = UIO_USERSPACE;
143 	uio->uio_offset = -1;
144 	uio->uio_resid = 0;
145 	for (i = 0; i < iovcnt; i++) {
146 		if (iov->iov_len > INT_MAX - uio->uio_resid) {
147 			free(uio, M_IOV);
148 			return (EINVAL);
149 		}
150 		uio->uio_resid += iov->iov_len;
151 		iov++;
152 	}
153 	*uiop = uio;
154 	return (0);
155 }
156 
157 int
158 linux32_copyiniov(struct l_iovec32 *iovp32, l_ulong iovcnt, struct iovec **iovp,
159     int error)
160 {
161 	struct l_iovec32 iov32;
162 	struct iovec *iov;
163 	uint32_t iovlen;
164 	int i;
165 
166 	*iovp = NULL;
167 	if (iovcnt > UIO_MAXIOV)
168 		return (error);
169 	iovlen = iovcnt * sizeof(struct iovec);
170 	iov = malloc(iovlen, M_IOV, M_WAITOK);
171 	for (i = 0; i < iovcnt; i++) {
172 		error = copyin(&iovp32[i], &iov32, sizeof(struct l_iovec32));
173 		if (error) {
174 			free(iov, M_IOV);
175 			return (error);
176 		}
177 		iov[i].iov_base = PTRIN(iov32.iov_base);
178 		iov[i].iov_len = iov32.iov_len;
179 	}
180 	*iovp = iov;
181 	return(0);
182 
183 }
184 
185 int
186 linux_readv(struct thread *td, struct linux_readv_args *uap)
187 {
188 	struct uio *auio;
189 	int error;
190 
191 	error = linux32_copyinuio(uap->iovp, uap->iovcnt, &auio);
192 	if (error)
193 		return (error);
194 	error = kern_readv(td, uap->fd, auio);
195 	free(auio, M_IOV);
196 	return (error);
197 }
198 
199 int
200 linux_writev(struct thread *td, struct linux_writev_args *uap)
201 {
202 	struct uio *auio;
203 	int error;
204 
205 	error = linux32_copyinuio(uap->iovp, uap->iovcnt, &auio);
206 	if (error)
207 		return (error);
208 	error = kern_writev(td, uap->fd, auio);
209 	free(auio, M_IOV);
210 	return (error);
211 }
212 
213 struct l_ipc_kludge {
214 	l_uintptr_t msgp;
215 	l_long msgtyp;
216 } __packed;
217 
218 int
219 linux_ipc(struct thread *td, struct linux_ipc_args *args)
220 {
221 
222 	switch (args->what & 0xFFFF) {
223 	case LINUX_SEMOP: {
224 
225 		return (kern_semop(td, args->arg1, PTRIN(args->ptr),
226 		    args->arg2, NULL));
227 	}
228 	case LINUX_SEMGET: {
229 		struct linux_semget_args a;
230 
231 		a.key = args->arg1;
232 		a.nsems = args->arg2;
233 		a.semflg = args->arg3;
234 		return (linux_semget(td, &a));
235 	}
236 	case LINUX_SEMCTL: {
237 		struct linux_semctl_args a;
238 		int error;
239 
240 		a.semid = args->arg1;
241 		a.semnum = args->arg2;
242 		a.cmd = args->arg3;
243 		error = copyin(PTRIN(args->ptr), &a.arg, sizeof(a.arg));
244 		if (error)
245 			return (error);
246 		return (linux_semctl(td, &a));
247 	}
248 	case LINUX_SEMTIMEDOP: {
249 		struct linux_semtimedop_args a;
250 
251 		a.semid = args->arg1;
252 		a.tsops = PTRIN(args->ptr);
253 		a.nsops = args->arg2;
254 		a.timeout = PTRIN(args->arg5);
255 		return (linux_semtimedop(td, &a));
256 	}
257 	case LINUX_MSGSND: {
258 		struct linux_msgsnd_args a;
259 
260 		a.msqid = args->arg1;
261 		a.msgp = PTRIN(args->ptr);
262 		a.msgsz = args->arg2;
263 		a.msgflg = args->arg3;
264 		return (linux_msgsnd(td, &a));
265 	}
266 	case LINUX_MSGRCV: {
267 		struct linux_msgrcv_args a;
268 
269 		a.msqid = args->arg1;
270 		a.msgsz = args->arg2;
271 		a.msgflg = args->arg3;
272 		if ((args->what >> 16) == 0) {
273 			struct l_ipc_kludge tmp;
274 			int error;
275 
276 			if (args->ptr == 0)
277 				return (EINVAL);
278 			error = copyin(PTRIN(args->ptr), &tmp, sizeof(tmp));
279 			if (error)
280 				return (error);
281 			a.msgp = PTRIN(tmp.msgp);
282 			a.msgtyp = tmp.msgtyp;
283 		} else {
284 			a.msgp = PTRIN(args->ptr);
285 			a.msgtyp = args->arg5;
286 		}
287 		return (linux_msgrcv(td, &a));
288 	}
289 	case LINUX_MSGGET: {
290 		struct linux_msgget_args a;
291 
292 		a.key = args->arg1;
293 		a.msgflg = args->arg2;
294 		return (linux_msgget(td, &a));
295 	}
296 	case LINUX_MSGCTL: {
297 		struct linux_msgctl_args a;
298 
299 		a.msqid = args->arg1;
300 		a.cmd = args->arg2;
301 		a.buf = PTRIN(args->ptr);
302 		return (linux_msgctl(td, &a));
303 	}
304 	case LINUX_SHMAT: {
305 		struct linux_shmat_args a;
306 		l_uintptr_t addr;
307 		int error;
308 
309 		a.shmid = args->arg1;
310 		a.shmaddr = PTRIN(args->ptr);
311 		a.shmflg = args->arg2;
312 		error = linux_shmat(td, &a);
313 		if (error != 0)
314 			return (error);
315 		addr = td->td_retval[0];
316 		error = copyout(&addr, PTRIN(args->arg3), sizeof(addr));
317 		td->td_retval[0] = 0;
318 		return (error);
319 	}
320 	case LINUX_SHMDT: {
321 		struct linux_shmdt_args a;
322 
323 		a.shmaddr = PTRIN(args->ptr);
324 		return (linux_shmdt(td, &a));
325 	}
326 	case LINUX_SHMGET: {
327 		struct linux_shmget_args a;
328 
329 		a.key = args->arg1;
330 		a.size = args->arg2;
331 		a.shmflg = args->arg3;
332 		return (linux_shmget(td, &a));
333 	}
334 	case LINUX_SHMCTL: {
335 		struct linux_shmctl_args a;
336 
337 		a.shmid = args->arg1;
338 		a.cmd = args->arg2;
339 		a.buf = PTRIN(args->ptr);
340 		return (linux_shmctl(td, &a));
341 	}
342 	default:
343 		break;
344 	}
345 
346 	return (EINVAL);
347 }
348 
349 int
350 linux_old_select(struct thread *td, struct linux_old_select_args *args)
351 {
352 	struct l_old_select_argv linux_args;
353 	struct linux_select_args newsel;
354 	int error;
355 
356 	error = copyin(args->ptr, &linux_args, sizeof(linux_args));
357 	if (error)
358 		return (error);
359 
360 	newsel.nfds = linux_args.nfds;
361 	newsel.readfds = PTRIN(linux_args.readfds);
362 	newsel.writefds = PTRIN(linux_args.writefds);
363 	newsel.exceptfds = PTRIN(linux_args.exceptfds);
364 	newsel.timeout = PTRIN(linux_args.timeout);
365 	return (linux_select(td, &newsel));
366 }
367 
368 int
369 linux_set_cloned_tls(struct thread *td, void *desc)
370 {
371 	struct l_user_desc info;
372 	struct pcb *pcb;
373 	int error;
374 
375 	error = copyin(desc, &info, sizeof(struct l_user_desc));
376 	if (error) {
377 		linux_msg(td, "set_cloned_tls copyin info failed!");
378 	} else {
379 		/* We might copy out the entry_number as GUGS32_SEL. */
380 		info.entry_number = GUGS32_SEL;
381 		error = copyout(&info, desc, sizeof(struct l_user_desc));
382 		if (error)
383 			linux_msg(td, "set_cloned_tls copyout info failed!");
384 
385 		pcb = td->td_pcb;
386 		update_pcb_bases(pcb);
387 		pcb->pcb_gsbase = (register_t)info.base_addr;
388 		td->td_frame->tf_gs = GSEL(GUGS32_SEL, SEL_UPL);
389 	}
390 
391 	return (error);
392 }
393 
394 int
395 linux_set_upcall(struct thread *td, register_t stack)
396 {
397 
398 	if (stack)
399 		td->td_frame->tf_rsp = stack;
400 
401 	/*
402 	 * The newly created Linux thread returns
403 	 * to the user space by the same path that a parent do.
404 	 */
405 	td->td_frame->tf_rax = 0;
406 	return (0);
407 }
408 
409 int
410 linux_mmap2(struct thread *td, struct linux_mmap2_args *args)
411 {
412 
413 	return (linux_mmap_common(td, PTROUT(args->addr), args->len, args->prot,
414 		args->flags, args->fd, (uint64_t)(uint32_t)args->pgoff *
415 		PAGE_SIZE));
416 }
417 
418 int
419 linux_mmap(struct thread *td, struct linux_mmap_args *args)
420 {
421 	int error;
422 	struct l_mmap_argv linux_args;
423 
424 	error = copyin(args->ptr, &linux_args, sizeof(linux_args));
425 	if (error)
426 		return (error);
427 
428 	return (linux_mmap_common(td, linux_args.addr, linux_args.len,
429 	    linux_args.prot, linux_args.flags, linux_args.fd,
430 	    (uint32_t)linux_args.pgoff));
431 }
432 
433 int
434 linux_mprotect(struct thread *td, struct linux_mprotect_args *uap)
435 {
436 
437 	return (linux_mprotect_common(td, PTROUT(uap->addr), uap->len, uap->prot));
438 }
439 
440 int
441 linux_madvise(struct thread *td, struct linux_madvise_args *uap)
442 {
443 
444 	return (linux_madvise_common(td, PTROUT(uap->addr), uap->len, uap->behav));
445 }
446 
447 int
448 linux_iopl(struct thread *td, struct linux_iopl_args *args)
449 {
450 	int error;
451 
452 	if (args->level < 0 || args->level > 3)
453 		return (EINVAL);
454 	if ((error = priv_check(td, PRIV_IO)) != 0)
455 		return (error);
456 	if ((error = securelevel_gt(td->td_ucred, 0)) != 0)
457 		return (error);
458 	td->td_frame->tf_rflags = (td->td_frame->tf_rflags & ~PSL_IOPL) |
459 	    (args->level * (PSL_IOPL / 3));
460 
461 	return (0);
462 }
463 
464 int
465 linux_sigaction(struct thread *td, struct linux_sigaction_args *args)
466 {
467 	l_osigaction_t osa;
468 	l_sigaction_t act, oact;
469 	int error;
470 
471 	if (args->nsa != NULL) {
472 		error = copyin(args->nsa, &osa, sizeof(l_osigaction_t));
473 		if (error)
474 			return (error);
475 		act.lsa_handler = osa.lsa_handler;
476 		act.lsa_flags = osa.lsa_flags;
477 		act.lsa_restorer = osa.lsa_restorer;
478 		LINUX_SIGEMPTYSET(act.lsa_mask);
479 		act.lsa_mask.__mask = osa.lsa_mask;
480 	}
481 
482 	error = linux_do_sigaction(td, args->sig, args->nsa ? &act : NULL,
483 	    args->osa ? &oact : NULL);
484 
485 	if (args->osa != NULL && !error) {
486 		osa.lsa_handler = oact.lsa_handler;
487 		osa.lsa_flags = oact.lsa_flags;
488 		osa.lsa_restorer = oact.lsa_restorer;
489 		osa.lsa_mask = oact.lsa_mask.__mask;
490 		error = copyout(&osa, args->osa, sizeof(l_osigaction_t));
491 	}
492 
493 	return (error);
494 }
495 
496 /*
497  * Linux has two extra args, restart and oldmask.  We don't use these,
498  * but it seems that "restart" is actually a context pointer that
499  * enables the signal to happen with a different register set.
500  */
501 int
502 linux_sigsuspend(struct thread *td, struct linux_sigsuspend_args *args)
503 {
504 	sigset_t sigmask;
505 	l_sigset_t mask;
506 
507 	LINUX_SIGEMPTYSET(mask);
508 	mask.__mask = args->mask;
509 	linux_to_bsd_sigset(&mask, &sigmask);
510 	return (kern_sigsuspend(td, sigmask));
511 }
512 
513 int
514 linux_pause(struct thread *td, struct linux_pause_args *args)
515 {
516 	struct proc *p = td->td_proc;
517 	sigset_t sigmask;
518 
519 	PROC_LOCK(p);
520 	sigmask = td->td_sigmask;
521 	PROC_UNLOCK(p);
522 	return (kern_sigsuspend(td, sigmask));
523 }
524 
525 int
526 linux_gettimeofday(struct thread *td, struct linux_gettimeofday_args *uap)
527 {
528 	struct timeval atv;
529 	l_timeval atv32;
530 	struct timezone rtz;
531 	int error = 0;
532 
533 	if (uap->tp) {
534 		microtime(&atv);
535 		atv32.tv_sec = atv.tv_sec;
536 		atv32.tv_usec = atv.tv_usec;
537 		error = copyout(&atv32, uap->tp, sizeof(atv32));
538 	}
539 	if (error == 0 && uap->tzp != NULL) {
540 		rtz.tz_minuteswest = 0;
541 		rtz.tz_dsttime = 0;
542 		error = copyout(&rtz, uap->tzp, sizeof(rtz));
543 	}
544 	return (error);
545 }
546 
547 int
548 linux_settimeofday(struct thread *td, struct linux_settimeofday_args *uap)
549 {
550 	l_timeval atv32;
551 	struct timeval atv, *tvp;
552 	struct timezone atz, *tzp;
553 	int error;
554 
555 	if (uap->tp) {
556 		error = copyin(uap->tp, &atv32, sizeof(atv32));
557 		if (error)
558 			return (error);
559 		atv.tv_sec = atv32.tv_sec;
560 		atv.tv_usec = atv32.tv_usec;
561 		tvp = &atv;
562 	} else
563 		tvp = NULL;
564 	if (uap->tzp) {
565 		error = copyin(uap->tzp, &atz, sizeof(atz));
566 		if (error)
567 			return (error);
568 		tzp = &atz;
569 	} else
570 		tzp = NULL;
571 	return (kern_settimeofday(td, tvp, tzp));
572 }
573 
574 int
575 linux_getrusage(struct thread *td, struct linux_getrusage_args *uap)
576 {
577 	struct rusage s;
578 	int error;
579 
580 	error = kern_getrusage(td, uap->who, &s);
581 	if (error != 0)
582 		return (error);
583 	if (uap->rusage != NULL)
584 		error = linux_copyout_rusage(&s, uap->rusage);
585 	return (error);
586 }
587 
588 int
589 linux_set_thread_area(struct thread *td,
590     struct linux_set_thread_area_args *args)
591 {
592 	struct l_user_desc info;
593 	struct pcb *pcb;
594 	int error;
595 
596 	error = copyin(args->desc, &info, sizeof(struct l_user_desc));
597 	if (error)
598 		return (error);
599 
600 	/*
601 	 * Semantics of Linux version: every thread in the system has array
602 	 * of three TLS descriptors. 1st is GLIBC TLS, 2nd is WINE, 3rd unknown.
603 	 * This syscall loads one of the selected TLS descriptors with a value
604 	 * and also loads GDT descriptors 6, 7 and 8 with the content of
605 	 * the per-thread descriptors.
606 	 *
607 	 * Semantics of FreeBSD version: I think we can ignore that Linux has
608 	 * three per-thread descriptors and use just the first one.
609 	 * The tls_array[] is used only in [gs]et_thread_area() syscalls and
610 	 * for loading the GDT descriptors. We use just one GDT descriptor
611 	 * for TLS, so we will load just one.
612 	 *
613 	 * XXX: This doesn't work when a user space process tries to use more
614 	 * than one TLS segment. Comment in the Linux source says wine might
615 	 * do this.
616 	 */
617 
618 	/*
619 	 * GLIBC reads current %gs and call set_thread_area() with it.
620 	 * We should let GUDATA_SEL and GUGS32_SEL proceed as well because
621 	 * we use these segments.
622 	 */
623 	switch (info.entry_number) {
624 	case GUGS32_SEL:
625 	case GUDATA_SEL:
626 	case 6:
627 	case -1:
628 		info.entry_number = GUGS32_SEL;
629 		break;
630 	default:
631 		return (EINVAL);
632 	}
633 
634 	/*
635 	 * We have to copy out the GDT entry we use.
636 	 *
637 	 * XXX: What if a user space program does not check the return value
638 	 * and tries to use 6, 7 or 8?
639 	 */
640 	error = copyout(&info, args->desc, sizeof(struct l_user_desc));
641 	if (error)
642 		return (error);
643 
644 	pcb = td->td_pcb;
645 	update_pcb_bases(pcb);
646 	pcb->pcb_gsbase = (register_t)info.base_addr;
647 	update_gdt_gsbase(td, info.base_addr);
648 
649 	return (0);
650 }
651 
652 void
653 bsd_to_linux_regset32(const struct reg32 *b_reg,
654     struct linux_pt_regset32 *l_regset)
655 {
656 
657 	l_regset->ebx = b_reg->r_ebx;
658 	l_regset->ecx = b_reg->r_ecx;
659 	l_regset->edx = b_reg->r_edx;
660 	l_regset->esi = b_reg->r_esi;
661 	l_regset->edi = b_reg->r_edi;
662 	l_regset->ebp = b_reg->r_ebp;
663 	l_regset->eax = b_reg->r_eax;
664 	l_regset->ds = b_reg->r_ds;
665 	l_regset->es = b_reg->r_es;
666 	l_regset->fs = b_reg->r_fs;
667 	l_regset->gs = b_reg->r_gs;
668 	l_regset->orig_eax = b_reg->r_eax;
669 	l_regset->eip = b_reg->r_eip;
670 	l_regset->cs = b_reg->r_cs;
671 	l_regset->eflags = b_reg->r_eflags;
672 	l_regset->esp = b_reg->r_esp;
673 	l_regset->ss = b_reg->r_ss;
674 }
675 
676 int futex_xchgl_nosmap(int oparg, uint32_t *uaddr, int *oldval);
677 int futex_xchgl_smap(int oparg, uint32_t *uaddr, int *oldval);
678 DEFINE_IFUNC(, int, futex_xchgl, (int, uint32_t *, int *))
679 {
680 
681 	return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ?
682 	    futex_xchgl_smap : futex_xchgl_nosmap);
683 }
684 
685 int futex_addl_nosmap(int oparg, uint32_t *uaddr, int *oldval);
686 int futex_addl_smap(int oparg, uint32_t *uaddr, int *oldval);
687 DEFINE_IFUNC(, int, futex_addl, (int, uint32_t *, int *))
688 {
689 
690 	return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ?
691 	    futex_addl_smap : futex_addl_nosmap);
692 }
693 
694 int futex_orl_nosmap(int oparg, uint32_t *uaddr, int *oldval);
695 int futex_orl_smap(int oparg, uint32_t *uaddr, int *oldval);
696 DEFINE_IFUNC(, int, futex_orl, (int, uint32_t *, int *))
697 {
698 
699 	return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ?
700 	    futex_orl_smap : futex_orl_nosmap);
701 }
702 
703 int futex_andl_nosmap(int oparg, uint32_t *uaddr, int *oldval);
704 int futex_andl_smap(int oparg, uint32_t *uaddr, int *oldval);
705 DEFINE_IFUNC(, int, futex_andl, (int, uint32_t *, int *))
706 {
707 
708 	return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ?
709 	    futex_andl_smap : futex_andl_nosmap);
710 }
711 
712 int futex_xorl_nosmap(int oparg, uint32_t *uaddr, int *oldval);
713 int futex_xorl_smap(int oparg, uint32_t *uaddr, int *oldval);
714 DEFINE_IFUNC(, int, futex_xorl, (int, uint32_t *, int *))
715 {
716 
717 	return ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0 ?
718 	    futex_xorl_smap : futex_xorl_nosmap);
719 }
720 
721 int
722 linux_ptrace_peekuser(struct thread *td, pid_t pid, void *addr, void *data)
723 {
724 
725 	LINUX_RATELIMIT_MSG_OPT1("PTRACE_PEEKUSER offset %ld not implemented; "
726 	    "returning EINVAL", (uintptr_t)addr);
727 	return (EINVAL);
728 }
729 
730 int
731 linux_ptrace_pokeuser(struct thread *td, pid_t pid, void *addr, void *data)
732 {
733 
734 	LINUX_RATELIMIT_MSG_OPT1("PTRACE_POKEUSER offset %ld "
735 	    "not implemented; returning EINVAL", (uintptr_t)addr);
736 	return (EINVAL);
737 }
738