Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build on musl libc systems #2916

Merged
merged 7 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/lib/globals_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@

#include <limits.h> /* for USHRT_MAX */
#ifdef UNIX
# include <sys/types.h> /* Fix for case 5341. */
# include <signal.h>
#endif
/* DR_API EXPORT VERBATIM */
#ifdef UNIX
# include <sys/types.h> /* for pid_t (non-glibc, e.g. musl) */
#endif
#ifdef WINDOWS
/* allow nameless struct/union */
# pragma warning(disable: 4201)
Expand Down
5 changes: 3 additions & 2 deletions core/unix/injector.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ typedef struct _dr_inject_info_t {
static bool
inject_ptrace(dr_inject_info_t *info, const char *library_path);

/* "enum __ptrace_request request" is used by glibc, but musl uses "int". */
static long
our_ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);
our_ptrace(int request, pid_t pid, void *addr, void *data);
#endif

/*******************************************************************************
Expand Down Expand Up @@ -889,7 +890,7 @@ static const enum_name_pair_t pt_req_map[] = {
* libc from the injector process should always work.
*/
static long
our_ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data)
our_ptrace(int request, pid_t pid, void *addr, void *data)
{
long r = dynamorio_syscall(SYS_ptrace, 4, request, pid, addr, data);
if (verbose &&
Expand Down
4 changes: 3 additions & 1 deletion core/unix/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ typedef FILE stdfile_t;
# define STDFILE_FILENO _file
#elif defined(LINUX)
typedef struct _IO_FILE stdfile_t;
# define STDFILE_FILENO _fileno
# ifdef __GLIBC__
# define STDFILE_FILENO _fileno
# endif
#endif
extern stdfile_t **privmod_stdout;
extern stdfile_t **privmod_stderr;
Expand Down
23 changes: 20 additions & 3 deletions core/unix/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -6168,6 +6168,23 @@ cleanup_after_vfork_execve(dcontext_t *dcontext)
HEAPACCT(ACCT_THREAD_MGT));
}

static void
set_stdfile_fileno(stdfile_t **stdfile, file_t file_no)
{
#ifdef STDFILE_FILENO
(*stdfile)->STDFILE_FILENO = file_no;
#else
# warning stdfile_t is opaque; DynamoRIO will not set fds of libc FILEs.
/* i#1973: musl libc support (and potentially other non-glibcs) */
/* only called by handle_close_pre(), so warning is specific to that. */
SYSLOG_INTERNAL_WARNING_ONCE(
"DynamoRIO cannot set the file descriptors of private libc FILEs on "
"this platform. Client usage of stdio.h stdin, stdout, or stderr may "
"no longer work as expected, because the app is closing the UNIX fds "
"backing these.");
#endif
}

/* returns whether to execute syscall */
static bool
handle_close_pre(dcontext_t *dcontext)
Expand Down Expand Up @@ -6204,7 +6221,7 @@ handle_close_pre(dcontext_t *dcontext)
if (privmod_stdout != NULL &&
IF_CLIENT_INTERFACE_ELSE(INTERNAL_OPTION(private_loader), false)) {
/* update the privately loaded libc's stdout _fileno. */
(*privmod_stdout)->STDFILE_FILENO = our_stdout;
set_stdfile_fileno(privmod_stdout, our_stdout);
}
}
if (DYNAMO_OPTION(dup_stderr_on_close) && fd == STDERR) {
Expand All @@ -6220,7 +6237,7 @@ handle_close_pre(dcontext_t *dcontext)
if (privmod_stderr != NULL &&
IF_CLIENT_INTERFACE_ELSE(INTERNAL_OPTION(private_loader), false)) {
/* update the privately loaded libc's stderr _fileno. */
(*privmod_stderr)->STDFILE_FILENO = our_stderr;
set_stdfile_fileno(privmod_stderr, our_stderr);
}
}
if (DYNAMO_OPTION(dup_stdin_on_close) && fd == STDIN) {
Expand All @@ -6236,7 +6253,7 @@ handle_close_pre(dcontext_t *dcontext)
if (privmod_stdin != NULL &&
IF_CLIENT_INTERFACE_ELSE(INTERNAL_OPTION(private_loader), false)) {
/* update the privately loaded libc's stdout _fileno. */
(*privmod_stdin)->STDFILE_FILENO = our_stdin;
set_stdfile_fileno(privmod_stdin, our_stdin);
}
}
return true;
Expand Down
4 changes: 3 additions & 1 deletion core/unix/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@
# include <errno.h>
#endif

#ifdef MACOS
/* Define the Linux names, which the code is already using */
#ifndef SA_NOMASK
# define SA_NOMASK SA_NODEFER
#endif
#ifndef SA_ONESHOT
# define SA_ONESHOT SA_RESETHAND
#endif

Expand Down
2 changes: 1 addition & 1 deletion core/unix/signal_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ notify_signalfd(dcontext_t *dcontext, thread_sig_info_t *info, int sig,
#ifdef ANDROID
towrite.ssi_tid = frame->info._sifields._timer._tid;
#else
towrite.ssi_tid = frame->info._sifields._timer.si_tid;
towrite.ssi_tid = frame->info.si_timerid;
#endif
towrite.ssi_overrun = frame->info.si_overrun;
towrite.ssi_status = frame->info.si_status;
Expand Down
5 changes: 4 additions & 1 deletion core/unix/signal_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,11 @@ libc_sigismember(const sigset_t *set, int _sig)
/* sigset_t is just a uint32 */
return TEST(1UL << sig, *set);
#else
/* "set->__val" would be cleaner, but is glibc specific (e.g. musl libc
* uses __bits as the field name on sigset_t).
*/
uint bits_per = 8*sizeof(ulong);
return TEST(1UL << (sig % bits_per), set->__val[sig / bits_per]);
return TEST(1UL << (sig % bits_per), ((const ulong *)set)[sig / bits_per]);
#endif
}

Expand Down