Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright 2006 The Android Open Source Project
      3  */
      4 
      5 #ifndef _LIBTHREAD_DB__THREAD_DB_H
      6 #define _LIBTHREAD_DB__THREAD_DB_H
      7 
      8 #include <pthread.h>
      9 #include <signal.h>
     10 #include <stdint.h>
     11 #include <sys/types.h>
     12 #include <sys/procfs.h>
     13 
     14 #define TD_THR_ANY_USER_FLAGS       0xffffffff
     15 #define TD_THR_LOWEST_PRIORITY      -20
     16 #define TD_SIGNO_MASK               NULL
     17 
     18 /* td_err_e values */
     19 enum {
     20     TD_OK,
     21     TD_ERR,
     22     TD_NOTHR,
     23     TD_NOSV,
     24     TD_NOLWP,
     25     TD_BADPH,
     26     TD_BADTH,
     27     TD_BADSH,
     28     TD_BADTA,
     29     TD_BADKEY,
     30     TD_NOMSG,
     31     TD_NOFPREGS,
     32     TD_NOLIBTHREAD,
     33     TD_NOEVENT,
     34     TD_NOCAPAB,
     35     TD_DBERR,
     36     TD_NOAPLIC,
     37     TD_NOTSD,
     38     TD_MALLOC,
     39     TD_PARTIALREG,
     40     TD_NOXREGS,
     41     TD_VERSION
     42 };
     43 
     44 /*
     45  * td_event_e values
     46  * NOTE: There is a max of 32 events
     47  */
     48 enum {
     49     TD_CREATE,
     50     TD_DEATH
     51 };
     52 
     53 /* td_thr_state_e values */
     54 enum {
     55     TD_THR_ANY_STATE,
     56     TD_THR_UNKNOWN,
     57     TD_THR_SLEEP,
     58     TD_THR_ZOMBIE
     59 };
     60 
     61 typedef int32_t td_err_e;
     62 typedef uint32_t td_event_e;
     63 typedef uint32_t td_notify_e;
     64 typedef uint32_t td_thr_state_e;
     65 typedef pthread_t thread_t;
     66 
     67 typedef struct
     68 {
     69     pid_t pid;
     70     struct ps_prochandle *ph;
     71 } td_thragent_t;
     72 
     73 typedef struct
     74 {
     75     pid_t pid;
     76     pid_t tid;
     77 } td_thrhandle_t;
     78 
     79 typedef struct
     80 {
     81     td_event_e event;
     82     td_thrhandle_t const * th_p;
     83     union {
     84         void * data;
     85     } msg;
     86 } td_event_msg_t;
     87 
     88 typedef struct
     89 {
     90     uint32_t events;
     91 } td_thr_events_t;
     92 
     93 typedef struct
     94 {
     95     union {
     96         void * bptaddr;
     97     } u;
     98 } td_notify_t;
     99 
    100 typedef struct
    101 {
    102     td_thr_state_e ti_state;
    103     thread_t ti_tid; // pthread's id for the thread
    104     int32_t ti_lid; // the kernel's id for the thread
    105 } td_thrinfo_t;
    106 
    107 
    108 #define td_event_emptyset(set) \
    109     (set)->events = 0
    110 
    111 #define td_event_fillset(set) \
    112     (set)->events = 0xffffffff
    113 
    114 #define td_event_addset(set, n) \
    115     (set)->events |= (1 << n)
    116 
    117 
    118 typedef int td_thr_iter_f(td_thrhandle_t const *, void *);
    119 
    120 
    121 struct ps_prochandle;
    122 
    123 #ifdef __cplusplus
    124 extern "C"{
    125 #endif
    126 
    127 extern td_err_e td_ta_new(struct ps_prochandle * proc_handle, td_thragent_t ** thread_agent);
    128 
    129 extern td_err_e td_ta_delete(td_thragent_t * ta);
    130 
    131 extern td_err_e td_ta_set_event(td_thragent_t const * agent, td_thr_events_t * event);
    132 
    133 extern td_err_e td_ta_event_addr(td_thragent_t const * agent, td_event_e event, td_notify_t * notify);
    134 
    135 extern td_err_e td_ta_clear_event(const td_thragent_t * ta_arg,
    136 				  td_thr_events_t * event);
    137 
    138 extern td_err_e td_ta_event_getmsg(td_thragent_t const * agent, td_event_msg_t * event);
    139 
    140 extern td_err_e td_ta_map_lwp2thr(td_thragent_t const * agent, lwpid_t lwpid,
    141 				  td_thrhandle_t *th);
    142 
    143 extern td_err_e td_thr_get_info(td_thrhandle_t const * handle,
    144 				td_thrinfo_t * info);
    145 
    146 extern td_err_e td_thr_event_enable(td_thrhandle_t const * handle,
    147 				    td_event_e event);
    148 
    149 extern td_err_e td_ta_thr_iter(td_thragent_t const * agent, td_thr_iter_f * func, void * cookie,
    150                                td_thr_state_e state, int32_t prio, sigset_t * sigmask, uint32_t user_flags);
    151 
    152 extern td_err_e td_thr_event_enable(td_thrhandle_t const * handle, td_event_e event);
    153 
    154 extern td_err_e td_thr_get_info(td_thrhandle_t const * handle, td_thrinfo_t * info);
    155 
    156 extern char const ** td_symbol_list(void);
    157 
    158 extern td_err_e td_thr_tls_get_addr(const td_thrhandle_t * th,
    159 				    psaddr_t map_address, size_t offset,
    160 				    psaddr_t * address);
    161 
    162 #ifdef __cplusplus
    163 }
    164 #endif
    165 
    166 #endif
    167