xref: /freebsd/sys/amd64/ia32/ia32_misc.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
12c66cccaSKonstantin Belousov /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3c49761ddSPedro F. Giffuni  *
42c66cccaSKonstantin Belousov  * Copyright (c) 2009 Konstantin Belousov
52c66cccaSKonstantin Belousov  * All rights reserved.
62c66cccaSKonstantin Belousov  *
72c66cccaSKonstantin Belousov  * Redistribution and use in source and binary forms, with or without
82c66cccaSKonstantin Belousov  * modification, are permitted provided that the following conditions
92c66cccaSKonstantin Belousov  * are met:
102c66cccaSKonstantin Belousov  * 1. Redistributions of source code must retain the above copyright
112c66cccaSKonstantin Belousov  *    notice, this list of conditions and the following disclaimer.
122c66cccaSKonstantin Belousov  * 2. Redistributions in binary form must reproduce the above copyright
132c66cccaSKonstantin Belousov  *    notice, this list of conditions and the following disclaimer in the
142c66cccaSKonstantin Belousov  *    documentation and/or other materials provided with the distribution.
152c66cccaSKonstantin Belousov  *
162c66cccaSKonstantin Belousov  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
172c66cccaSKonstantin Belousov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
182c66cccaSKonstantin Belousov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
192c66cccaSKonstantin Belousov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
202c66cccaSKonstantin Belousov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
212c66cccaSKonstantin Belousov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
222c66cccaSKonstantin Belousov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
232c66cccaSKonstantin Belousov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
242c66cccaSKonstantin Belousov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
252c66cccaSKonstantin Belousov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
262c66cccaSKonstantin Belousov  * SUCH DAMAGE.
272c66cccaSKonstantin Belousov  */
282c66cccaSKonstantin Belousov 
292c66cccaSKonstantin Belousov #include <sys/param.h>
302c66cccaSKonstantin Belousov #include <sys/mount.h>
312c66cccaSKonstantin Belousov #include <sys/proc.h>
322c66cccaSKonstantin Belousov #include <sys/socket.h>
332c66cccaSKonstantin Belousov #include <sys/sysent.h>
342c66cccaSKonstantin Belousov #include <sys/sysproto.h>
352c66cccaSKonstantin Belousov #include <sys/systm.h>
362c66cccaSKonstantin Belousov #include <sys/uio.h>
372c66cccaSKonstantin Belousov 
382c66cccaSKonstantin Belousov #include <machine/cpu.h>
392c66cccaSKonstantin Belousov #include <machine/sysarch.h>
402c66cccaSKonstantin Belousov 
412c66cccaSKonstantin Belousov #include <compat/freebsd32/freebsd32_util.h>
422c66cccaSKonstantin Belousov #include <compat/freebsd32/freebsd32.h>
432c66cccaSKonstantin Belousov #include <compat/freebsd32/freebsd32_proto.h>
442c66cccaSKonstantin Belousov 
452c66cccaSKonstantin Belousov int
freebsd32_sysarch(struct thread * td,struct freebsd32_sysarch_args * uap)462c66cccaSKonstantin Belousov freebsd32_sysarch(struct thread *td, struct freebsd32_sysarch_args *uap)
472c66cccaSKonstantin Belousov {
482c66cccaSKonstantin Belousov 	struct sysarch_args uap1;
492c66cccaSKonstantin Belousov 	struct i386_ldt_args uapl;
502c66cccaSKonstantin Belousov 	struct i386_ldt_args32 uapl32;
512c66cccaSKonstantin Belousov 	int error;
522c66cccaSKonstantin Belousov 
532c66cccaSKonstantin Belousov 	if (uap->op == I386_SET_LDT || uap->op == I386_GET_LDT) {
542c66cccaSKonstantin Belousov 		if ((error = copyin(uap->parms, &uapl32, sizeof(uapl32))) != 0)
552c66cccaSKonstantin Belousov 			return (error);
562c66cccaSKonstantin Belousov 		uap1.op = uap->op;
572c66cccaSKonstantin Belousov 		uap1.parms = (char *)&uapl;
582c66cccaSKonstantin Belousov 		uapl.start = uapl32.start;
592c66cccaSKonstantin Belousov 		uapl.descs = (struct user_segment_descriptor *)(uintptr_t)
602c66cccaSKonstantin Belousov 		    uapl32.descs;
612c66cccaSKonstantin Belousov 		uapl.num = uapl32.num;
622c66cccaSKonstantin Belousov 		return (sysarch_ldt(td, &uap1, UIO_SYSSPACE));
632c66cccaSKonstantin Belousov 	} else {
642c66cccaSKonstantin Belousov 		uap1.op = uap->op;
652c66cccaSKonstantin Belousov 		uap1.parms = uap->parms;
662c66cccaSKonstantin Belousov 		return (sysarch(td, &uap1));
672c66cccaSKonstantin Belousov 	}
682c66cccaSKonstantin Belousov }
69