OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2014 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/minsfi.h" |
| 8 #include "native_client/src/include/minsfi_priv.h" |
| 9 |
| 10 /* |
| 11 * Fixed offset of the data segment. This must be kept in sync with the |
| 12 * AllocateDataSegment compiler pass. |
| 13 */ |
| 14 #define DATASEG_OFFSET 0x10000 |
| 15 |
| 16 /* Globals exported by the sandbox, aka the manifest. */ |
| 17 extern uint32_t __sfi_pointer_size; |
| 18 extern const char __sfi_data_segment[]; |
| 19 extern uint32_t __sfi_data_segment_size; |
| 20 |
| 21 /* Entry point of the sandbox */ |
| 22 extern uint32_t _start_minsfi(void); |
| 23 |
| 24 static inline void GetManifest(MinsfiManifest *sb) { |
| 25 sb->ptr_size = __sfi_pointer_size; |
| 26 sb->dataseg_offset = DATASEG_OFFSET; |
| 27 sb->dataseg_size = __sfi_data_segment_size; |
| 28 sb->dataseg_template = __sfi_data_segment; |
| 29 } |
| 30 |
| 31 bool MinsfiInitializeSandbox(void) { |
| 32 MinsfiManifest manifest; |
| 33 MinsfiSandbox sb; |
| 34 |
| 35 if (MinsfiGetActiveSandbox() != NULL) |
| 36 return true; |
| 37 |
| 38 GetManifest(&manifest); |
| 39 if (!MinsfiInitSandbox(&manifest, &sb)) |
| 40 return false; |
| 41 |
| 42 MinsfiSetActiveSandbox(&sb); |
| 43 return true; |
| 44 } |
| 45 |
| 46 int MinsfiInvokeSandbox(void) { |
| 47 if (MinsfiGetActiveSandbox() == NULL) |
| 48 return EXIT_FAILURE; |
| 49 |
| 50 return _start_minsfi(); |
| 51 } |
| 52 |
| 53 bool MinsfiDestroySandbox(void) { |
| 54 const MinsfiSandbox *sb; |
| 55 |
| 56 if ((sb = MinsfiGetActiveSandbox()) == NULL) |
| 57 return true; |
| 58 |
| 59 if (MinsfiUnmapSandbox(sb)) { |
| 60 MinsfiSetActiveSandbox(NULL); |
| 61 return true; |
| 62 } |
| 63 |
| 64 return false; |
| 65 } |
OLD | NEW |