* Fill in information that is thread specific. Must be called with * target process locked. If 'preferthread' is set, overwrite certain * process-related fields that are maintained for both threads and * processes. */
| 1213 | * processes. |
| 1214 | */ |
| 1215 | static void |
| 1216 | fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp, int preferthread) |
| 1217 | { |
| 1218 | struct proc *p; |
| 1219 | |
| 1220 | p = td->td_proc; |
| 1221 | kp->ki_tdaddr = td; |
| 1222 | PROC_LOCK_ASSERT(p, MA_OWNED); |
| 1223 | |
| 1224 | if (preferthread) |
| 1225 | PROC_STATLOCK(p); |
| 1226 | thread_lock(td); |
| 1227 | if (td->td_wmesg != NULL) |
| 1228 | strlcpy(kp->ki_wmesg, td->td_wmesg, sizeof(kp->ki_wmesg)); |
| 1229 | else |
| 1230 | bzero(kp->ki_wmesg, sizeof(kp->ki_wmesg)); |
| 1231 | if (strlcpy(kp->ki_tdname, td->td_name, sizeof(kp->ki_tdname)) >= |
| 1232 | sizeof(kp->ki_tdname)) { |
| 1233 | strlcpy(kp->ki_moretdname, |
| 1234 | td->td_name + sizeof(kp->ki_tdname) - 1, |
| 1235 | sizeof(kp->ki_moretdname)); |
| 1236 | } else { |
| 1237 | bzero(kp->ki_moretdname, sizeof(kp->ki_moretdname)); |
| 1238 | } |
| 1239 | if (TD_ON_LOCK(td)) { |
| 1240 | kp->ki_kiflag |= KI_LOCKBLOCK; |
| 1241 | strlcpy(kp->ki_lockname, td->td_lockname, |
| 1242 | sizeof(kp->ki_lockname)); |
| 1243 | } else { |
| 1244 | kp->ki_kiflag &= ~KI_LOCKBLOCK; |
| 1245 | bzero(kp->ki_lockname, sizeof(kp->ki_lockname)); |
| 1246 | } |
| 1247 | |
| 1248 | if (p->p_state == PRS_NORMAL) { /* approximate. */ |
| 1249 | if (TD_ON_RUNQ(td) || |
| 1250 | TD_CAN_RUN(td) || |
| 1251 | TD_IS_RUNNING(td)) { |
| 1252 | kp->ki_stat = SRUN; |
| 1253 | } else if (P_SHOULDSTOP(p)) { |
| 1254 | kp->ki_stat = SSTOP; |
| 1255 | } else if (TD_IS_SLEEPING(td)) { |
| 1256 | kp->ki_stat = SSLEEP; |
| 1257 | } else if (TD_ON_LOCK(td)) { |
| 1258 | kp->ki_stat = SLOCK; |
| 1259 | } else { |
| 1260 | kp->ki_stat = SWAIT; |
| 1261 | } |
| 1262 | } else if (p->p_state == PRS_ZOMBIE) { |
| 1263 | kp->ki_stat = SZOMB; |
| 1264 | } else { |
| 1265 | kp->ki_stat = SIDL; |
| 1266 | } |
| 1267 | |
| 1268 | /* Things in the thread */ |
| 1269 | kp->ki_wchan = td->td_wchan; |
| 1270 | kp->ki_pri.pri_level = td->td_priority; |
| 1271 | kp->ki_pri.pri_native = td->td_base_pri; |
| 1272 |
no test coverage detected