Page MenuHomePhabricator

naive_attempt.patch

Authored By
bzimport
Nov 22 2014, 3:36 AM
Size
2 KB
Referenced Files
None
Subscribers
None

naive_attempt.patch

diff --git c/luasandbox_timer.h w/luasandbox_timer.h
index 04b30cbe57..105bf689c2 100644
--- c/luasandbox_timer.h
+++ w/luasandbox_timer.h
@@ -5,8 +5,8 @@
#ifdef CLOCK_REALTIME
-#ifdef CLOCK_PROCESS_CPUTIME_ID
-#define LUASANDBOX_CLOCK_ID CLOCK_PROCESS_CPUTIME_ID
+#ifdef CLOCK_THREAD_CPUTIME_ID
+#define LUASANDBOX_CLOCK_ID CLOCK_THREAD_CPUTIME_ID
#else
#define LUASANDBOX_CLOCK_ID CLOCK_REALTIME
#endif
diff --git c/timer.c w/timer.c
index 063d140366..5a3edd1b14 100644
--- c/timer.c
+++ w/timer.c
@@ -6,6 +6,9 @@
#include <signal.h>
#include <time.h>
#include <semaphore.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <unistd.h>
#include <lua.h>
#include <lauxlib.h>
@@ -112,7 +115,7 @@ void luasandbox_timer_install_handler(struct sigaction * oldact)
struct sigaction newact;
newact.sa_sigaction = luasandbox_timer_handle_signal;
newact.sa_flags = SA_SIGINFO;
- sigprocmask(SIG_BLOCK, NULL, &newact.sa_mask);
+ pthread_sigmask(SIG_BLOCK, NULL, &newact.sa_mask);
sigaction(LUASANDBOX_SIGNAL, &newact, oldact);
}
@@ -140,7 +143,7 @@ static void luasandbox_timer_handle_signal(int signo, siginfo_t * info, void * c
if (data->type == LUASANDBOX_TIMER_EMERGENCY) {
sigset_t set;
sigemptyset(&set);
- sigprocmask(SIG_SETMASK, &set, NULL);
+ pthread_sigmask(SIG_SETMASK, &set, NULL);
data->sandbox->timed_out = 1;
data->sandbox->emergency_timed_out = 1;
if (data->sandbox->in_php) {
@@ -461,8 +464,13 @@ static void luasandbox_timer_create_one(luasandbox_timer * lt, php_luasandbox_ob
ev.sigev_notify = SIGEV_THREAD;
ev.sigev_notify_function = luasandbox_timer_handle_profiler;
} else {
- ev.sigev_notify = SIGEV_SIGNAL;
- ev.sigev_signo = LUASANDBOX_SIGNAL;
+#ifdef HHVM
+ ev.sigev_notify = SIGEV_THREAD_ID;
+ ev._sigev_un._tid = syscall(SYS_gettid);
+#else
+ ev.sigev_notify = SIGEV_SIGNAL;
+ ev.sigev_signo = LUASANDBOX_SIGNAL;
+#endif
}
lt->cbdata.type = type;
lt->cbdata.sandbox = sandbox;
@@ -553,7 +561,7 @@ static void luasandbox_timer_stop_one(luasandbox_timer * lt, struct timespec * r
siginfo_t info;
sigemptyset(&sigset);
sigaddset(&sigset, LUASANDBOX_SIGNAL);
- sigprocmask(SIG_BLOCK, &sigset, &oldset);
+ pthread_sigmask(SIG_BLOCK, &sigset, &oldset);
timer_delete(lt->timer);
while (1) {
sigpending(&pendset);
@@ -563,7 +571,7 @@ static void luasandbox_timer_stop_one(luasandbox_timer * lt, struct timespec * r
sigwaitinfo(&sigset, &info);
luasandbox_timer_handle_signal(LUASANDBOX_SIGNAL, &info, NULL);
}
- sigprocmask(SIG_SETMASK, &oldset, NULL);
+ pthread_sigmask(SIG_SETMASK, &oldset, NULL);
}
}

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
13863
Default Alt Text
naive_attempt.patch (2 KB)

Event Timeline