xref: /f-stack/freebsd/sys/exec.h (revision 22ce4aff)
1a9643ea8Slogwang /*-
2*22ce4affSfengbojiang  * SPDX-License-Identifier: BSD-3-Clause
3*22ce4affSfengbojiang  *
4a9643ea8Slogwang  * Copyright (c) 1992, 1993
5a9643ea8Slogwang  *	The Regents of the University of California.  All rights reserved.
6a9643ea8Slogwang  * (c) UNIX System Laboratories, Inc.
7a9643ea8Slogwang  * All or some portions of this file are derived from material licensed
8a9643ea8Slogwang  * to the University of California by American Telephone and Telegraph
9a9643ea8Slogwang  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10a9643ea8Slogwang  * the permission of UNIX System Laboratories, Inc.
11a9643ea8Slogwang  *
12a9643ea8Slogwang  * Redistribution and use in source and binary forms, with or without
13a9643ea8Slogwang  * modification, are permitted provided that the following conditions
14a9643ea8Slogwang  * are met:
15a9643ea8Slogwang  * 1. Redistributions of source code must retain the above copyright
16a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer.
17a9643ea8Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
18a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer in the
19a9643ea8Slogwang  *    documentation and/or other materials provided with the distribution.
20*22ce4affSfengbojiang  * 3. Neither the name of the University nor the names of its contributors
21a9643ea8Slogwang  *    may be used to endorse or promote products derived from this software
22a9643ea8Slogwang  *    without specific prior written permission.
23a9643ea8Slogwang  *
24a9643ea8Slogwang  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25a9643ea8Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26a9643ea8Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27a9643ea8Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28a9643ea8Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29a9643ea8Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30a9643ea8Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31a9643ea8Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32a9643ea8Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33a9643ea8Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34a9643ea8Slogwang  * SUCH DAMAGE.
35a9643ea8Slogwang  *
36a9643ea8Slogwang  *	@(#)exec.h	8.3 (Berkeley) 1/21/94
37a9643ea8Slogwang  * $FreeBSD$
38a9643ea8Slogwang  */
39a9643ea8Slogwang 
40a9643ea8Slogwang #ifndef _SYS_EXEC_H_
41a9643ea8Slogwang #define _SYS_EXEC_H_
42a9643ea8Slogwang 
43a9643ea8Slogwang /*
44a9643ea8Slogwang  * Before ps_args existed, the following structure, found at the top of
45a9643ea8Slogwang  * the user stack of each user process, was used by ps(1) to locate
46a9643ea8Slogwang  * environment and argv strings.  Normally ps_argvstr points to the
47a9643ea8Slogwang  * argv vector, and ps_nargvstr is the same as the program's argc. The
48a9643ea8Slogwang  * fields ps_envstr and ps_nenvstr are the equivalent for the environment.
49a9643ea8Slogwang  *
50a9643ea8Slogwang  * Programs should now use setproctitle(3) to change ps output.
51a9643ea8Slogwang  * setproctitle() always informs the kernel with sysctl and sets the
52a9643ea8Slogwang  * pointers in ps_strings.  The kern.proc.args sysctl first tries p_args.
53a9643ea8Slogwang  * If p_args is NULL, it then falls back to reading ps_strings and following
54a9643ea8Slogwang  * the pointers.
55a9643ea8Slogwang  */
56a9643ea8Slogwang struct ps_strings {
57a9643ea8Slogwang 	char	**ps_argvstr;	/* first of 0 or more argument strings */
58a9643ea8Slogwang 	unsigned int ps_nargvstr; /* the number of argument strings */
59a9643ea8Slogwang 	char	**ps_envstr;	/* first of 0 or more environment strings */
60a9643ea8Slogwang 	unsigned int ps_nenvstr; /* the number of environment strings */
61a9643ea8Slogwang };
62a9643ea8Slogwang 
63a9643ea8Slogwang struct image_params;
64a9643ea8Slogwang 
65a9643ea8Slogwang struct execsw {
66a9643ea8Slogwang 	int (*ex_imgact)(struct image_params *);
67a9643ea8Slogwang 	const char *ex_name;
68a9643ea8Slogwang };
69a9643ea8Slogwang 
70a9643ea8Slogwang #include <machine/exec.h>
71a9643ea8Slogwang 
72a9643ea8Slogwang #ifdef _KERNEL
73a9643ea8Slogwang #include <sys/cdefs.h>
74a9643ea8Slogwang 
75a9643ea8Slogwang /*
76a9643ea8Slogwang  * Address of ps_strings structure (in user space).
77a9643ea8Slogwang  * Prefer the kern.ps_strings or kern.proc.ps_strings sysctls to this constant.
78a9643ea8Slogwang  */
79a9643ea8Slogwang #define	PS_STRINGS	(USRSTACK - sizeof(struct ps_strings))
80a9643ea8Slogwang 
81a9643ea8Slogwang int exec_map_first_page(struct image_params *);
82a9643ea8Slogwang void exec_unmap_first_page(struct image_params *);
83a9643ea8Slogwang 
84a9643ea8Slogwang int exec_register(const struct execsw *);
85a9643ea8Slogwang int exec_unregister(const struct execsw *);
86a9643ea8Slogwang 
87a9643ea8Slogwang extern int coredump_pack_fileinfo;
88a9643ea8Slogwang extern int coredump_pack_vmmapinfo;
89a9643ea8Slogwang 
90a9643ea8Slogwang /*
91a9643ea8Slogwang  * note: name##_mod cannot be const storage because the
92a9643ea8Slogwang  * linker_file_sysinit() function modifies _file in the
93a9643ea8Slogwang  * moduledata_t.
94a9643ea8Slogwang  */
95a9643ea8Slogwang 
96a9643ea8Slogwang #include <sys/module.h>
97a9643ea8Slogwang 
98a9643ea8Slogwang #define EXEC_SET(name, execsw_arg) \
99a9643ea8Slogwang 	static int __CONCAT(name,_modevent)(module_t mod, int type, \
100a9643ea8Slogwang 	    void *data) \
101a9643ea8Slogwang 	{ \
102a9643ea8Slogwang 		struct execsw *exec = (struct execsw *)data; \
103a9643ea8Slogwang 		int error = 0; \
104a9643ea8Slogwang 		switch (type) { \
105a9643ea8Slogwang 		case MOD_LOAD: \
106a9643ea8Slogwang 			/* printf(#name " module loaded\n"); */ \
107a9643ea8Slogwang 			error = exec_register(exec); \
108a9643ea8Slogwang 			if (error) \
109a9643ea8Slogwang 				printf(__XSTRING(name) "register failed\n"); \
110a9643ea8Slogwang 			break; \
111a9643ea8Slogwang 		case MOD_UNLOAD: \
112a9643ea8Slogwang 			/* printf(#name " module unloaded\n"); */ \
113a9643ea8Slogwang 			error = exec_unregister(exec); \
114a9643ea8Slogwang 			if (error) \
115a9643ea8Slogwang 				printf(__XSTRING(name) " unregister failed\n");\
116a9643ea8Slogwang 			break; \
117a9643ea8Slogwang 		default: \
118a9643ea8Slogwang 			error = EOPNOTSUPP; \
119a9643ea8Slogwang 			break; \
120a9643ea8Slogwang 		} \
121a9643ea8Slogwang 		return error; \
122a9643ea8Slogwang 	} \
123a9643ea8Slogwang 	static moduledata_t __CONCAT(name,_mod) = { \
124a9643ea8Slogwang 		__XSTRING(name), \
125a9643ea8Slogwang 		__CONCAT(name,_modevent), \
126a9643ea8Slogwang 		(void *)& execsw_arg \
127a9643ea8Slogwang 	}; \
128a9643ea8Slogwang 	DECLARE_MODULE_TIED(name, __CONCAT(name,_mod), SI_SUB_EXEC, \
129a9643ea8Slogwang 	    SI_ORDER_ANY)
130a9643ea8Slogwang #endif
131a9643ea8Slogwang 
132a9643ea8Slogwang #endif
133