|
From: Tom H. <th...@cy...> - 2004-11-24 23:53:04
|
CVS commit by thughes:
Yet another attempt to make the pthre cancellation wrappers work.
The exact search order followed by RTLD_NEXT and RTLD_DEFAULT seems to be
very variable across different glibc releases, especially when the pthread
library is pulled in implicitly by a dependency in another library.
As a result I have now given up on that scheme and have resorted to the
simple tactic of explicitly opening libc.so and then looking for the
function to forward to through that handle.
MERGE TO STABLE
M +58 -45 vg_libpthread.c 1.161.2.3
--- valgrind/coregrind/vg_libpthread.c #1.161.2.2:1.161.2.3
@@ -2243,17 +2243,34 @@ void ** (*__libc_internal_tsd_address)
------------------------------------------------------------------ */
-static void *libpthread_handle;
+static void *get_libc_handle(void)
+{
+ static void *libc_handle = NULL;
-#define FORWARD(name, altname, args...) \
+ if (libc_handle == NULL) {
+ libc_handle = dlopen("libc.so.6", RTLD_LAZY);
+ my_assert(libc_handle != NULL);
+ }
+
+ return libc_handle;
+}
+
+static void *get_libpthread_handle(void)
+{
+ static void *libpthread_handle = NULL;
+
+ if (libpthread_handle == NULL) {
+ libpthread_handle = dlopen("libpthread.so.0", RTLD_LAZY);
+ my_assert(libpthread_handle != NULL);
+ }
+
+ return libpthread_handle;
+}
+
+#define FORWARD(name, args...) \
({ \
static name##_t name##_ptr = NULL; \
- if (libpthread_handle == NULL) { \
- libpthread_handle = dlopen("libpthread.so.0", RTLD_LAZY); \
- my_assert(libpthread_handle != NULL); \
- } \
if (name##_ptr == NULL) { \
- if ((name##_ptr = (name##_t)dlsym(RTLD_NEXT, #name)) == NULL) \
- name##_ptr = (name##_t)dlsym(RTLD_DEFAULT, #altname); \
- my_assert(name##_ptr != NULL && name##_ptr != dlsym(libpthread_handle, #name)); \
+ name##_ptr = (name##_t)dlsym(get_libc_handle(), #name); \
+ my_assert(name##_ptr != NULL && name##_ptr != dlsym(get_libpthread_handle(), #name)); \
} \
name##_ptr(args); \
@@ -2270,9 +2287,5 @@ int sigaction(int signum,
{
__my_pthread_testcancel();
-#ifdef GLIBC_2_1
- return FORWARD(sigaction, __sigaction, signum, act, oldact);
-#else
- return FORWARD(sigaction, __libc_sigaction, signum, act, oldact);
-#endif
+ return FORWARD(sigaction, signum, act, oldact);
}
@@ -2284,5 +2297,5 @@ int accept(int fd, struct sockaddr *addr
{
__my_pthread_testcancel();
- return FORWARD(accept, __libc_accept, fd, addr, len);
+ return FORWARD(accept, fd, addr, len);
}
@@ -2297,5 +2310,5 @@ int connect(int sockfd,
{
__my_pthread_testcancel();
- return FORWARD(connect, __libc_connect, sockfd, serv_addr, addrlen);
+ return FORWARD(connect, sockfd, serv_addr, addrlen);
}
@@ -2307,5 +2320,5 @@ int fcntl(int fd, int cmd, long arg)
{
__my_pthread_testcancel();
- return FORWARD(fcntl, __libc_fcntl, fd, cmd, arg);
+ return FORWARD(fcntl, fd, cmd, arg);
}
@@ -2317,5 +2330,5 @@ ssize_t write(int fd, const void *buf, s
{
__my_pthread_testcancel();
- return FORWARD(write, __libc_write, fd, buf, count);
+ return FORWARD(write, fd, buf, count);
}
@@ -2327,5 +2340,5 @@ ssize_t read(int fd, void *buf, size_t c
{
__my_pthread_testcancel();
- return FORWARD(read, __libc_read, fd, buf, count);
+ return FORWARD(read, fd, buf, count);
}
@@ -2335,5 +2348,5 @@ int (*open64_t)(const char *pathname, in
int open64(const char *pathname, int flags, mode_t mode)
{
- return FORWARD(open64, __libc_open64, pathname, flags, mode);
+ return FORWARD(open64, pathname, flags, mode);
}
@@ -2343,5 +2356,5 @@ int (*open_t)(const char *pathname, int
int open(const char *pathname, int flags, mode_t mode)
{
- return FORWARD(open, __libc_open, pathname, flags, mode);
+ return FORWARD(open, pathname, flags, mode);
}
@@ -2352,5 +2365,5 @@ int close(int fd)
{
__my_pthread_testcancel();
- return FORWARD(close, __libc_close, fd);
+ return FORWARD(close, fd);
}
@@ -2362,5 +2375,5 @@ pid_t waitpid(pid_t pid, int *status, in
{
__my_pthread_testcancel();
- return FORWARD(waitpid, __libc_waitpid, pid, status, options);
+ return FORWARD(waitpid, pid, status, options);
}
@@ -2372,5 +2385,5 @@ int __nanosleep(const struct timespec *r
{
__my_pthread_testcancel();
- return FORWARD(__nanosleep, __libc_nanosleep, req, rem);
+ return FORWARD(__nanosleep, req, rem);
}
@@ -2381,5 +2394,5 @@ int pause(void)
{
__my_pthread_testcancel();
- return FORWARD(pause, __libc_pause);
+ return FORWARD(pause);
}
@@ -2391,5 +2404,5 @@ int __tcdrain(int fd)
{
__my_pthread_testcancel();
- return FORWARD(__tcdrain, __libc_tcdrain, fd);
+ return FORWARD(__tcdrain, fd);
}
@@ -2401,5 +2414,5 @@ int fsync(int fd)
{
__my_pthread_testcancel();
- return FORWARD(fsync, __libc_fsync, fd);
+ return FORWARD(fsync, fd);
}
@@ -2411,5 +2424,5 @@ off_t lseek(int fildes, off_t offset, in
{
__my_pthread_testcancel();
- return FORWARD(lseek, __libc_lseek, fildes, offset, whence);
+ return FORWARD(lseek, fildes, offset, whence);
}
@@ -2421,5 +2434,5 @@ __off64_t lseek64(int fildes, __off64_t
{
__my_pthread_testcancel();
- return FORWARD(lseek64, __libc_lseek64, fildes, offset, whence);
+ return FORWARD(lseek64, fildes, offset, whence);
}
@@ -2432,5 +2445,5 @@ ssize_t __pread64 (int __fd, void *__buf
{
__my_pthread_testcancel();
- return FORWARD(__pread64, __libc_pread64, __fd, __buf, __nbytes, __offset);
+ return FORWARD(__pread64, __fd, __buf, __nbytes, __offset);
}
@@ -2443,5 +2456,5 @@ ssize_t __pwrite64 (int __fd, const void
{
__my_pthread_testcancel();
- return FORWARD(__pwrite64, __libc_pwrite64, __fd, __buf, __nbytes, __offset);
+ return FORWARD(__pwrite64, __fd, __buf, __nbytes, __offset);
}
@@ -2453,5 +2466,5 @@ ssize_t pwrite(int fd, const void *buf,
{
__my_pthread_testcancel();
- return FORWARD(pwrite, __libc_pwrite, fd, buf, count, offset);
+ return FORWARD(pwrite, fd, buf, count, offset);
}
@@ -2463,5 +2476,5 @@ ssize_t pread(int fd, void *buf, size_t
{
__my_pthread_testcancel();
- return FORWARD(pread, __libc_pread, fd, buf, count, offset);
+ return FORWARD(pread, fd, buf, count, offset);
}
@@ -2472,5 +2485,5 @@ int recv(int s, void *msg, size_t len, i
{
__my_pthread_testcancel();
- return FORWARD(recv, __libc_recv, s, msg, len, flags);
+ return FORWARD(recv, s, msg, len, flags);
}
@@ -2481,5 +2494,5 @@ int send(int s, const void *msg, size_t
{
__my_pthread_testcancel();
- return FORWARD(send, __libc_send, s, msg, len, flags);
+ return FORWARD(send, s, msg, len, flags);
}
@@ -2491,5 +2504,5 @@ int sendmsg(int s, const struct msghdr *
{
__my_pthread_testcancel();
- return FORWARD(sendmsg, __libc_sendmsg, s, msg, flags);
+ return FORWARD(sendmsg, s, msg, flags);
}
@@ -2501,5 +2514,5 @@ int recvmsg(int s, struct msghdr *msg, i
{
__my_pthread_testcancel();
- return FORWARD(recvmsg, __libc_recvmsg, s, msg, flags);
+ return FORWARD(recvmsg, s, msg, flags);
}
@@ -2513,5 +2526,5 @@ int recvfrom(int s, void *buf, size_t le
{
__my_pthread_testcancel();
- return FORWARD(recvfrom, __libc_recfrom, s, buf, len, flags, from, fromlen);
+ return FORWARD(recvfrom, s, buf, len, flags, from, fromlen);
}
@@ -2525,5 +2538,5 @@ int sendto(int s, const void *msg, size_
{
__my_pthread_testcancel();
- return FORWARD(sendto, __libc_sendto, s, msg, len, flags, to, tolen);
+ return FORWARD(sendto, s, msg, len, flags, to, tolen);
}
@@ -2535,5 +2548,5 @@ int system(const char* str)
{
__my_pthread_testcancel();
- return FORWARD(system, __libc_system, str);
+ return FORWARD(system, str);
}
@@ -2545,5 +2558,5 @@ pid_t wait(int *status)
{
__my_pthread_testcancel();
- return FORWARD(wait, __libc_wait, status);
+ return FORWARD(wait, status);
}
@@ -2555,5 +2568,5 @@ int msync(const void *start, size_t leng
{
__my_pthread_testcancel();
- return FORWARD(msync, __libc_msync, start, length, flags);
+ return FORWARD(msync, start, length, flags);
}
@@ -2581,5 +2594,5 @@ void (*longjmp_t)(jmp_buf env, int val)
void longjmp(jmp_buf env, int val)
{
- FORWARD(longjmp, __libc_longjmp, env, val);
+ FORWARD(longjmp, env, val);
}
@@ -2590,5 +2603,5 @@ void siglongjmp(sigjmp_buf env, int val)
{
kludged("siglongjmp", "(it ignores cleanup handlers)");
- FORWARD(siglongjmp, __libc_siglongjmp, env, val);
+ FORWARD(siglongjmp, env, val);
}
@@ -2652,5 +2665,5 @@ pid_t __fork(void)
run_fork_handlers(0 /* prepare */);
- pid = FORWARD(__fork, __libc_fork);
+ pid = FORWARD(__fork);
if (pid == 0) {
/* I am the child */
|