| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_SEG_SFI_NCVALIDATE_H__ | 7 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_SEG_SFI_NCVALIDATE_H__ |
| 8 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_SEG_SFI_NCVALIDATE_H__ | 8 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_SEG_SFI_NCVALIDATE_H__ |
| 9 | 9 |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| 11 #include "native_client/src/trusted/validator/x86/nacl_cpuid.h" | 11 #include "native_client/src/trusted/validator/x86/nacl_cpuid.h" |
| 12 #include "native_client/src/trusted/validator/types_memory_model.h" | 12 #include "native_client/src/trusted/validator/types_memory_model.h" |
| 13 | 13 |
| 14 /* | 14 /* |
| 15 * ncvalidate.h: Validator for the segment-based sandbox. | 15 * ncvalidate.h: Validator for the segment-based sandbox. |
| 16 * | 16 * |
| 17 * This is the primary library interface to the validator for the | 17 * This is the primary library interface to the validator for the |
| 18 * segment-based sandbox. This version should be used when performance | 18 * segment-based sandbox. This version should be used when performance |
| 19 * is important. See ncvalidate_detailed.h for a secondary API which | 19 * is important. See ncvalidate_detailed.h for a secondary API which |
| 20 * provides more details when reporting errors. | 20 * provides more details when reporting errors. |
| 21 * | 21 * |
| 22 * Basic usage: | 22 * Basic usage: |
| 23 * if (!NaClArchSuppported()) fail | 23 * if (!NaClArchSuppported()) fail |
| 24 * vstate = NCValidateInit(base, size, 16, features); | 24 * vstate = NCValidateInit(base, size, features); |
| 25 * if vstate == 0 fail | 25 * if vstate == 0 fail |
| 26 * for each section: | 26 * for each section: |
| 27 * NCValidateSegment(maddr, base, size, vstate); | 27 * NCValidateSegment(maddr, base, size, vstate); |
| 28 * rc = NCValidateFinish(); | 28 * rc = NCValidateFinish(); |
| 29 * if rc != 0 fail | 29 * if rc != 0 fail |
| 30 * NCValidateFreeState(&vstate); | 30 * NCValidateFreeState(&vstate); |
| 31 * | 31 * |
| 32 * See the README file in this directory for more info on the general | 32 * See the README file in this directory for more info on the general |
| 33 * structure of the validator. | 33 * structure of the validator. |
| 34 */ | 34 */ |
| 35 struct Gio; | 35 struct Gio; |
| 36 struct NCDecoderInst; | 36 struct NCDecoderInst; |
| 37 struct NCValidatorState; | 37 struct NCValidatorState; |
| 38 struct NaClErrorReporter; | 38 struct NaClErrorReporter; |
| 39 | 39 |
| 40 /* | 40 /* |
| 41 * Set the maximum number of diagnostic errors to be reported to the | 41 * Set the maximum number of diagnostic errors to be reported to the |
| 42 * given value (-1 implies all error messages). | 42 * given value (-1 implies all error messages). |
| 43 */ | 43 */ |
| 44 void NCValidateSetNumDiagnostics(struct NCValidatorState *vstate, | 44 void NCValidateSetNumDiagnostics(struct NCValidatorState *vstate, |
| 45 int num_diagnostics); | 45 int num_diagnostics); |
| 46 | 46 |
| 47 /* | 47 /* |
| 48 * NCValidateInit: Initialize NaCl validator internal state. | 48 * NCValidateInit: Initialize NaCl validator internal state. |
| 49 * Parameters: | 49 * Parameters: |
| 50 * vbase: base virtual address for code segment | 50 * vbase: base virtual address for code segment |
| 51 * codesize: size in bytes of code segment | 51 * codesize: size in bytes of code segment |
| 52 * alignment: 16 or 32, specifying alignment | |
| 53 * features: the features supported by the CPU that will run the code | 52 * features: the features supported by the CPU that will run the code |
| 54 * Returns: | 53 * Returns: |
| 55 * an initialized struct NCValidatorState * if everything is okay, | 54 * an initialized struct NCValidatorState * if everything is okay, |
| 56 * else NULL | 55 * else NULL |
| 57 */ | 56 */ |
| 58 struct NCValidatorState *NCValidateInit(const NaClPcAddress vbase, | 57 struct NCValidatorState *NCValidateInit(const NaClPcAddress vbase, |
| 59 const NaClMemorySize codesize, | 58 const NaClMemorySize codesize, |
| 60 const uint8_t alignment, | |
| 61 const int readonly_text, | 59 const int readonly_text, |
| 62 const NaClCPUFeaturesX86 *features); | 60 const NaClCPUFeaturesX86 *features); |
| 63 | 61 |
| 64 /* | 62 /* |
| 65 * Allows "stub out mode" to be enabled, in which some unsafe | 63 * Allows "stub out mode" to be enabled, in which some unsafe |
| 66 * instructions will be rendered safe by replacing them with HLT | 64 * instructions will be rendered safe by replacing them with HLT |
| 67 * instructions. | 65 * instructions. |
| 68 */ | 66 */ |
| 69 void NCValidateSetStubOutMode(struct NCValidatorState *vstate, | 67 void NCValidateSetStubOutMode(struct NCValidatorState *vstate, |
| 70 int do_stub_out); | 68 int do_stub_out); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 91 void NCValidateSegment(uint8_t *mbase, NaClPcAddress vbase, | 89 void NCValidateSegment(uint8_t *mbase, NaClPcAddress vbase, |
| 92 NaClMemorySize sz, | 90 NaClMemorySize sz, |
| 93 struct NCValidatorState *vstate); | 91 struct NCValidatorState *vstate); |
| 94 | 92 |
| 95 /* Validate a segment for dynamic code replacement */ | 93 /* Validate a segment for dynamic code replacement */ |
| 96 /* This routine checks that the code found at mbase_old | 94 /* This routine checks that the code found at mbase_old |
| 97 * can be dynamically replaced with the code at mbase_new | 95 * can be dynamically replaced with the code at mbase_new |
| 98 * safely. Returns non-zero if successful. | 96 * safely. Returns non-zero if successful. |
| 99 */ | 97 */ |
| 100 int NCValidateSegmentPair(uint8_t *mbase_old, uint8_t *mbase_new, | 98 int NCValidateSegmentPair(uint8_t *mbase_old, uint8_t *mbase_new, |
| 101 NaClPcAddress vbase, size_t sz, uint8_t alignment, | 99 NaClPcAddress vbase, size_t sz, |
| 102 const NaClCPUFeaturesX86 *features); | 100 const NaClCPUFeaturesX86 *features); |
| 103 | 101 |
| 104 /* Check targets and alignment. Returns non-zero if there are */ | 102 /* Check targets and alignment. Returns non-zero if there are */ |
| 105 /* safety issues, else returns 1 */ | 103 /* safety issues, else returns 1 */ |
| 106 /* BEWARE: vstate is invalid after this call */ | 104 /* BEWARE: vstate is invalid after this call */ |
| 107 int NCValidateFinish(struct NCValidatorState *vstate); | 105 int NCValidateFinish(struct NCValidatorState *vstate); |
| 108 | 106 |
| 109 /* BEWARE: this call deallocates vstate. */ | 107 /* BEWARE: this call deallocates vstate. */ |
| 110 void NCValidateFreeState(struct NCValidatorState **vstate); | 108 void NCValidateFreeState(struct NCValidatorState **vstate); |
| 111 | 109 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 133 * If zero, no messages are printed. | 131 * If zero, no messages are printed. |
| 134 * If >0, only that many diagnostic errors are printed. | 132 * If >0, only that many diagnostic errors are printed. |
| 135 * If negative, all validator diagnostics are printed. | 133 * If negative, all validator diagnostics are printed. |
| 136 */ | 134 */ |
| 137 void NCValidatorSetMaxDiagnostics(int new_value); | 135 void NCValidatorSetMaxDiagnostics(int new_value); |
| 138 | 136 |
| 139 /* Returns 1 if any code has been overwritten with halts. */ | 137 /* Returns 1 if any code has been overwritten with halts. */ |
| 140 int NCValidatorDidStubOut(struct NCValidatorState *vstate); | 138 int NCValidatorDidStubOut(struct NCValidatorState *vstate); |
| 141 | 139 |
| 142 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_SEG_SFI_NCVALIDATE_H__
*/ | 140 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_SEG_SFI_NCVALIDATE_H__
*/ |
| OLD | NEW |