xref: /illumos-gate/usr/src/uts/common/exec/elf/elf_impl.h (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /*
26  * Copyright 2019 Joyent, Inc.
27  */
28 
29 #ifndef _ELF_ELF_IMPL_H
30 #define	_ELF_ELF_IMPL_H
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #if	!defined(_LP64) || defined(_ELF32_COMPAT)
37 
38 /*
39  * Definitions for ELF32, native 32-bit or 32-bit compatibility mode.
40  */
41 #define	ELFCLASS	ELFCLASS32
42 typedef	unsigned int	aux_val_t;
43 typedef	auxv32_t	aux_entry_t;
44 
45 #define	USR_LIB_RTLD	"/usr/lib/ld.so.1"
46 
47 #else	/* !_LP64 || _ELF32_COMPAT */
48 
49 /*
50  * Definitions for native 64-bit ELF
51  */
52 #define	ELFCLASS	ELFCLASS64
53 typedef	unsigned long	aux_val_t;
54 typedef	auxv_t		aux_entry_t;
55 
56 /* put defines for 64-bit architectures here */
57 #if defined(__sparcv9)
58 #define	USR_LIB_RTLD	"/usr/lib/sparcv9/ld.so.1"
59 #endif
60 
61 #if defined(__amd64)
62 #define	USR_LIB_RTLD	"/usr/lib/amd64/ld.so.1"
63 #endif
64 
65 #endif	/* !_LP64 || _ELF32_COMPAT */
66 
67 /*
68  * Start of an ELF Note.
69  */
70 typedef struct {
71 	Nhdr	nhdr;
72 	char	name[8];
73 } Note;
74 
75 typedef struct {
76 	vnode_t		*ecc_vp;
77 	proc_t		*ecc_p;
78 	cred_t		*ecc_credp;
79 	rlim64_t	ecc_rlimit;
80 	core_content_t	ecc_content;
81 	u_offset_t	ecc_doffset;
82 	void		*ecc_buf;
83 	size_t		ecc_bufsz;
84 } elf_core_ctx_t;
85 
86 #ifdef	_ELF32_COMPAT
87 /*
88  * These are defined only for the 32-bit compatibility
89  * compilation mode of the 64-bit kernel.
90  */
91 #define	elfexec	elf32exec
92 #define	elfnote	elf32note
93 #define	elfcore	elf32core
94 #define	elfreadhdr		elf32readhdr
95 #define	mapexec_brand		mapexec32_brand
96 #define	setup_note_header	setup_note_header32
97 #define	write_elfnotes		write_elfnotes32
98 #define	setup_old_note_header	setup_old_note_header32
99 #define	write_old_elfnotes	write_old_elfnotes32
100 
101 #if defined(__sparc)
102 #define	gwindows_t	gwindows32_t
103 #define	rwindow		rwindow32
104 #endif
105 
106 #define	psinfo_t	psinfo32_t
107 #define	pstatus_t	pstatus32_t
108 #define	lwpsinfo_t	lwpsinfo32_t
109 #define	lwpstatus_t	lwpstatus32_t
110 
111 #define	prgetpsinfo	prgetpsinfo32
112 #define	prgetstatus	prgetstatus32
113 #define	prgetlwpsinfo	prgetlwpsinfo32
114 #define	prgetlwpstatus	prgetlwpstatus32
115 #define	prgetwindows	prgetwindows32
116 
117 #define	prpsinfo_t	prpsinfo32_t
118 #define	prstatus_t	prstatus32_t
119 #if defined(prfpregset_t)
120 #undef prfpregset_t
121 #endif
122 #define	prfpregset_t	prfpregset32_t
123 
124 #define	oprgetstatus	oprgetstatus32
125 #define	oprgetpsinfo	oprgetpsinfo32
126 #define	prgetprfpregs	prgetprfpregs32
127 
128 #endif	/*	_ELF32_COMPAT	*/
129 
130 extern int elfnote(vnode_t *, offset_t *, int, int, void *, rlim64_t, cred_t *);
131 extern void setup_old_note_header(Phdr *, proc_t *);
132 extern void setup_note_header(Phdr *, proc_t *);
133 
134 extern int write_old_elfnotes(proc_t *, int, vnode_t *, offset_t,
135     rlim64_t, cred_t *);
136 
137 extern int write_elfnotes(proc_t *, int, vnode_t *, offset_t,
138     rlim64_t, cred_t *, core_content_t);
139 
140 #ifdef	__cplusplus
141 }
142 #endif
143 
144 #endif	/* _ELF_ELF_IMPL_H */
145