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 #ifndef NATIVE_CLIENT_SRC_INCLUDE_MINSFI_PRIV_H_ |
| 8 #define NATIVE_CLIENT_SRC_INCLUDE_MINSFI_PRIV_H_ |
| 9 |
| 10 #include <stdbool.h> |
| 11 #include <stdlib.h> |
| 12 #include <stdint.h> |
| 13 #include <unistd.h> |
| 14 |
| 15 typedef struct { |
| 16 uint32_t ptr_size; /* size of sandboxed pointers in bits */ |
| 17 uint32_t dataseg_offset; |
| 18 uint32_t dataseg_size; |
| 19 const char *dataseg_template; |
| 20 } MinsfiManifest; |
| 21 |
| 22 typedef struct { |
| 23 uint32_t offset; |
| 24 uint32_t length; |
| 25 } MinsfiMemoryRegion; |
| 26 |
| 27 typedef struct { |
| 28 MinsfiMemoryRegion dataseg; |
| 29 MinsfiMemoryRegion heap; |
| 30 MinsfiMemoryRegion stack; |
| 31 } MinsfiMemoryLayout; |
| 32 |
| 33 typedef struct { |
| 34 char *mem_base; |
| 35 uint64_t mem_alloc_size; |
| 36 uint32_t ptr_mask; |
| 37 MinsfiMemoryLayout mem_layout; |
| 38 } MinsfiSandbox; |
| 39 |
| 40 /* |
| 41 * Computes the boundaries of the individual regions of the sandbox's address |
| 42 * subspace and stores them into the given minsfi_layout data structure. |
| 43 * Returns FALSE if a layout cannot be created for the given parameters. |
| 44 */ |
| 45 bool MinsfiGenerateMemoryLayout(const MinsfiManifest *manifest, |
| 46 uint32_t page_size, MinsfiMemoryLayout *layout); |
| 47 |
| 48 /* |
| 49 * This function initializes the address subspace of the sandbox. Protection of |
| 50 * the pages allocated to the data segment, heap and stack is set to read/write, |
| 51 * the rest is no-access. The data segment template is copied into the sandbox. |
| 52 * |
| 53 * The function returns TRUE if the initialization was successful, and stores |
| 54 * information about the sandbox into the given MinsfiSandbox struct. |
| 55 */ |
| 56 bool MinsfiInitSandbox(const MinsfiManifest *manifest, MinsfiSandbox *sb); |
| 57 |
| 58 /* |
| 59 * Unmaps a memory region given by the provided base and the declared pointer |
| 60 * size of the sandbox. The function returns FALSE if munmap() fails. |
| 61 */ |
| 62 bool MinsfiUnmapSandbox(const MinsfiSandbox *sb); |
| 63 |
| 64 /* |
| 65 * Returns information about the active sandbox, or NULL if there is no |
| 66 * initialized sandbox at the moment. |
| 67 */ |
| 68 const MinsfiSandbox *MinsfiGetActiveSandbox(void); |
| 69 |
| 70 /* |
| 71 * Sets the sandbox which all trampolines will refer to. Internally copies the |
| 72 * data structure to its own storage. |
| 73 */ |
| 74 void MinsfiSetActiveSandbox(const MinsfiSandbox *sb); |
| 75 |
| 76 #endif // NATIVE_CLIENT_SRC_INCLUDE_MINSFI_PRIV_H_ |
OLD | NEW |