aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorDmitry Chagin <dchagin@FreeBSD.org>2022-05-23 10:18:41 +0000
committerDmitry Chagin <dchagin@FreeBSD.org>2022-05-23 10:18:41 +0000
commit26700ac0c4d0466c00f944bde9613d18625d1f91 (patch)
treeb5866d4b0037ddf4da94d9a50be8903198901001 /sys
parente0aef0d62d2b14e754f25ef4f3582ae5faf8579c (diff)
downloadsrc-26700ac0c4d0466c00f944bde9613d18625d1f91.tar.gz
src-26700ac0c4d0466c00f944bde9613d18625d1f91.zip
linux(4): Deduplicate execve
As linux_execve is common across archs, except amd64 32-bit Linuxulator, move it under compat/linux. Noted by: andrew@ MFC after: 2 weeks
Diffstat (limited to 'sys')
-rw-r--r--sys/amd64/linux/linux_machdep.c27
-rw-r--r--sys/arm64/linux/linux_machdep.c30
-rw-r--r--sys/compat/linux/linux_misc.c28
-rw-r--r--sys/i386/linux/linux_machdep.c25
4 files changed, 28 insertions, 82 deletions
diff --git a/sys/amd64/linux/linux_machdep.c b/sys/amd64/linux/linux_machdep.c
index 18be62dab9ae..1c042424f3ea 100644
--- a/sys/amd64/linux/linux_machdep.c
+++ b/sys/amd64/linux/linux_machdep.c
@@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$");
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/filedesc.h>
-#include <sys/imgact.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/limits.h>
@@ -83,8 +82,6 @@ __FBSDID("$FreeBSD$");
#include <x86/reg.h>
#include <x86/sysarch.h>
-#include <security/audit/audit.h>
-
#include <amd64/linux/linux.h>
#include <amd64/linux/linux_proto.h>
#include <compat/linux/linux_emul.h>
@@ -99,30 +96,6 @@ __FBSDID("$FreeBSD$");
#define LINUX_ARCH_AMD64 0xc000003e
int
-linux_execve(struct thread *td, struct linux_execve_args *args)
-{
- struct image_args eargs;
- char *path;
- int error;
-
- LINUX_CTR(execve);
-
- if (!LUSECONVPATH(td)) {
- error = exec_copyin_args(&eargs, args->path, UIO_USERSPACE,
- args->argp, args->envp);
- } else {
- LCONVPATHEXIST(args->path, &path);
- error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, args->argp,
- args->envp);
- LFREEPATH(path);
- }
- if (error == 0)
- error = linux_common_execve(td, &eargs);
- AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
- return (error);
-}
-
-int
linux_set_upcall(struct thread *td, register_t stack)
{
diff --git a/sys/arm64/linux/linux_machdep.c b/sys/arm64/linux/linux_machdep.c
index 749e097730f7..0bfe51f7da1e 100644
--- a/sys/arm64/linux/linux_machdep.c
+++ b/sys/arm64/linux/linux_machdep.c
@@ -33,19 +33,15 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/fcntl.h>
-#include <sys/imgact.h>
#include <sys/ktr.h>
#include <sys/proc.h>
#include <sys/ptrace.h>
#include <sys/reg.h>
#include <sys/sdt.h>
-#include <security/audit/audit.h>
-
#include <arm64/linux/linux.h>
#include <arm64/linux/linux_proto.h>
#include <compat/linux/linux_dtrace.h>
-#include <compat/linux/linux_emul.h>
#include <compat/linux/linux_fork.h>
#include <compat/linux/linux_misc.h>
#include <compat/linux/linux_mmap.h>
@@ -59,32 +55,6 @@ LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE);
/* DTrace probes */
LIN_SDT_PROBE_DEFINE0(machdep, linux_mmap2, todo);
-/*
- * LINUXTODO: deduplicate; linux_execve is common across archs, except that on
- * amd64 compat linuxulator it calls freebsd32_exec_copyin_args.
- */
-int
-linux_execve(struct thread *td, struct linux_execve_args *uap)
-{
- struct image_args eargs;
- char *path;
- int error;
-
- if (!LUSECONVPATH(td)) {
- error = exec_copyin_args(&eargs, uap->path, UIO_USERSPACE,
- uap->argp, uap->envp);
- } else {
- LCONVPATHEXIST(uap->path, &path);
- error = exec_copyin_args(&eargs, path, UIO_SYSSPACE,
- uap->argp, uap->envp);
- LFREEPATH(path);
- }
- if (error == 0)
- error = linux_common_execve(td, &eargs);
- AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
- return (error);
-}
-
int
linux_set_upcall(struct thread *td, register_t stack)
{
diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index 7ea4b8481220..225187826677 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
#include <sys/imgact_aout.h>
#endif
#include <sys/jail.h>
+#include <sys/imgact.h>
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/lock.h>
@@ -74,6 +75,7 @@ __FBSDID("$FreeBSD$");
#include <sys/cpuset.h>
#include <sys/uio.h>
+#include <security/audit/audit.h>
#include <security/mac/mac_framework.h>
#include <vm/vm.h>
@@ -2906,3 +2908,29 @@ linux_seccomp(struct thread *td, struct linux_seccomp_args *args)
return (EINVAL);
}
}
+
+#ifndef COMPAT_LINUX32
+int
+linux_execve(struct thread *td, struct linux_execve_args *args)
+{
+ struct image_args eargs;
+ char *path;
+ int error;
+
+ LINUX_CTR(execve);
+
+ if (!LUSECONVPATH(td)) {
+ error = exec_copyin_args(&eargs, args->path, UIO_USERSPACE,
+ args->argp, args->envp);
+ } else {
+ LCONVPATHEXIST(args->path, &path);
+ error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, args->argp,
+ args->envp);
+ LFREEPATH(path);
+ }
+ if (error == 0)
+ error = linux_common_execve(td, &eargs);
+ AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
+ return (error);
+}
+#endif
diff --git a/sys/i386/linux/linux_machdep.c b/sys/i386/linux/linux_machdep.c
index 1e665eb9f505..dc156dbd673d 100644
--- a/sys/i386/linux/linux_machdep.c
+++ b/sys/i386/linux/linux_machdep.c
@@ -33,7 +33,6 @@ __FBSDID("$FreeBSD$");
#include <sys/capsicum.h>
#include <sys/fcntl.h>
#include <sys/file.h>
-#include <sys/imgact.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mman.h>
@@ -61,8 +60,6 @@ __FBSDID("$FreeBSD$");
#include <vm/vm.h>
#include <vm/vm_map.h>
-#include <security/audit/audit.h>
-
#include <i386/linux/linux.h>
#include <i386/linux/linux_proto.h>
#include <compat/linux/linux_emul.h>
@@ -97,28 +94,6 @@ struct l_old_select_argv {
struct l_timeval *timeout;
};
-int
-linux_execve(struct thread *td, struct linux_execve_args *args)
-{
- struct image_args eargs;
- char *newpath;
- int error;
-
- if (!LUSECONVPATH(td)) {
- error = exec_copyin_args(&eargs, args->path, UIO_USERSPACE,
- args->argp, args->envp);
- } else {
- LCONVPATHEXIST(args->path, &newpath);
- error = exec_copyin_args(&eargs, newpath, UIO_SYSSPACE,
- args->argp, args->envp);
- LFREEPATH(newpath);
- }
- if (error == 0)
- error = linux_common_execve(td, &eargs);
- AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
- return (error);
-}
-
struct l_ipc_kludge {
struct l_msgbuf *msgp;
l_long msgtyp;