threadinfo.hh (9329:3fe8438cbcfc) threadinfo.hh (12090:11d69759b378)
1/*
2 * Copyright (c) 2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 81 unchanged lines hidden (view full) ---

90 p.readBlob(addr, (uint8_t *)&sp, sizeof(Addr));
91
92 return sp & ~ULL(0x3fff);
93 }
94
95 inline Addr
96 curTaskInfo(Addr thread_info = 0)
97 {
1/*
2 * Copyright (c) 2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 81 unchanged lines hidden (view full) ---

90 p.readBlob(addr, (uint8_t *)&sp, sizeof(Addr));
91
92 return sp & ~ULL(0x3fff);
93 }
94
95 inline Addr
96 curTaskInfo(Addr thread_info = 0)
97 {
98 // Note that in Linux 4.10 the thread_info struct will no longer have a
99 // pointer to the task_struct for arm64. See:
100 // https://patchwork.kernel.org/patch/9333699/
98 int32_t offset;
99 if (!get_data("thread_info_task", offset))
100 return 0;
101
102 if (!thread_info)
103 thread_info = curThreadInfo();
104
105 Addr addr;
106 CopyOut(tc, &addr, thread_info + offset, sizeof(addr));
107
108 return addr;
109 }
110
111 int32_t
101 int32_t offset;
102 if (!get_data("thread_info_task", offset))
103 return 0;
104
105 if (!thread_info)
106 thread_info = curThreadInfo();
107
108 Addr addr;
109 CopyOut(tc, &addr, thread_info + offset, sizeof(addr));
110
111 return addr;
112 }
113
114 int32_t
112 curTaskPID(Addr thread_info = 0)
113 {
115 curTaskPIDFromTaskStruct(Addr task_struct) {
114 int32_t offset;
115 if (!get_data("task_struct_pid", offset))
116 return -1;
117
118 int32_t pid;
116 int32_t offset;
117 if (!get_data("task_struct_pid", offset))
118 return -1;
119
120 int32_t pid;
119 CopyOut(tc, &pid, curTaskInfo(thread_info) + offset, sizeof(pid));
121 CopyOut(tc, &pid, task_struct + offset, sizeof(pid));
120
121 return pid;
122 }
123
124 int32_t
122
123 return pid;
124 }
125
126 int32_t
125 curTaskTGID(Addr thread_info = 0)
127 curTaskPID(Addr thread_info = 0)
126 {
128 {
129 return curTaskPIDFromTaskStruct(curTaskInfo(thread_info));
130 }
131
132 int32_t
133 curTaskTGIDFromTaskStruct(Addr task_struct)
134 {
127 int32_t offset;
128 if (!get_data("task_struct_tgid", offset))
129 return -1;
130
131 int32_t tgid;
135 int32_t offset;
136 if (!get_data("task_struct_tgid", offset))
137 return -1;
138
139 int32_t tgid;
132 CopyOut(tc, &tgid, curTaskInfo(thread_info) + offset, sizeof(tgid));
140 CopyOut(tc, &tgid, task_struct + offset, sizeof(tgid));
133
134 return tgid;
135 }
136
141
142 return tgid;
143 }
144
145 int32_t
146 curTaskTGID(Addr thread_info = 0)
147 {
148 return curTaskTGIDFromTaskStruct(curTaskInfo(thread_info));
149 }
150
137 int64_t
151 int64_t
138 curTaskStart(Addr thread_info = 0)
152 curTaskStartFromTaskStruct(Addr task_struct)
139 {
140 int32_t offset;
141 if (!get_data("task_struct_start_time", offset))
142 return -1;
143
144 int64_t data;
145 // start_time is actually of type timespec, but if we just
146 // grab the first long, we'll get the seconds out of it
153 {
154 int32_t offset;
155 if (!get_data("task_struct_start_time", offset))
156 return -1;
157
158 int64_t data;
159 // start_time is actually of type timespec, but if we just
160 // grab the first long, we'll get the seconds out of it
147 CopyOut(tc, &data, curTaskInfo(thread_info) + offset, sizeof(data));
161 CopyOut(tc, &data, task_struct + offset, sizeof(data));
148
149 return data;
150 }
151
162
163 return data;
164 }
165
166 int64_t
167 curTaskStart(Addr thread_info = 0)
168 {
169 return curTaskStartFromTaskStruct(curTaskInfo(thread_info));
170 }
171
152 std::string
172 std::string
153 curTaskName(Addr thread_info = 0)
173 curTaskNameFromTaskStruct(Addr task_struct)
154 {
155 int32_t offset;
156 int32_t size;
157
158 if (!get_data("task_struct_comm", offset))
159 return "FailureIn_curTaskName";
160
161 if (!get_data("task_struct_comm_size", size))
162 return "FailureIn_curTaskName";
163
164 char buffer[size + 1];
174 {
175 int32_t offset;
176 int32_t size;
177
178 if (!get_data("task_struct_comm", offset))
179 return "FailureIn_curTaskName";
180
181 if (!get_data("task_struct_comm_size", size))
182 return "FailureIn_curTaskName";
183
184 char buffer[size + 1];
165 CopyStringOut(tc, buffer, curTaskInfo(thread_info) + offset, size);
185 CopyStringOut(tc, buffer, task_struct + offset, size);
166
167 return buffer;
168 }
169
186
187 return buffer;
188 }
189
190 std::string
191 curTaskName(Addr thread_info = 0)
192 {
193 return curTaskNameFromTaskStruct(curTaskInfo(thread_info));
194 }
195
170 int32_t
196 int32_t
171 curTaskMm(Addr thread_info = 0)
197 curTaskMmFromTaskStruct(Addr task_struct)
172 {
173 int32_t offset;
174 if (!get_data("task_struct_mm", offset))
175 return -1;
176
177 int32_t mm_ptr;
198 {
199 int32_t offset;
200 if (!get_data("task_struct_mm", offset))
201 return -1;
202
203 int32_t mm_ptr;
178 CopyOut(tc, &mm_ptr, curTaskInfo(thread_info) + offset, sizeof(mm_ptr));
204 CopyOut(tc, &mm_ptr, task_struct + offset, sizeof(mm_ptr));
179
180 return mm_ptr;
181 }
205
206 return mm_ptr;
207 }
208
209 int32_t
210 curTaskMm(Addr thread_info = 0)
211 {
212 return curTaskMmFromTaskStruct(curTaskInfo(thread_info));
213 }
182};
183
184} // namespace Linux
185
186#endif // __ARCH_GENERIC_LINUX_THREADINFO_HH__
214};
215
216} // namespace Linux
217
218#endif // __ARCH_GENERIC_LINUX_THREADINFO_HH__