summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--byterun/signals.c36
-rw-r--r--byterun/startup.c13
2 files changed, 49 insertions, 0 deletions
diff --git a/byterun/signals.c b/byterun/signals.c
index 387d830b0..44caac100 100644
--- a/byterun/signals.c
+++ b/byterun/signals.c
@@ -99,6 +99,42 @@ void handle_signal(int signal_number)
}
}
+#ifdef _WIN32
+#include <windows.h>
+
+#define hexa_digit(ch) (ch >= 97 ? ch - 87 : \
+ (ch >= 65 ? ch - 55 : \
+ (ch >= 48 ? ch - 48 : 0)))
+
+DWORD WINAPI caml_signal_thread(LPVOID lpParam)
+{
+ char *data;
+ int i;
+ HANDLE h;
+ /* Get an hexa-code raw handle through the environment */
+ data = getenv("CAMLSIGPIPE");
+ for(i = 0; i < sizeof(HANDLE); i++)
+ ((char*)&h)[i] = (hexa_digit(data[2*i]) << 4) + hexa_digit(data[2*i+1]);
+ while (1) {
+ DWORD numread;
+ BOOL ret;
+ char iobuf[2];
+ /* This shall always return a single character */
+ ret = ReadFile(h, iobuf, 1, &numread, NULL);
+ if (!ret || numread != 1) sys_exit(Val_int(0));
+ switch (iobuf[0]) {
+ case 'C':
+ pending_signal = SIGINT;
+ something_to_do = 1;
+ break;
+ case 'T':
+ exit(0);
+ break;
+ }
+ }
+}
+#endif
+
void urge_major_slice (void)
{
force_major_slice = 1;
diff --git a/byterun/startup.c b/byterun/startup.c
index a2f5c201a..56d1d1f02 100644
--- a/byterun/startup.c
+++ b/byterun/startup.c
@@ -37,6 +37,7 @@
#include "misc.h"
#include "mlvalues.h"
#include "prims.h"
+#include "signals.h"
#include "stacks.h"
#include "sys.h"
@@ -238,6 +239,11 @@ static void parse_camlrunparam(void)
extern void init_ieee_floats (void);
+#ifdef _WIN32
+#include <windows.h>
+extern DWORD WINAPI caml_signal_thread(LPVOID lpParam);
+#endif
+
/* Main entry point when loading code from a file */
void caml_main(char **argv)
@@ -301,6 +307,13 @@ void caml_main(char **argv)
/* Initialize system libraries */
init_exceptions();
sys_init(argv + pos);
+#ifdef _WIN32
+ /* Startup a thread for signals */
+ if (getenv("CAMLSIGPIPE")) {
+ int lpThreadId;
+ CreateThread(NULL, 0, caml_signal_thread, NULL, 0, &lpThreadId);
+ }
+#endif
/* Execute the program */
debugger(PROGRAM_START);
res = interprete(start_code, trail.code_size);