OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Native Client Authors. All rights reserved. | 2 * Copyright 2010 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /* | 7 /* |
8 * Windows-specific routines for verifying that Data Execution Prevention is | 8 * Windows-specific routines for verifying that Data Execution Prevention is |
9 * functional. | 9 * functional. |
10 */ | 10 */ |
11 | 11 |
12 #include "native_client/src/include/portability.h" | 12 #include "native_client/src/include/portability.h" |
13 | 13 |
14 #include <setjmp.h> | 14 #include <setjmp.h> |
15 #include <stdlib.h> | 15 #include <stdlib.h> |
16 | 16 |
17 #include "native_client/src/trusted/platform_qualify/nacl_dep_qualify.h" | 17 #include "native_client/src/trusted/platform_qualify/nacl_dep_qualify.h" |
| 18 #include "native_client/src/trusted/service_runtime/nacl_signal.h" |
| 19 |
| 20 static int g_SigFound; |
| 21 |
| 22 static enum NaClSignalResult signal_catch(int in_untrusted_code, |
| 23 int signal, |
| 24 void *ctx) { |
| 25 UNREFERENCED_PARAMETER(ctx); |
| 26 /* Should be a trusted segfault */ |
| 27 if (!in_untrusted_code && 11 == signal) { |
| 28 g_SigFound = signal; |
| 29 return NACL_SIGNAL_SKIP; |
| 30 } |
| 31 return NACL_SIGNAL_SEARCH; /* some other signal we weren't expecting */ |
| 32 } |
| 33 |
| 34 static int setup_signals() { |
| 35 return NaClSignalHandlerAdd(signal_catch); |
| 36 } |
| 37 |
| 38 static void restore_signals(int handlerId) { |
| 39 if (0 == NaClSignalHandlerRemove(handlerId)) { |
| 40 /* What to do if the remove failed? */ |
| 41 fprintf(stderr, "Failed to unload handler.\n"); |
| 42 } |
| 43 } |
18 | 44 |
19 /* | 45 /* |
20 * Returns 1 if Data Execution Prevention is present and working. | 46 * Returns 1 if Data Execution Prevention is present and working. |
21 */ | 47 */ |
22 int NaClAttemptToExecuteData() { | 48 int NaClAttemptToExecuteData() { |
23 int result; | 49 int result; |
| 50 int handlerId; |
24 char *thunk_buffer = malloc(64); | 51 char *thunk_buffer = malloc(64); |
25 nacl_void_thunk thunk = NaClGenerateThunk(thunk_buffer, 64); | 52 nacl_void_thunk thunk = NaClGenerateThunk(thunk_buffer, 64); |
26 | 53 |
| 54 handlerId = setup_signals(); |
| 55 g_SigFound = 0; |
27 __try { | 56 __try { |
28 thunk(); | 57 thunk(); |
29 result = 0; | 58 } __except (EXCEPTION_EXECUTE_HANDLER) { |
30 } __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ? | |
31 EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { | |
32 result = 1; | |
33 } | 59 } |
34 | 60 |
| 61 /* Should be a segfault */ |
| 62 if (11 == g_SigFound) { |
| 63 result = 1; |
| 64 } else { |
| 65 result = 0; |
| 66 } |
| 67 |
| 68 restore_signals(handlerId); |
35 return result; | 69 return result; |
36 } | 70 } |
OLD | NEW |