xref: /titanic_51/usr/src/cmd/sgs/rtld/common/_audit.h (revision bbaa8b60dd95d714741fc474adad3cf710ef4efd)
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 /*
23  * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef	__AUDIT_DOT_H
27 #define	__AUDIT_DOT_H
28 
29 #ifndef _ASM
30 
31 #include <sys/types.h>
32 #include <rtld.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Define all auditing structures.
40  *
41  * A shared object may be a client of one or more audit libraries.  Calls to an
42  * auditor are accompanied with cookies that identify an object being audited.
43  * These cookies are initialized to the link-map pointers of the object being
44  * audited, however the auditor is free to re-allocate these cookies, and thus
45  * associate their own data with each object being audited.
46  *
47  * With auditing version LAV_VERSION5, local auditors can provide la_preinit()
48  * and la_activity() routines, each of which should be passed a cookie that
49  * represents the link-map of the head of the associated link-map list.  These
50  * cookies are maintained on the associated link-map list, using the lm_cookies
51  * alist.  These cookies are created by _audit_add_head(), and dynamically
52  * retrieved by the _audit_preinit() and _audit_activity() routines.
53  *
54  * Having these cookies kept on the link-map list decouples these cookies from
55  * the Audit_client structure of the object being locally audited.  In addition,
56  * this model ensures that multiple objects, undergoing local auditing from the
57  * same auditor, receive the same head link-map cookie.
58  */
59 typedef struct {
60 	Rt_map		*ac_lmp;	/* audit library identifier */
61 	uintptr_t	ac_cookie;	/* cookie assigned to audit library */
62 	Word		ac_flags;	/*    and its associated flags */
63 } Audit_client;
64 
65 #define	FLG_AC_BINDTO	0x00001
66 #define	FLG_AC_BINDFROM	0x00002
67 
68 /*
69  * Each shared object being audited may provide a list of client structures
70  * and dynamic plts (one per auditor).
71  */
72 struct audit_info {
73 	uint_t		ai_cnt;		/* no. of clients */
74 	Audit_client	*ai_clients;	/* array of client structures */
75 	void		*ai_dynplts;	/* array of dynamic plts */
76 };
77 
78 /*
79  * Define an Audit Descriptor - each audit object is added to this descriptor
80  * as an Audit Interface.  There is one global audit descriptor - auditors,
81  * and a specific object my require its own - AUDITORS(lmp).
82  */
83 struct audit_desc {
84 	char		*ad_name;	/* originating audit names */
85 	APlist		*ad_list;	/* audit objs Audit Interface list */
86 	uint_t		ad_cnt;		/* no. of audit objs in this desc. */
87 	uint_t		ad_flags;	/* audit capabilities found.  See */
88 					/*    LML_TFLG_AUD_* flags */
89 };
90 
91 /*
92  * Define an Audit List descriptor for each audit object.
93  */
94 struct audit_list {
95 	const char	*al_libname;	/* object name for diagnostics */
96 	Rt_map		*al_lmp;	/* object link-map */
97 	Grp_hdl		*al_ghp;	/* object handle */
98 	uint_t		al_flags;	/* audit capabilities found */
99 	uint_t		(*al_version)(uint_t);
100 	void		(*al_preinit)(uintptr_t *);
101 	char		*(*al_objsearch)(const char *, uintptr_t *, uint_t);
102 	uint_t		(*al_objopen)(Link_map *, Lmid_t, uintptr_t *);
103 	int		(*al_objfilter)(uintptr_t *, const char *, uintptr_t *,
104 				uint_t);
105 	uint_t		(*al_objclose)(uintptr_t *);
106 	void		(*al_activity)(uintptr_t *, uint_t);
107 #if	defined(_ELF64)
108 	uintptr_t	(*al_pltenter)(Sym *, uint_t, uintptr_t *, uintptr_t *,
109 				void *, uint_t *, const char *);
110 	uintptr_t	(*al_pltexit)(Sym *, uint_t, uintptr_t *, uintptr_t *,
111 				uintptr_t, const char *);
112 	uintptr_t	(*al_symbind)(Sym *, uint_t, uintptr_t *,
113 				uintptr_t *, uint_t *, const char *);
114 #else
115 	uintptr_t	(*al_pltenter)(Sym *, uint_t, uintptr_t *, uintptr_t *,
116 				void *, uint_t *);
117 	uintptr_t	(*al_pltexit)(Sym *, uint_t, uintptr_t *, uintptr_t *,
118 				uintptr_t);
119 	uintptr_t	(*al_symbind)(Sym *, uint_t, uintptr_t *,
120 				uintptr_t *, uint_t *);
121 #endif /* _ELF64 */
122 	uint_t		al_vernum;	/* object version */
123 };
124 
125 /*
126  * Link-Edit audit functions
127  */
128 extern int		audit_setup(Rt_map *, Audit_desc *, uint_t, int *);
129 
130 extern void		audit_desc_cleanup(Rt_map *);
131 extern void		audit_info_cleanup(Rt_map *);
132 
133 extern int		audit_objopen(Rt_map *, Rt_map *);
134 extern int		audit_objfilter(Rt_map *, const char *, Rt_map *,
135 			    uint_t flags);
136 extern void		audit_activity(Rt_map *, uint_t);
137 extern void		audit_preinit(Rt_map *);
138 extern char		*audit_objsearch(Rt_map *, const char *, uint_t);
139 extern void		audit_objclose(Rt_map *, Rt_map *);
140 extern void		_audit_objclose(APlist *, Rt_map *);
141 extern Addr		audit_symbind(Rt_map *, Rt_map *, Sym *, uint_t,
142 			    Addr value, uint_t *);
143 extern Addr		audit_pltenter(Rt_map *, Rt_map *, Sym *, uint_t,
144 			    void *, uint_t *);
145 extern Addr		audit_pltexit(uintptr_t, Rt_map *, Rt_map *, Sym *,
146 			    uint_t);
147 
148 extern uint_t		audit_flags;
149 
150 #endif /* _ASM */
151 
152 /*
153  * Values for audit_flags.  Intended to be the same as the LML equivalents
154  * but kept in a separate variable to simplify boot_elf.s coding.
155  */
156 #define	AF_PLTENTER	0x01		/* same as LML_AUD_PLTENTER */
157 #define	AF_PLTEXIT	0x02		/* Same as LML_AUD_PLTEXIT */
158 
159 #ifdef	__cplusplus
160 }
161 #endif
162 
163 #endif /* __AUDIT_DOT_H */
164