From 949ddc71a07b6fafd02f0ebc5114d09932697e1d Mon Sep 17 00:00:00 2001 From: vlaforet Date: Thu, 29 Jun 2023 14:42:00 +0200 Subject: [PATCH 1/2] Make LiTL work with recent libraries --- src/mcstp.c | 6 +++--- src/utils.h | 4 ---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/mcstp.c b/src/mcstp.c index 7d4fbbf..3cf3dd3 100644 --- a/src/mcstp.c +++ b/src/mcstp.c @@ -39,7 +39,7 @@ * is preempted. * Indeed, a thread A can overtake another thread B behind which it has been * waiting for a long time. - * The waiting thread A will first yield its CPU (via pthread_yield) in order to + * The waiting thread A will first yield its CPU (via sched_yield) in order to * create an opportunity for the preempted thread (lock holder or B) to make * progress. * If this is not enough, T will overtake the predecessor thread (B) by marking @@ -144,7 +144,7 @@ int mcs_tp_mutex_trylock(mcs_tp_mutex_t *impl, mcs_tp_node_t *me) { goto success; } else if (me->status == FAILED) { if (GET_TIME() - impl->cs_start_time > MAX_CS_TIME) - pthread_yield(); + sched_yield(); me->last_lock = impl; return EBUSY; @@ -164,7 +164,7 @@ int mcs_tp_mutex_trylock(mcs_tp_mutex_t *impl, mcs_tp_node_t *me) { } if (GET_TIME() - impl->cs_start_time > MAX_CS_TIME) - pthread_yield(); + sched_yield(); me->last_lock = impl; return EBUSY; diff --git a/src/utils.h b/src/utils.h index 5514bdf..47f2ff3 100644 --- a/src/utils.h +++ b/src/utils.h @@ -109,10 +109,6 @@ static inline uint64_t rdtsc(void) { return low | ((uint64_t)high) << 32; } -static inline int gettid() { - return syscall(SYS_gettid); -} - // EPFL libslock #define my_random xorshf96 #define getticks rdtsc From 17289637c917747bdc376073248bacdcb9e981d5 Mon Sep 17 00:00:00 2001 From: vlaforet Date: Thu, 29 Jun 2023 14:42:46 +0200 Subject: [PATCH 2/2] Fix pthread_create interposition with glibc > 2.33 --- src/interpose.c | 4 +++- src/interpose.h | 2 ++ src/interpose.map | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/interpose.c b/src/interpose.c index 1e65e77..53648ee 100644 --- a/src/interpose.c +++ b/src/interpose.c @@ -405,7 +405,7 @@ static void *lp_start_routine(void *_arg) { return res; } -int pthread_create(pthread_t *thread, const pthread_attr_t *attr, +int __pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) { DEBUG_PTHREAD("[p] pthread_create\n"); struct routine *r = malloc(sizeof(struct routine)); @@ -415,6 +415,8 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, return REAL(pthread_create)(thread, attr, lp_start_routine, r); } +__asm__(".symver __pthread_create,pthread_create@@" GLIBC_2_2_5); +__asm__(".symver __pthread_create,pthread_create@" GLIBC_2_34); int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) { diff --git a/src/interpose.h b/src/interpose.h index 08eb99c..99a0689 100644 --- a/src/interpose.h +++ b/src/interpose.h @@ -51,7 +51,9 @@ fprintf(stderr, "WARNING: unable to find symbol: %s.\n", S(name)); \ } while (0) +#define GLIBC_2_2_5 "GLIBC_2.2.5" #define GLIBC_2_3_2 "GLIBC_2.3.2" +#define GLIBC_2_34 "GLIBC_2.34" extern int (*REAL(pthread_mutex_init))(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr); diff --git a/src/interpose.map b/src/interpose.map index 9a75060..1b4c358 100644 --- a/src/interpose.map +++ b/src/interpose.map @@ -35,3 +35,8 @@ GLIBC_2.3.2 { pthread_cond_wait; pthread_cond_timedwait; } GLIBC_2.2.5; + +GLIBC_2.34 { + global: + pthread_create; +} GLIBC_2.3.2; \ No newline at end of file