Add support for epoll
authorweiyu <weiyuluo1232@gmail.com>
Sat, 5 Sep 2020 01:01:16 +0000 (18:01 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Sat, 5 Sep 2020 01:01:16 +0000 (18:01 -0700)
Makefile
threads-model.h
threads.cc

index adb080de5d44871596ee201fb659666684645bbc..1fdbf70297c7d2250f205ecf8118952ca42b9078 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ OBJECTS := libthreads.o schedule.o model.o threads.o librace.o action.o \
           snapshot.o malloc.o mymemory.o common.o mutex.o conditionvariable.o \
           context.o execution.o libannotate.o plugins.o pthread.o futex.o fuzzer.o \
           sleeps.o history.o funcnode.o funcinst.o predicate.o printf.o newfuzzer.o \
           snapshot.o malloc.o mymemory.o common.o mutex.o conditionvariable.o \
           context.o execution.o libannotate.o plugins.o pthread.o futex.o fuzzer.o \
           sleeps.o history.o funcnode.o funcinst.o predicate.o printf.o newfuzzer.o \
-          concretepredicate.o waitobj.o hashfunction.o pipe.o actionlist.o
+          concretepredicate.o waitobj.o hashfunction.o pipe.o epoll.o actionlist.o
 
 CPPFLAGS += -Iinclude -I.
 LDFLAGS := -ldl -lrt -rdynamic -lpthread
 
 CPPFLAGS += -Iinclude -I.
 LDFLAGS := -ldl -lrt -rdynamic -lpthread
index 15dd151577e908027f002565cf2855e95c85d787..a99f6619350fdcd21a6f1b0c7899002f7e843e32 100644 (file)
@@ -13,6 +13,7 @@
 #include "context.h"
 #include "classlist.h"
 #include "pthread.h"
 #include "context.h"
 #include "classlist.h"
 #include "pthread.h"
+#include <sys/epoll.h>
 
 struct thread_params {
        thrd_start_t func;
 
 struct thread_params {
        thrd_start_t func;
@@ -232,6 +233,7 @@ static inline int id_to_int(thread_id_t id)
        return id;
 }
 
        return id;
 }
 
+int real_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);
 int real_pthread_mutex_init(pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr);
 int real_pthread_mutex_lock (pthread_mutex_t *__mutex);
 int real_pthread_mutex_unlock (pthread_mutex_t *__mutex);
 int real_pthread_mutex_init(pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr);
 int real_pthread_mutex_lock (pthread_mutex_t *__mutex);
 int real_pthread_mutex_unlock (pthread_mutex_t *__mutex);
index e22ffa3221f83ae1f95abb5b7b6c63da04c72183..faa49fc5707454bb105b384d1f4482bd418fb711 100644 (file)
@@ -16,8 +16,9 @@
 #include "schedule.h"
 #include "clockvector.h"
 
 #include "schedule.h"
 #include "clockvector.h"
 
-#ifdef TLS
 #include <dlfcn.h>
 #include <dlfcn.h>
+
+#ifdef TLS
 uintptr_t get_tls_addr() {
        uintptr_t addr;
        asm ("mov %%fs:0, %0" : "=r" (addr));
 uintptr_t get_tls_addr() {
        uintptr_t addr;
        asm ("mov %%fs:0, %0" : "=r" (addr));
@@ -110,6 +111,13 @@ void thread_startup()
 #endif
 }
 
 #endif
 }
 
+
+static int (*real_epoll_wait_p)(int epfd, struct epoll_event *events, int maxevents, int timeout) = NULL;
+
+int real_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) {
+       return real_epoll_wait_p(epfd, events, maxevents, timeout);
+}
+
 static int (*pthread_mutex_init_p)(pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr) = NULL;
 
 int real_pthread_mutex_init(pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr) {
 static int (*pthread_mutex_init_p)(pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr) = NULL;
 
 int real_pthread_mutex_init(pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr) {
@@ -148,6 +156,13 @@ void real_pthread_exit (void * value_ptr) {
 
 void real_init_all() {
        char * error;
 
 void real_init_all() {
        char * error;
+       if (!real_epoll_wait_p) {
+               real_epoll_wait_p = (int (*)(int epfd, struct epoll_event *events, int maxevents, int timeout))dlsym(RTLD_NEXT, "epoll_wait");
+               if ((error = dlerror()) != NULL) {
+                       fputs(error, stderr);
+                       exit(EXIT_FAILURE);
+               }
+       }
        if (!pthread_mutex_init_p) {
                pthread_mutex_init_p = (int (*)(pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr))dlsym(RTLD_NEXT, "pthread_mutex_init");
                if ((error = dlerror()) != NULL) {
        if (!pthread_mutex_init_p) {
                pthread_mutex_init_p = (int (*)(pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr))dlsym(RTLD_NEXT, "pthread_mutex_init");
                if ((error = dlerror()) != NULL) {