syscall symbol loading fixes, makefile SDK_DEBUG tweak

This commit is contained in:
Joseph Henry
2016-06-29 11:57:05 -07:00
parent b52551ea4a
commit 3c3ef79c6e
7 changed files with 67 additions and 26 deletions

View File

@@ -43,28 +43,28 @@ void zt_init_rpc(char *path, char *nwid);
extern char *api_netpath;
#if defined(__linux__)
static int (*realaccept4)(ACCEPT4_SIG) = 0;
extern int (*realaccept4)(ACCEPT4_SIG);
#if !defined(__ANDROID__)
static int (*realsyscall)(SYSCALL_SIG) = 0;
extern int (*realsyscall)(SYSCALL_SIG);
#endif
#endif
#if !defined(__ANDROID__)
bool check_intercept_enabled_for_thread();
static int (*realbind)(BIND_SIG) = 0;
static int (*realsendmsg)(SENDMSG_SIG) = 0;
static ssize_t (*realsendto)(SENDTO_SIG) = 0;
static int (*realrecvmsg)(RECVMSG_SIG) = 0;
static int (*realrecvfrom)(RECVFROM_SIG) = 0;
extern int (*realbind)(BIND_SIG);
extern int (*realsendmsg)(SENDMSG_SIG);
extern ssize_t (*realsendto)(SENDTO_SIG);
extern int (*realrecvmsg)(RECVMSG_SIG);
extern int (*realrecvfrom)(RECVFROM_SIG);
#endif
static int (*realconnect)(CONNECT_SIG) = 0;
static int (*realaccept)(ACCEPT_SIG) = 0;
static int (*reallisten)(LISTEN_SIG) = 0;
static int (*realsocket)(SOCKET_SIG) = 0;
static int (*realsetsockopt)(SETSOCKOPT_SIG) = 0;
static int (*realgetsockopt)(GETSOCKOPT_SIG) = 0;
static int (*realclose)(CLOSE_SIG) = 0;
static int (*realgetsockname)(GETSOCKNAME_SIG) = 0;
extern int (*realconnect)(CONNECT_SIG);
extern int (*realaccept)(ACCEPT_SIG);
extern int (*reallisten)(LISTEN_SIG);
extern int (*realsocket)(SOCKET_SIG);
extern int (*realsetsockopt)(SETSOCKOPT_SIG);
extern int (*realgetsockopt)(GETSOCKOPT_SIG);
extern int (*realclose)(CLOSE_SIG);
extern int (*realgetsockname)(GETSOCKNAME_SIG);
ssize_t zt_sendto(SENDTO_SIG);
ssize_t zt_sendmsg(SENDMSG_SIG);

View File

@@ -63,6 +63,30 @@ void dwr(int level, const char *fmt, ... );
pthread_key_t thr_id_key;
char *api_netpath;
// externs common between SDK_Intercept and SDK_Socket from SDK.h
#if defined(__linux__)
int (*realaccept4)(ACCEPT4_SIG) = 0;
#if !defined(__ANDROID__)
int (*realsyscall)(SYSCALL_SIG) = 0;
#endif
#endif
#if !defined(__ANDROID__)
int (*realbind)(BIND_SIG) = 0;
int (*realsendmsg)(SENDMSG_SIG) = 0;
ssize_t (*realsendto)(SENDTO_SIG) = 0;
int (*realrecvmsg)(RECVMSG_SIG) = 0;
int (*realrecvfrom)(RECVFROM_SIG) = 0;
#endif
int (*realconnect)(CONNECT_SIG) = 0;
int (*realaccept)(ACCEPT_SIG) = 0;
int (*reallisten)(LISTEN_SIG) = 0;
int (*realsocket)(SOCKET_SIG) = 0;
int (*realsetsockopt)(SETSOCKOPT_SIG) = 0;
int (*realgetsockopt)(GETSOCKOPT_SIG) = 0;
int (*realclose)(CLOSE_SIG);
int (*realgetsockname)(GETSOCKNAME_SIG) = 0;
// ------------------------------------------------------------------------------
// --------------------- Get Original socket API pointers -----------------------
// ------------------------------------------------------------------------------
@@ -503,8 +527,10 @@ char *api_netpath;
int close(CLOSE_SIG) {
dwr(MSG_DEBUG, " close(%d)\n", fd);
check_intercept_enabled_for_thread();
return realclose(fd);
if(!check_intercept_enabled_for_thread()) {
return realclose(fd);
}
zt_close(fd);
}
// ------------------------------------------------------------------------------

View File

@@ -47,6 +47,10 @@
#include "SDK.h"
#include "SDK_RPC.h"
// externs common between SDK_Intercept and SDK_Socket from SDK.h
int (*realsocket)(SOCKET_SIG);
int (*realconnect)(CONNECT_SIG);
#ifdef __cplusplus
extern "C" {
#endif

View File

@@ -74,16 +74,21 @@
void print_addr(struct sockaddr *addr);
void dwr(int level, const char *fmt, ... );
char *api_netpath = (char *)0;
// ------------------------------------------------------------------------------
// ---------------------------------- zt_init_rpc -------------------------------
// ------------------------------------------------------------------------------
// Assembles (and/or) sets the RPC path for communication with the ZeroTier service
void zt_init_rpc(char *path, char *nwid)
{
dwr(MSG_DEBUG, "zt_init_rpc\n");
// Just double check we have
if(!realconnect) {
load_symbols();
}
if(!api_netpath) {
#if defined(SDK_BUNDLED)
// Get the path/nwid from the user application
@@ -373,9 +378,9 @@ char *api_netpath = (char *)0;
struct connect_st rpc_st;
#if defined(__linux__)
#if !defined(__ANDROID__)
rpc_st.__tid = syscall(SYS_gettid);
//rpc_st.__tid = syscall(SYS_gettid);
#else
rpc_st.__tid = gettid(); // dummy value
//rpc_st.__tid = gettid(); // dummy value
#endif
#endif
rpc_st.__fd = __fd;
@@ -482,8 +487,9 @@ char *api_netpath = (char *)0;
// int fd
int zt_close(CLOSE_SIG) {
dwr(MSG_DEBUG, "zt_close(%d)", fd);
return close(fd);
get_api_netpath();
dwr(MSG_DEBUG, "zt_close(%d)\n", fd);
return realclose(fd);
}
// ------------------------------------------------------------------------------