Permalink
Browse files

windows: don't blow up when an invalid FD is used

  • Loading branch information...
1 parent b877db9 commit 39ca621987e1d1542cec76b8785aa15ea26e225d @piscisaureus piscisaureus committed Sep 22, 2012
Showing with 13 additions and 1 deletion.
  1. +13 −1 src/win/core.c
View
@@ -24,6 +24,7 @@
#include <limits.h>
#include <malloc.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "uv.h"
@@ -40,10 +41,21 @@ static uv_once_t uv_init_guard_ = UV_ONCE_INIT;
static uv_once_t uv_default_loop_init_guard_ = UV_ONCE_INIT;
+static void uv__crt_invalid_parameter_handler(const wchar_t* expression,
+ const wchar_t* function, const wchar_t * file, unsigned int line,
+ uintptr_t reserved) {
+ /* No-op. */
+}
+
+
static void uv_init(void) {
/* Tell Windows that we will handle critical errors. */
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
- SEM_NOOPENFILEERRORBOX);
+ SEM_NOOPENFILEERRORBOX);
+
+ /* Tell the CRT to not exit the application when an invalid parameter is */
+ /* passed. The main issue is that invalid FDs will trigger this behavior. */
+ _set_invalid_parameter_handler(uv__crt_invalid_parameter_handler);
/* Fetch winapi function pointers. This must be done first because other */
/* intialization code might need these function pointers to be loaded. */

2 comments on commit 39ca621

Contributor

saghul replied Oct 10, 2012

This fails to compile on MinGW when doing make test:

$ make test
gcc -Iinclude -Iinclude/uv-private -Iinclude -Iinclude/uv-private -g --std=gnu89
 -D_WIN32_WINNT=0x0600 -Isrc/ares/config_win32 -D_GNU_SOURCE  -o test/run-tests
test/run-tests.c \
                test/runner.c test/runner-win.c test/blackhole-server.c test/ech
o-server.c test/test-*.c uv.a -lws2_32 -lpsapi -liphlpapi -lm
uv.a(core.o): In function `uv_init':
c:\Users\saghul\src\libuv/src/win/core.c:58: undefined reference to `_set_invali
d_parameter_handler'
collect2: ld devolvi¾ el estado de salida 1
make: *** [test/run-tests.exe] Error 1
Contributor

saghul replied Oct 10, 2012

Fix, as discussed on IRC: saghul/libuv@046f788

Please sign in to comment.