The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/tools/cred_dump_backtraces.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    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.
    5  */
    6 
    7 #include <stdio.h>
    8 #include <stdlib.h>
    9 #include <fcntl.h>
   10 #include <limits.h>
   11 #include <string.h>
   12 #include <errno.h>
   13 #include <unistd.h>
   14 #include <sys/stat.h>
   15 #include <sys/types.h>
   16 #include <sys/sysctl.h>
   17 #include <bsm/audit.h>
   18 
   19 /* bad!  this is replicated in kern_credential.c.  make sure they stay in sync!
   20  * Or better yet have commone header file? 
   21  */
   22 #define MAX_STACK_DEPTH 8
   23 struct cred_backtrace {
   24         int                             depth;
   25         uint32_t                stack[ MAX_STACK_DEPTH ];
   26 };
   27 typedef struct cred_backtrace cred_backtrace;
   28 
   29 struct cred_debug_buffer {
   30         int                             next_slot;
   31         cred_backtrace  stack_buffer[ 1 ];      
   32 };
   33 typedef struct cred_debug_buffer cred_debug_buffer;
   34 
   35 
   36 main( int argc, char *argv[] )
   37 {
   38         int                             err, i, j;
   39         size_t                  len;
   40     char                        *my_bufferp = NULL;
   41         cred_debug_buffer       *bt_buffp;
   42         cred_backtrace          *btp;
   43 
   44         /* get size of buffer we will need */
   45         len = 0;
   46     err = sysctlbyname( "kern.cred_bt", NULL, &len, NULL, 0 );
   47         if ( err != 0 ) {
   48                 printf( "sysctl failed  \n" );
   49                 printf( "\terrno %d - \"%s\" \n", errno, strerror( errno ) );
   50                 return;
   51         }
   52         
   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 ) );
   57                 return;
   58         }
   59     err = sysctlbyname( "kern.cred_bt", my_bufferp, &len, NULL, 0 );
   60         if ( err != 0 ) {
   61                 printf( "sysctl 2 failed  \n" );
   62                 printf( "\terrno %d - \"%s\" \n", errno, strerror( errno ) );
   63                 return;
   64         }
   65 
   66         bt_buffp = (cred_debug_buffer *) my_bufferp;
   67         btp = &bt_buffp->stack_buffer[ 0 ];
   68         
   69         printf("number of traces %d \n", bt_buffp->next_slot);
   70         for ( i = 0; i < bt_buffp->next_slot; i++, btp++ ) {
   71                 printf("[%d] ", i);
   72                 for ( j = 0; j < btp->depth; j++ ) {
   73                         printf("%p ", btp->stack[ j ]);
   74                 }
   75                 printf("\n");
   76         }
   77         
   78         return;
   79 }
   80 

Cache object: 2fe1ff0357e11f1942d033b8b29a6ddc


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.