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 
     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 } td_thragent_t;
     71 
     72 typedef struct
     73 {
     74     pid_t pid;
     75     pid_t tid;
     76 } td_thrhandle_t;
     77 
     78 typedef struct
     79 {
     80     td_event_e event;
     81     td_thrhandle_t const * th_p;
     82     union {
     83         void * data;
     84     } msg;
     85 } td_event_msg_t;
     86 
     87 typedef struct
     88 {
     89     uint32_t events;
     90 } td_thr_events_t;
     91 
     92 typedef struct
     93 {
     94     union {
     95         void * bptaddr;
     96     } u;
     97 } td_notify_t;
     98 
     99 typedef struct
    100 {
    101     td_thr_state_e ti_state;
    102     thread_t ti_tid; // pthread's id for the thread
    103     int32_t ti_lid; // the kernel's id for the thread
    104 } td_thrinfo_t;
    105 
    106 
    107 #define td_event_emptyset(set) \
    108     (set)->events = 0
    109 
    110 #define td_event_fillset(set) \
    111     (set)->events = 0xffffffff
    112 
    113 #define td_event_addset(set, n) \
    114     (set)->events |= (1 << n)
    115 
    116 
    117 typedef int td_thr_iter_f(td_thrhandle_t const *, void *);
    118 
    119 
    120 struct ps_prochandle;
    121 
    122 #ifdef __cplusplus
    123 extern "C"{
    124 #endif
    125 
    126 extern td_err_e td_ta_new(struct ps_prochandle const * proc_handle, td_thragent_t ** thread_agent);
    127 
    128 extern td_err_e td_ta_set_event(td_thragent_t const * agent, td_thr_events_t * event);
    129 
    130 extern td_err_e td_ta_event_addr(td_thragent_t const * agent, td_event_e event, td_notify_t * notify);
    131 
    132 extern td_err_e td_ta_event_getmsg(td_thragent_t const * agent, td_event_msg_t * event);
    133 
    134 extern td_err_e td_ta_thr_iter(td_thragent_t const * agent, td_thr_iter_f * func, void * cookie,
    135                                td_thr_state_e state, int32_t prio, sigset_t * sigmask, uint32_t user_flags);
    136 
    137 extern char const ** td_symbol_list(void);
    138 
    139 #ifdef __cplusplus
    140 }
    141 #endif
    142 
    143 #endif
    144