From 97c884fda8f097721e2062daccc25e36b31dc44e Mon Sep 17 00:00:00 2001
From: Aaron LI <aly@aaronly.me>
Date: Wed, 17 Feb 2021 20:18:42 +0800
Subject: [PATCH 3/7] kern: Staticize several functions and variables in
 kern_exec.c

Staticize exec_copyin_args(), exec_free_args() and print_execve_args()
functions, and move the related prototypes and exec_path_segflg enum
from <sys/imgact.h> here.

In addition, staticize the 'debug_execve_args' variable.
---
 sys/kern/kern_exec.c | 23 ++++++++++++++++-------
 sys/sys/imgact.h     |  9 ++-------
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 3a85873651c..39bbe2458c1 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -77,7 +77,16 @@
 MALLOC_DEFINE(M_PARGS, "proc-args", "Process arguments");
 MALLOC_DEFINE(M_EXECARGS, "exec-args", "Exec arguments");
 
-static register_t *exec_copyout_strings (struct image_params *);
+enum exec_path_segflg {
+	PATH_SYSSPACE,
+	PATH_USERSPACE,
+};
+
+static register_t *exec_copyout_strings(struct image_params *);
+static int	exec_copyin_args(struct image_args *, char *,
+				 enum exec_path_segflg, char **, char **);
+static void	exec_free_args(struct image_args *);
+static void	print_execve_args(struct image_args *args);
 
 /* XXX This should be vm_size_t. */
 __read_mostly static u_long ps_strings = PS_STRINGS;
@@ -97,8 +106,7 @@ SYSCTL_INT(_kern, OID_AUTO, ps_argsopen, CTLFLAG_RW, &ps_argsopen, 0, "");
 __read_mostly static int ktrace_suid = 0;
 SYSCTL_INT(_kern, OID_AUTO, ktrace_suid, CTLFLAG_RW, &ktrace_suid, 0, "");
 
-void print_execve_args(struct image_args *args);
-__read_mostly int debug_execve_args = 0;
+__read_mostly static int debug_execve_args = 0;
 SYSCTL_INT(_kern, OID_AUTO, debug_execve_args, CTLFLAG_RW, &debug_execve_args,
     0, "");
 
@@ -159,7 +167,7 @@ SYSCTL_PROC(_kern, OID_AUTO, stackgap_random, CTLFLAG_RW|CTLTYPE_INT,
 	0, 0, sysctl_kern_stackgap, "I",
 	"Max random stack gap (power of 2), static gap if negative");
 
-void
+static void
 print_execve_args(struct image_args *args)
 {
 	char *cp;
@@ -899,9 +907,9 @@ exec_new_vmspace(struct image_params *imgp, struct vmspace *vmcopy)
  * Copy out argument and environment strings from the old process
  *	address space into the temporary string buffer.
  */
-int
+static int
 exec_copyin_args(struct image_args *args, char *fname,
-		enum exec_path_segflg segflg, char **argv, char **envv)
+		 enum exec_path_segflg segflg, char **argv, char **envv)
 {
 	char	*argp, *envp;
 	int	error = 0;
@@ -993,10 +1001,11 @@ exec_copyin_args(struct image_args *args, char *fname,
 			args->envc++;
 		}
 	}
+
 	return (error);
 }
 
-void
+static void
 exec_free_args(struct image_args *args)
 {
 	if (args->buf) {
diff --git a/sys/sys/imgact.h b/sys/sys/imgact.h
index 1cd5cdc59fb..cef991a1827 100644
--- a/sys/sys/imgact.h
+++ b/sys/sys/imgact.h
@@ -27,7 +27,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/sys/imgact.h,v 1.22.2.2 2001/12/22 01:21:44 jwd Exp $
- * $DragonFly: src/sys/sys/imgact.h,v 1.6 2004/04/11 00:10:34 dillon Exp $
  */
 
 #ifndef _SYS_IMGACT_H_
@@ -43,7 +42,7 @@ struct image_args {
 	char *begin_argv;	/* beginning of argv in buf */
 	char *begin_envv;	/* beginning of envv in buf */
 	char *endp;		/* current `end' pointer of arg & env strings */
-	char *fname;		/* beginning of file name */
+	char *fname;		/* file name of the executable */
 	int space;		/* space left in arg & env buffer */
 	int argc;		/* count of argument strings */
 	int envc;		/* count of environment strings */
@@ -70,16 +69,12 @@ struct image_params {
 };
 
 #ifdef _KERNEL
-enum	exec_path_segflg {PATH_SYSSPACE, PATH_USERSPACE};
-
 struct vmspace;
+
 int	exec_resident_imgact (struct image_params *);
 int	exec_check_permissions (struct image_params *, struct mount *);
 int	exec_new_vmspace (struct image_params *, struct vmspace *vmres);
 int	exec_shell_imgact (struct image_params *);
-int	exec_copyin_args(struct image_args *, char *, enum exec_path_segflg,
-	char **, char **);
-void	exec_free_args(struct image_args *);
 #endif
 
 #endif /* !_SYS_IMGACT_H_ */
-- 
2.30.0

