Skip to content

Commit

Permalink
Add gettid, sched_get_priority_min / _max
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX committed Aug 24, 2022
1 parent bff594f commit 00f1daa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,22 @@ ssize_t shim::__read_chk(int fd, void *buf, size_t count, size_t buf_size) {
return read(fd, buf, count);
}

int shim::gettid() {
#ifdef __APPLE__
uint64_t tid;
pthread_threadid_np(NULL, &tid);
return (long&)tid;
#elif defined(SYS_gettid)
return syscall(SYS_gettid);
#else
// Fallback for freebsd
return pthread_getthreadid_np();
#endif
}

long shim::fakesyscall(long sysno, ...) {
if (sysno == FAKE_SYS_gettid) {
#ifdef __APPLE__
uint64_t tid;
pthread_threadid_np(NULL, &tid);
return (long&)tid;
#elif defined(SYS_gettid)
return syscall(SYS_gettid);
#else
// Fallback for freebsd
return pthread_getthreadid_np();
#endif
return shim::gettid();
} else if (sysno == FAKE_SYS_getrandom) {
va_list l;
va_start(l, sysno);
Expand Down Expand Up @@ -569,6 +573,9 @@ void shim::add_unistd_shimmed_symbols(std::vector<shim::shimmed_symbol> &list) {
{"getpagesize", ::getpagesize},
{"getdtablesize", ::getdtablesize},
{"syscall", fakesyscall},
{"gettid", gettid},
{"sched_get_priority_min", sched_get_priority_min},
{"sched_get_priority_max", sched_get_priority_max},
{"lockf", WithErrnoUpdate(::lockf)},
{"swab", ::swab},

Expand Down
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace shim {

}

int gettid();
void assert_impl(const char* file, int line, const char* msg);
void assert2_impl(const char* file, int line, const char* function, const char* msg);

Expand Down

0 comments on commit 00f1daa

Please sign in to comment.