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