Add a tid_for_thread call

This commit is contained in:
Ariel Abreu 2022-03-24 13:58:45 -04:00
parent a4364df97b
commit be9afe1fa5
No known key found for this signature in database
GPG Key ID: D67AE16CCEA85B70
2 changed files with 20 additions and 0 deletions

View File

@ -200,6 +200,12 @@ calls = [
('tracer', 'int32_t'),
], []),
('tid_for_thread', [
('thread', 'uint32_t'),
], [
('tid', 'int32_t'),
]),
#
# kqueue channels
#

View File

@ -857,4 +857,18 @@ void DarlingServer::Call::SetTracer::processCall() {
_sendReply(code);
};
void DarlingServer::Call::TidForThread::processCall() {
int code = 0;
int32_t tid = 0;
if (auto thread = Thread::threadForPort(_body.thread)) {
tid = thread->nsid();
} else {
// might be user error (e.g. invalid port number or dead thread), so don't negate it
code = ESRCH;
}
_sendReply(code, tid);
};
DSERVER_CLASS_SOURCE_DEFS;