Skip to content

Commit

Permalink
Merge pull request #1 from kito-cheng/master
Browse files Browse the repository at this point in the history
Improve the DMTCP hack in bionic to prevent libc.a include libdl
  • Loading branch information
kito-cheng committed Feb 22, 2013
2 parents 0bc8d86 + 03955df commit 188d0a2
Showing 1 changed file with 20 additions and 48 deletions.
68 changes: 20 additions & 48 deletions bionic/0001-Bionic-support-for-DMTCP.patch
Original file line number Diff line number Diff line change
@@ -1,63 +1,56 @@
From 1a82cc9e1db7adc51aad481e3dcfa9da86083060 Mon Sep 17 00:00:00 2001
From 6e870d1b5c9e2a594f5d89eec2d971519bd7487c Mon Sep 17 00:00:00 2001
From: Kito Cheng <[email protected]>
Date: Mon, 30 Jul 2012 00:11:26 +0800
Subject: [PATCH 1/3] Bionic support for DMTCP

Change-Id: I427c324c09265dd2f369ad3fbb85de7cbcc7843c
---
libc/Android.mk | 2 +-
libc/bionic/pthread.c | 20 ++++++++++++++++----
libdl/Android.mk | 11 +++++++++++
3 files changed, 28 insertions(+), 5 deletions(-)
libc/bionic/pthread.c | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/libc/Android.mk b/libc/Android.mk
index ae54004..5109f77 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -714,7 +714,7 @@ LOCAL_CFLAGS := $(libc_common_cflags) \
-DLIBC_STATIC
LOCAL_C_INCLUDES := $(libc_common_c_includes)
LOCAL_MODULE := libc
-LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
+LOCAL_WHOLE_STATIC_LIBRARIES := libc_common libdl
LOCAL_SYSTEM_SHARED_LIBRARIES :=

include $(BUILD_STATIC_LIBRARY)
diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c
index 3435d21..b80d26e 100644
index 3435d21..97c7ddf 100644
--- a/libc/bionic/pthread.c
+++ b/libc/bionic/pthread.c
@@ -50,8 +50,11 @@
@@ -50,8 +50,15 @@
#include <fcntl.h>
#include <stdio.h>
#include <bionic_pthread.h>
+#ifndef LIBC_STATIC
+#include <dlfcn.h>
+#endif

extern int __pthread_clone(int (*fn)(void*), void *child_stack, int flags, void *arg);
+#ifndef LIBC_STATIC
+static int (*__hijack__pthread_clone)(int (*fn)(void*), void *child_stack, int flags, void *arg) = NULL;
+static void *hijack_handle = NULL;
+#endif
extern void _exit_with_stack_teardown(void * stackBase, int stackSize, int retCode);
extern void _exit_thread(int retCode);
extern int __set_errno(int);
@@ -307,6 +310,10 @@ int pthread_create(pthread_t *thread_out, pthread_attr_t const * attr,
@@ -307,6 +314,12 @@ int pthread_create(pthread_t *thread_out, pthread_attr_t const * attr,
int madestack = 0;
int old_errno = errno;

+#ifndef LIBC_STATIC
+ if (getenv("DMTCP_HIJACK_LIBS") &&
+ !hijack_handle) {
+ hijack_handle =dlopen("dmtcphijack.so", 0);
+ }
+#endif
/* this will inform the rest of the C library that at least one thread
* was created. this will enforce certain functions to acquire/release
* locks (e.g. atexit()) to protect shared global structures.
@@ -354,10 +361,15 @@ int pthread_create(pthread_t *thread_out, pthread_attr_t const * attr,
@@ -354,10 +367,22 @@ int pthread_create(pthread_t *thread_out, pthread_attr_t const * attr,

tls[TLS_SLOT_THREAD_ID] = thread;

- tid = __pthread_clone((int(*)(void*))start_routine, tls,
- CLONE_FILES | CLONE_FS | CLONE_VM | CLONE_SIGHAND
- | CLONE_THREAD | CLONE_SYSVSEM | CLONE_DETACHED,
- arg);
+#ifdef LIBC_STATIC
tid = __pthread_clone((int(*)(void*))start_routine, tls,
CLONE_FILES | CLONE_FS | CLONE_VM | CLONE_SIGHAND
| CLONE_THREAD | CLONE_SYSVSEM | CLONE_DETACHED,
arg);
+#else
+ int flags = CLONE_FILES | CLONE_FS | CLONE_VM | CLONE_SIGHAND |
+ CLONE_THREAD | CLONE_SYSVSEM | CLONE_DETACHED;
+ if (!__hijack__pthread_clone && hijack_handle)
Expand All @@ -67,31 +60,10 @@ index 3435d21..b80d26e 100644
+ } else {
+ tid = __pthread_clone((int(*)(void*))start_routine, tls, flags, arg);
+ }
+#endif

if(tid < 0) {
int result;
diff --git a/libdl/Android.mk b/libdl/Android.mk
index d2289f8..b74be7a 100644
--- a/libdl/Android.mk
+++ b/libdl/Android.mk
@@ -1,6 +1,17 @@
LOCAL_PATH:= $(call my-dir)

#
+# libdl.a
+#
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= libdl.c
+
+LOCAL_MODULE:= libdl
+
+include $(BUILD_STATIC_LIBRARY)
+
+#
# libdl
#

--
1.7.7.6

0 comments on commit 188d0a2

Please sign in to comment.