Skip to content

Commit

Permalink
i#58 MacOS: use the _nocancel versions of all system calls that DR ma…
Browse files Browse the repository at this point in the history
…kes in

order to defer app-initiated thread termination.

SVN-Revision: 2482
  • Loading branch information
derekbruening committed Jan 13, 2014
1 parent 1a6d6eb commit 1215489
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions core/unix/injector.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ gen_print(void *dc, instrlist_t *ilist, const char *msg)
args[1] = OPND_CREATE_MEMPTR(DR_REG_XSP, 0); /* msg is on TOS. */
args[2] = OPND_CREATE_INTPTR(strlen(msg));
gen_push_string(dc, ilist, msg);
gen_syscall(dc, ilist, SYS_write, 3, args);
gen_syscall(dc, ilist, SYSNUM_NO_CANCEL(SYS_write), 3, args);
}
#endif

Expand Down Expand Up @@ -1015,7 +1015,7 @@ injectee_open(dr_inject_info_t *info, const char *path, int flags, mode_t mode)
args[num_args++] = OPND_CREATE_INTPTR(flags);
args[num_args++] = OPND_CREATE_INTPTR(mode);
ASSERT(num_args <= MAX_SYSCALL_ARGS);
gen_syscall(dc, ilist, SYS_open, num_args, args);
gen_syscall(dc, ilist, SYSNUM_NO_CANCEL(SYS_open), num_args, args);
return injectee_run_get_retval(info, dc, ilist);
}

Expand Down
13 changes: 7 additions & 6 deletions core/unix/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,8 @@ os_thread_sleep(uint64 milliseconds)
semaphore_create(mach_task_self(), &sem, SYNC_POLICY_FIFO, 0);
ASSERT(res == KERN_SUCCESS);
}
res = dynamorio_syscall(SYS___semwait_signal, 6, sem, MACH_PORT_NULL, 1, 1,
res = dynamorio_syscall(SYSNUM_NO_CANCEL(SYS___semwait_signal),
6, sem, MACH_PORT_NULL, 1, 1,
(int64_t)req.tv_sec, (int32_t)req.tv_nsec);
if (res == -EINTR) {
/* FIXME i#58: figure out how much time elapsed and re-wait */
Expand Down Expand Up @@ -3106,13 +3107,13 @@ int
open_syscall(const char *file, int flags, int mode)
{
ASSERT(file != NULL);
return dynamorio_syscall(SYS_open, 3, file, flags, mode);
return dynamorio_syscall(SYSNUM_NO_CANCEL(SYS_open), 3, file, flags, mode);
}

int
close_syscall(int fd)
{
return dynamorio_syscall(SYS_close, 1, fd);
return dynamorio_syscall(SYSNUM_NO_CANCEL(SYS_close), 1, fd);
}

int
Expand All @@ -3124,20 +3125,20 @@ dup_syscall(int fd)
ssize_t
read_syscall(int fd, void *buf, size_t nbytes)
{
return dynamorio_syscall(SYS_read, 3, fd, buf, nbytes);
return dynamorio_syscall(SYSNUM_NO_CANCEL(SYS_read), 3, fd, buf, nbytes);
}

ssize_t
write_syscall(int fd, const void *buf, size_t nbytes)
{
return dynamorio_syscall(SYS_write, 3, fd, buf, nbytes);
return dynamorio_syscall(SYSNUM_NO_CANCEL(SYS_write), 3, fd, buf, nbytes);
}

#ifndef NOT_DYNAMORIO_CORE_PROPER
static int
fcntl_syscall(int fd, int cmd, long arg)
{
return dynamorio_syscall(SYS_fcntl, 3, fd, cmd, arg);
return dynamorio_syscall(SYSNUM_NO_CANCEL(SYS_fcntl), 3, fd, cmd, arg);
}
#endif /* !NOT_DYNAMORIO_CORE_PROPER */

Expand Down
9 changes: 8 additions & 1 deletion core/unix/os_private.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2011-2013 Google, Inc. All rights reserved.
* Copyright (c) 2011-2014 Google, Inc. All rights reserved.
* Copyright (c) 2008-2010 VMware, Inc. All rights reserved.
* **********************************************************/

Expand Down Expand Up @@ -85,6 +85,13 @@
CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS| \
CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID)

/* On Mac, we use the _nocancel variant to defer app-initiated thread termination */
#ifdef MACOS
# define SYSNUM_NO_CANCEL(num) num##_nocancel
#else
# define SYSNUM_NO_CANCEL(num) num
#endif

/* Maximum number of arguments to Linux syscalls. */
enum { MAX_SYSCALL_ARGS = 6 };

Expand Down
2 changes: 1 addition & 1 deletion core/unix/stackdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
pid_t
wait_syscall(int *status)
{
return dynamorio_syscall(SYS_wait4, 4, WAIT_ANY, status, 0, NULL);
return dynamorio_syscall(SYSNUM_NO_CANCEL(SYS_wait4), 4, WAIT_ANY, status, 0, NULL);
}

static int
Expand Down
10 changes: 8 additions & 2 deletions suite/tests/tools.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2013 Google, Inc. All rights reserved.
* Copyright (c) 2013-2014 Google, Inc. All rights reserved.
* Copyright (c) 2005-2010 VMware, Inc. All rights reserved.
* **********************************************************/

Expand Down Expand Up @@ -449,7 +449,13 @@ nolibc_strlen(const char *str)
void
nolibc_print(const char *str)
{
nolibc_syscall(SYS_write, 3, stderr->_fileno, str, nolibc_strlen(str));
nolibc_syscall(
#ifdef MACOS
SYS_write_nocancel,
#else
SYS_write,
#endif
3, stderr->_fileno, str, nolibc_strlen(str));
}

/* Safe print int syscall.
Expand Down

0 comments on commit 1215489

Please sign in to comment.