• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _LIBTHREAD_DB__THREAD_DB_H
18 #define _LIBTHREAD_DB__THREAD_DB_H
19 
20 #include <pthread.h>
21 #include <signal.h>
22 #include <stdint.h>
23 #include <sys/types.h>
24 
25 typedef void *psaddr_t;
26 #define HAVE_PSADDR_T 1
27 
28 typedef pid_t lwpid_t;
29 #define HAVE_LWPID_T 1
30 
31 #define TD_THR_ANY_USER_FLAGS       0xffffffff
32 #define TD_THR_LOWEST_PRIORITY      -20
33 #define TD_SIGNO_MASK               NULL
34 
35 /* td_err_e values */
36 enum {
37     TD_OK,
38     TD_ERR,
39     TD_NOTHR,
40     TD_NOSV,
41     TD_NOLWP,
42     TD_BADPH,
43     TD_BADTH,
44     TD_BADSH,
45     TD_BADTA,
46     TD_BADKEY,
47     TD_NOMSG,
48     TD_NOFPREGS,
49     TD_NOLIBTHREAD,
50     TD_NOEVENT,
51     TD_NOCAPAB,
52     TD_DBERR,
53     TD_NOAPLIC,
54     TD_NOTSD,
55     TD_MALLOC,
56     TD_PARTIALREG,
57     TD_NOXREGS,
58     TD_VERSION
59 };
60 
61 /*
62  * td_event_e values
63  * NOTE: There is a max of 32 events
64  */
65 enum {
66     TD_CREATE,
67     TD_DEATH
68 };
69 
70 /* td_thr_state_e values */
71 enum {
72     TD_THR_ANY_STATE,
73     TD_THR_UNKNOWN,
74     TD_THR_SLEEP,
75     TD_THR_ZOMBIE
76 };
77 
78 typedef int32_t td_err_e;
79 typedef uint32_t td_event_e;
80 typedef uint32_t td_notify_e;
81 typedef uint32_t td_thr_state_e;
82 typedef pthread_t thread_t;
83 
84 typedef struct
85 {
86     pid_t pid;
87     struct ps_prochandle *ph;
88 } td_thragent_t;
89 
90 typedef struct
91 {
92     pid_t pid;
93     pid_t tid;
94 } td_thrhandle_t;
95 
96 typedef struct
97 {
98     td_event_e event;
99     td_thrhandle_t const * th_p;
100     union {
101         void * data;
102     } msg;
103 } td_event_msg_t;
104 
105 typedef struct
106 {
107     uint32_t events;
108 } td_thr_events_t;
109 
110 typedef struct
111 {
112     union {
113         void * bptaddr;
114     } u;
115 } td_notify_t;
116 
117 typedef struct
118 {
119     td_thr_state_e ti_state;
120     thread_t ti_tid; // pthread's id for the thread
121     int32_t ti_lid; // the kernel's id for the thread
122 } td_thrinfo_t;
123 
124 
125 #define td_event_emptyset(set) \
126     (set)->events = 0
127 
128 #define td_event_fillset(set) \
129     (set)->events = 0xffffffff
130 
131 #define td_event_addset(set, n) \
132     (set)->events |= (1 << n)
133 
134 
135 typedef int td_thr_iter_f(td_thrhandle_t const *, void *);
136 
137 
138 struct ps_prochandle;
139 
140 #ifdef __cplusplus
141 extern "C"{
142 #endif
143 
144 extern td_err_e td_ta_new(struct ps_prochandle * proc_handle, td_thragent_t ** thread_agent);
145 
146 extern td_err_e td_ta_delete(td_thragent_t * ta);
147 
148 extern td_err_e td_ta_set_event(td_thragent_t const * agent, td_thr_events_t * event);
149 
150 extern td_err_e td_ta_event_addr(td_thragent_t const * agent, td_event_e event, td_notify_t * notify);
151 
152 extern td_err_e td_ta_clear_event(const td_thragent_t * ta_arg,
153 				  td_thr_events_t * event);
154 
155 extern td_err_e td_ta_event_getmsg(td_thragent_t const * agent, td_event_msg_t * event);
156 
157 extern td_err_e td_ta_map_lwp2thr(td_thragent_t const * agent, lwpid_t lwpid,
158 				  td_thrhandle_t *th);
159 
160 extern td_err_e td_thr_get_info(td_thrhandle_t const * handle,
161 				td_thrinfo_t * info);
162 
163 extern td_err_e td_thr_event_enable(td_thrhandle_t const * handle,
164 				    td_event_e event);
165 
166 extern td_err_e td_ta_thr_iter(td_thragent_t const * agent, td_thr_iter_f * func, void * cookie,
167                                td_thr_state_e state, int32_t prio, sigset_t * sigmask, uint32_t user_flags);
168 
169 extern char const ** td_symbol_list(void);
170 
171 extern td_err_e td_thr_event_enable(td_thrhandle_t const * handle, td_event_e event);
172 
173 extern td_err_e td_thr_get_info(td_thrhandle_t const * handle, td_thrinfo_t * info);
174 
175 extern td_err_e td_thr_tls_get_addr(const td_thrhandle_t * th,
176 				    psaddr_t map_address, size_t offset,
177 				    psaddr_t * address);
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 
183 #endif
184