1 /* quick and dirty hack to grab credential backtrace info from kernel via sysctl.
2 * sysctl is only defined if xnu is built with DEBUG_CRED defined.
3 * The current version of this is used to target a specific credential and gather
4 * backtrace info on all references and unreferences.
15 #include <sys/types.h>
16 #include <sys/sysctl.h>
17 #include <bsm/audit.h>
19 /* bad! this is replicated in kern_credential.c. make sure they stay in sync!
20 * Or better yet have commone header file?
22 #define MAX_STACK_DEPTH 8
23 struct cred_backtrace
{
25 uint32_t stack
[ MAX_STACK_DEPTH
];
27 typedef struct cred_backtrace cred_backtrace
;
29 struct cred_debug_buffer
{
31 cred_backtrace stack_buffer
[ 1 ];
33 typedef struct cred_debug_buffer cred_debug_buffer
;
36 main( int argc
, char *argv
[] )
40 char *my_bufferp
= NULL
;
41 cred_debug_buffer
*bt_buffp
;
44 /* get size of buffer we will need */
46 err
= sysctlbyname( "kern.cred_bt", NULL
, &len
, NULL
, 0 );
48 printf( "sysctl failed \n" );
49 printf( "\terrno %d - \"%s\" \n", errno
, strerror( errno
) );
53 /* get a buffer for our back traces */
54 my_bufferp
= malloc( len
);
55 if ( my_bufferp
== NULL
) {
56 printf( "malloc error %d - \"%s\" \n", errno
, strerror( errno
) );
59 err
= sysctlbyname( "kern.cred_bt", my_bufferp
, &len
, NULL
, 0 );
61 printf( "sysctl 2 failed \n" );
62 printf( "\terrno %d - \"%s\" \n", errno
, strerror( errno
) );
66 bt_buffp
= (cred_debug_buffer
*) my_bufferp
;
67 btp
= &bt_buffp
->stack_buffer
[ 0 ];
69 printf("number of traces %d \n", bt_buffp
->next_slot
);
70 for ( i
= 0; i
< bt_buffp
->next_slot
; i
++, btp
++ ) {
72 for ( j
= 0; j
< btp
->depth
; j
++ ) {
73 printf("%p ", btp
->stack
[ j
]);