OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. |
| 5 */ |
| 6 |
| 7 #include "native_client/src/include/nacl/nacl_exception.h" |
| 8 |
| 9 #include <errno.h> |
| 10 #include <stdlib.h> |
| 11 |
| 12 #include "native_client/src/untrusted/irt/irt.h" |
| 13 |
| 14 |
| 15 static struct nacl_irt_exception_handling irt_exception_handling; |
| 16 |
| 17 /* |
| 18 * We don't do any locking here, but simultaneous calls are harmless enough. |
| 19 * They'll all be writing the same values to the same words. |
| 20 */ |
| 21 static int set_up_irt_exception_handling(void) { |
| 22 return nacl_interface_query(NACL_IRT_EXCEPTION_HANDLING_v0_1, |
| 23 &irt_exception_handling, |
| 24 sizeof(irt_exception_handling)) |
| 25 == sizeof(irt_exception_handling); |
| 26 } |
| 27 |
| 28 int nacl_exception_set_handler(nacl_exception_handler_t handler) { |
| 29 if (irt_exception_handling.exception_handler == NULL) { |
| 30 if (!set_up_irt_exception_handling()) |
| 31 return ENOSYS; |
| 32 } |
| 33 return irt_exception_handling.exception_handler(handler, NULL); |
| 34 } |
| 35 |
| 36 int nacl_exception_set_stack(void *stack, size_t size) { |
| 37 if (irt_exception_handling.exception_stack == NULL) { |
| 38 if (!set_up_irt_exception_handling()) |
| 39 return ENOSYS; |
| 40 } |
| 41 return irt_exception_handling.exception_stack(stack, size); |
| 42 } |
| 43 |
| 44 int nacl_exception_clear_flag() { |
| 45 if (irt_exception_handling.exception_clear_flag == NULL) { |
| 46 if (!set_up_irt_exception_handling()) |
| 47 return ENOSYS; |
| 48 } |
| 49 return irt_exception_handling.exception_clear_flag(); |
| 50 } |
OLD | NEW |