1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2018 Turing Robotic Industries Inc. 5 * Copyright (c) 2000 Marcel Moolenaar 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 31 #include <sys/cdefs.h> 32 __FBSDID("$FreeBSD$"); 33 34 #include <sys/param.h> 35 #include <sys/fcntl.h> 36 #include <sys/imgact.h> 37 #include <sys/ktr.h> 38 #include <sys/proc.h> 39 #include <sys/sdt.h> 40 41 #include <arm64/linux/linux.h> 42 #include <arm64/linux/linux_proto.h> 43 #include <compat/linux/linux_dtrace.h> 44 #include <compat/linux/linux_emul.h> 45 #include <compat/linux/linux_misc.h> 46 #include <compat/linux/linux_mmap.h> 47 #include <compat/linux/linux_util.h> 48 49 /* DTrace init */ 50 LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE); 51 52 /* DTrace probes */ 53 LIN_SDT_PROBE_DEFINE0(machdep, linux_set_upcall_kse, todo); 54 LIN_SDT_PROBE_DEFINE0(machdep, linux_mmap2, todo); 55 LIN_SDT_PROBE_DEFINE0(machdep, linux_rt_sigsuspend, todo); 56 LIN_SDT_PROBE_DEFINE0(machdep, linux_sigaltstack, todo); 57 LIN_SDT_PROBE_DEFINE0(machdep, linux_set_cloned_tls, todo); 58 59 /* 60 * LINUXTODO: deduplicate; linux_execve is common across archs, except that on 61 * amd64 compat linuxulator it calls freebsd32_exec_copyin_args. 62 */ 63 int 64 linux_execve(struct thread *td, struct linux_execve_args *uap) 65 { 66 struct image_args eargs; 67 char *path; 68 int error; 69 70 LCONVPATHEXIST(td, uap->path, &path); 71 72 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp, 73 uap->envp); 74 free(path, M_TEMP); 75 if (error == 0) 76 error = linux_common_execve(td, &eargs); 77 return (error); 78 } 79 80 /* LINUXTODO: implement (or deduplicate) arm64 linux_set_upcall_kse */ 81 int 82 linux_set_upcall_kse(struct thread *td, register_t stack) 83 { 84 85 LIN_SDT_PROBE0(machdep, linux_set_upcall_kse, todo); 86 return (EDOOFUS); 87 } 88 89 /* LINUXTODO: deduplicate arm64 linux_mmap2 */ 90 int 91 linux_mmap2(struct thread *td, struct linux_mmap2_args *uap) 92 { 93 94 LIN_SDT_PROBE0(machdep, linux_mmap2, todo); 95 return (linux_mmap_common(td, PTROUT(uap->addr), uap->len, uap->prot, 96 uap->flags, uap->fd, uap->pgoff)); 97 } 98 99 int 100 linux_mprotect(struct thread *td, struct linux_mprotect_args *uap) 101 { 102 103 return (linux_mprotect_common(td, PTROUT(uap->addr), uap->len, 104 uap->prot)); 105 } 106 107 /* LINUXTODO: implement arm64 linux_rt_sigsuspend */ 108 int 109 linux_rt_sigsuspend(struct thread *td, struct linux_rt_sigsuspend_args *uap) 110 { 111 112 LIN_SDT_PROBE0(machdep, linux_rt_sigsuspend, todo); 113 return (EDOOFUS); 114 } 115 116 /* LINUXTODO: implement arm64 linux_sigaltstack */ 117 int 118 linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap) 119 { 120 121 LIN_SDT_PROBE0(machdep, linux_sigaltstack, todo); 122 return (EDOOFUS); 123 } 124 125 /* LINUXTODO: implement arm64 linux_set_cloned_tls */ 126 int 127 linux_set_cloned_tls(struct thread *td, void *desc) 128 { 129 130 LIN_SDT_PROBE0(machdep, linux_set_cloned_tls, todo); 131 return (EDOOFUS); 132 } 133