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.
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.
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]
22 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <sys/param.h>
26 #include <sys/types.h>
28 #include <sys/t_lock.h>
29 #include <sys/thread.h>
30 #include <sys/systm.h>
32 #include <c2/audit_kernel.h>
33 #include <c2/audit_record.h>
35 static kmem_cache_t
*au_buf_cache
;
38 * au_buff_t and token_t are equivalent (see audit_record.h). Don't
39 * confuse this token_t with the one that is defined for userspace
40 * in the same header file.
44 * Function: au_get_buff
51 t_audit_data_t
*tad
= U2A(u
);
56 * If asynchronous (interrupt) thread, then we can't sleep
57 * (the tad ERRJMP flag is set at the start of async processing).
59 if (tad
->tad_ctrl
& TAD_ERRJMP
) {
60 buffer
= kmem_cache_alloc(au_buf_cache
, KM_NOSLEEP
);
62 /* return to top of stack & report an error */
63 ASSERT(tad
->tad_errjmp
);
64 longjmp(tad
->tad_errjmp
);
67 buffer
= kmem_cache_alloc(au_buf_cache
, KM_SLEEP
);
69 /* Never gets here when buffer == NULL */
70 bzero(buffer
, sizeof (*buffer
));
75 * Function: au_free_rec
77 * au_buff_t *buf; start of the record chain
80 au_free_rec(au_buff_t
*buf
)
83 t_audit_data_t
*tad
= U2A(u
);
88 * If asynchronous (interrupt) thread, schedule the release
89 * (the tad ERRJMP flag is set at the start of async processing).
91 if (tad
->tad_ctrl
& TAD_ERRJMP
) {
92 /* Discard async events via softcall. */
93 softcall(audit_async_discard_backend
, buf
);
98 kmem_cache_free(au_buf_cache
, buf
);
104 * Backend routine to discard an async event. Invoked from softcall.
105 * (Note: the freeing of memory for the event can't be done safely in high
106 * interrupt context due to the chance of sleeping on an adaptive mutex.
107 * Hence the softcall.)
110 audit_async_discard_backend(void *addr
)
116 * Function: au_append_rec
118 * au_buff_t *rec; start of the record chain
119 * au_buff_t *buf; buffer to append
120 * int pack; AU_PACK/1 - pack data, AU_LINK/0 - link buffer
123 au_append_rec(au_buff_t
*rec
, au_buff_t
*buf
, int pack
)
128 while (rec
->next_buf
)
130 if (((int)(rec
->len
+ buf
->len
) <= AU_BUFSIZE
) && pack
) {
131 bcopy(buf
->buf
, (char *)(rec
->buf
+ rec
->len
),
133 rec
->len
+= buf
->len
;
134 rec
->next_buf
= buf
->next_buf
;
135 kmem_cache_free(au_buf_cache
, buf
);
143 * Function: au_append_buf
145 * char *data; data buffer to append
146 * int len; size of data to append
147 * au_buff_t *buf; buffer to append to
150 au_append_buf(const char *data
, int len
, au_buff_t
*buf
)
155 while (buf
->next_buf
!= NULL
)
158 new_len
= (uint_t
)(buf
->len
+ len
) > AU_BUFSIZE
?
159 AU_BUFSIZE
- buf
->len
: len
;
160 bcopy(data
, (buf
->buf
+ buf
->len
), (uint_t
)new_len
);
161 buf
->len
+= (uchar_t
)new_len
;
166 if ((new_buf
= au_get_buff()) == NULL
) {
169 buf
->next_buf
= new_buf
;
171 new_len
= len
> AU_BUFSIZE
? AU_BUFSIZE
: len
;
172 bcopy(data
, buf
->buf
, (uint_t
)new_len
);
173 buf
->len
= (uchar_t
)new_len
;
182 au_buf_cache
= kmem_cache_create("audit_buffer",
183 sizeof (au_buff_t
), 0, NULL
, NULL
, NULL
, NULL
, NULL
, 0);