Skip to content

Commit

Permalink
Support for musl libc
Browse files Browse the repository at this point in the history
Closes: #141
  • Loading branch information
oxr463 committed Nov 29, 2018
2 parents f0867ed + e9fbcfb commit 5bb196e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
10 changes: 9 additions & 1 deletion src/cli/cli.c
Expand Up @@ -30,9 +30,13 @@
#include <sys/types.h> /* getpid(2), */
#include <unistd.h> /* getpid(2), */
#include <errno.h> /* errno(3), */
#include <execinfo.h> /* backtrace_symbols(3), */
#include <limits.h> /* INT_MAX, */

/* execinfo.h is GNU extension, disable it not using glibc */
#if defined(__GLIBC__)
#include <execinfo.h> /* backtrace_symbols(3), */
#endif

#include "cli/cli.h"
#include "cli/note.h"
#include "extension/care/extract.h"
Expand Down Expand Up @@ -550,6 +554,9 @@ const char *expand_front_variable(TALLOC_CTX *context, const char *string)
* with CFLAGS='-finstrument-functions -O0 -g' and LDFLAGS='-rdynamic'
* to enable this mechanism. */

/* since we rely on GLIBC extensions, disable all of this code if
* __GLIBC__ is not defined */
#if defined(__GLIBC__)
static int indent_level = 0;

void __cyg_profile_func_enter(void *this_function, void *call_site) DONT_INSTRUMENT;
Expand Down Expand Up @@ -578,3 +585,4 @@ void __cyg_profile_func_exit(void *this_function UNUSED, void *call_site UNUSED)
if (indent_level > 0)
indent_level--;
}
#endif
8 changes: 4 additions & 4 deletions src/extension/portmap/portmap.c
Expand Up @@ -4,11 +4,11 @@

#include <stdint.h> /* intptr_t, */
#include <stdlib.h> /* strtoul(3), */
#include <string.h> /* memset */
#include <sys/un.h> /* strncpy */
#include <sys/socket.h> /* AF_UNIX, AF_INET */
#include <arpa/inet.h> /* inet_ntop */
#include <linux/net.h> /* SYS_*, */

#include "cli/note.h"
#include "extension/extension.h"
#include "tracee/mem.h" /* read_data */
Expand Down Expand Up @@ -107,7 +107,7 @@ int prepare_getsockname_chained_syscall(Tracee *tracee, Config *config, word_t s
if(size_addr == 0)
return -EFAULT;

bzero(&sockaddr, sizeof(sockaddr));
memset(&sockaddr, '\0', sizeof(sockaddr));

/* we write the modified socket in this new address */
status = write_data(tracee, sock_addr, &sockaddr, sizeof(sockaddr));
Expand Down Expand Up @@ -170,7 +170,7 @@ int translate_port(Tracee *tracee, Config *config, word_t sockfd, word_t *sock_a
return 0;

/* Essential step, we clean the structure before adding data to it */
bzero(&sockaddr, sizeof(sockaddr));
memset(&sockaddr, '\0', sizeof(sockaddr));

/* Next, we read the socket address structure from the tracee's memory */
status = read_data(tracee, &sockaddr, *sock_addr, size);
Expand Down Expand Up @@ -363,7 +363,7 @@ int add_changed_port_as_entry(Tracee *tracee, Config *config, word_t sockfd, wor
return -result;

/* Essential step, we clean the structure before adding data to it */
bzero(&sockaddr, sizeof(sockaddr));
memset(&sockaddr, '\0', sizeof(sockaddr));

/* Next, we read the socket address structure from the tracee's memory */
status = read_data(tracee, &sockaddr, sock_addr, sizeof(sockaddr));
Expand Down
2 changes: 1 addition & 1 deletion src/ptrace/ptrace.c
Expand Up @@ -58,7 +58,7 @@
#define user_fpregs_struct user_fpsimd_struct
#endif

static const char *stringify_ptrace(enum __ptrace_request request)
static const char *stringify_ptrace(PTRACE_REQUEST_TYPE request)
{
#define CASE_STR(a) case a: return #a; break;
switch ((int) request) {
Expand Down
2 changes: 1 addition & 1 deletion src/syscall/enter.c
Expand Up @@ -26,7 +26,7 @@
#include <linux/net.h> /* SYS_*, */
#include <fcntl.h> /* AT_FDCWD, */
#include <limits.h> /* PATH_MAX, */

#include <string.h> /* strcpy */
#include "syscall/syscall.h"
#include "syscall/sysnum.h"
#include "syscall/socket.h"
Expand Down
4 changes: 4 additions & 0 deletions src/tracee/tracee.c
Expand Up @@ -45,6 +45,10 @@

#include "compat.h"

#ifndef __W_STOPCODE
#define __W_STOPCODE(sig) ((sig) <<8 | 0x7f)
#endif

typedef LIST_HEAD(tracees, tracee) Tracees;
static Tracees tracees;

Expand Down
10 changes: 8 additions & 2 deletions src/tracee/tracee.h
Expand Up @@ -30,10 +30,16 @@
#include <sys/ptrace.h>/* enum __ptrace_request */
#include <talloc.h> /* talloc_*, */
#include <stdint.h> /* *int*_t, */

#include <sys/wait.h> /* __WAIT_* */
#include "arch.h" /* word_t, user_regs_struct, */
#include "compat.h"

#if defined(__GLIBC__)
#define PTRACE_REQUEST_TYPE enum __ptrace_request
#else
#define PTRACE_REQUEST_TYPE int
#endif

typedef enum {
CURRENT = 0,
ORIGINAL = 1,
Expand Down Expand Up @@ -147,7 +153,7 @@ typedef struct tracee {
&& get_sysnum((tracee), ORIGINAL) == sysnum)

/* How this tracee is restarted. */
enum __ptrace_request restart_how;
PTRACE_REQUEST_TYPE restart_how;

/* Value of the tracee's general purpose registers. */
struct user_regs_struct _regs[NB_REG_VERSION];
Expand Down

0 comments on commit 5bb196e

Please sign in to comment.