| OLD | NEW |
| (Empty) |
| 1 /* | |
| 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 | |
| 4 * found in the LICENSE file. | |
| 5 | |
| 6 */ | |
| 7 | |
| 8 /* | |
| 9 * address_sets.c - Implements a bit set of addresses that is used by branch | |
| 10 * validation to check if branches are safe. | |
| 11 */ | |
| 12 | |
| 13 #include "native_client/src/trusted/validator/x86/ncval_reg_sfi/address_sets.h" | |
| 14 | |
| 15 #include "native_client/src/shared/platform/nacl_log.h" | |
| 16 #include "native_client/src/trusted/validator/x86/ncval_reg_sfi/ncvalidate_iter.
h" | |
| 17 #include "native_client/src/trusted/validator/x86/ncval_reg_sfi/ncvalidate_iter_
internal.h" | |
| 18 | |
| 19 /* To turn on debugging of instruction decoding, change value of | |
| 20 * DEBUGGING to 1. | |
| 21 */ | |
| 22 #define DEBUGGING 0 | |
| 23 | |
| 24 #include "native_client/src/shared/utils/debugging.h" | |
| 25 | |
| 26 #include "native_client/src/trusted/validator/x86/ncval_reg_sfi/address_sets_inl
.c" | |
| 27 | |
| 28 uint8_t NaClAddressSetContains(NaClAddressSet set, | |
| 29 NaClPcAddress address, | |
| 30 NaClValidatorState* state) { | |
| 31 if (NaClCheckAddressRange(address, state)) { | |
| 32 return set[NaClPcAddressToOffset(address)] & NaClPcAddressToMask(address); | |
| 33 } else { | |
| 34 return FALSE; | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 void NaClAddressSetAdd(NaClAddressSet set, NaClPcAddress address, | |
| 39 NaClValidatorState* state) { | |
| 40 NaClAddressSetAddInline(set, address, state); | |
| 41 } | |
| 42 | |
| 43 size_t NaClAddressSetArraySize(NaClMemorySize size) { | |
| 44 /* Be sure to add an element for partial overlaps. */ | |
| 45 /* TODO(karl) The cast to size_t for the number of elements may | |
| 46 * cause loss of data. We need to fix this. This is a security | |
| 47 * issue when doing cross-platform (32-64 bit) generation. | |
| 48 */ | |
| 49 return (size_t) NaClPcAddressToOffset(size) + 1; | |
| 50 } | |
| 51 | |
| 52 NaClAddressSet NaClAddressSetCreate(NaClMemorySize size) { | |
| 53 return (NaClAddressSet) calloc(NaClAddressSetArraySize(size), | |
| 54 sizeof(uint8_t)); | |
| 55 } | |
| 56 | |
| 57 void NaClAddressSetDestroy(NaClAddressSet set) { | |
| 58 free(set); | |
| 59 } | |
| OLD | NEW |