| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright (c) 2011 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 * address_sets_inl.c - Holds inline routines for commonly used (simple) |
| 9 * functions in address_sets.h. Used to speed up code. Inlined routines |
| 10 * correspond to the following functions in address_sets.h, but with |
| 11 * an 'Inline' suffix: |
| 12 * |
| 13 * NaClAddressSetAdd |
| 14 */ |
| 15 |
| 16 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_ADDRESS_SETS_INL_C
__ |
| 17 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_ADDRESS_SETS_INL_C
__ |
| 18 |
| 19 #include "native_client/src/trusted/validator/x86/ncval_reg_sfi/address_sets.h" |
| 20 |
| 21 /* Model the offset created by removing the bottom three bits of a PcAddress. */ |
| 22 typedef NaClPcAddress NaClPcOffset; |
| 23 |
| 24 /* Model the set of possible 3-bit tails of possible PcAddresses. */ |
| 25 static const uint8_t nacl_pc_address_masks[8] = { |
| 26 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; |
| 27 |
| 28 /* Convert the 3 lower bits of an address into the corresponding address mask |
| 29 * to use. |
| 30 */ |
| 31 static INLINE uint8_t NaClPcAddressToMask(NaClPcAddress address) { |
| 32 return nacl_pc_address_masks[(int) (address & (NaClPcAddress)0x7)]; |
| 33 } |
| 34 |
| 35 /* Convert an address into the corresponding offset in an address table. |
| 36 * That is, strip off the last three bits, since these remaining bits |
| 37 * will be encoded using the union of address masks in the address table. |
| 38 */ |
| 39 static INLINE NaClPcOffset NaClPcAddressToOffset(NaClPcAddress address) { |
| 40 return address >> 3; |
| 41 } |
| 42 |
| 43 /* Returns true if the given address is within the code segment. Generates |
| 44 * error messages if it isn't. |
| 45 */ |
| 46 static INLINE Bool NaClCheckAddressRange(NaClPcAddress address, |
| 47 NaClValidatorState* state) { |
| 48 if (address < state->vbase) { |
| 49 NaClValidatorPcAddressMessage(LOG_ERROR, state, address, |
| 50 "Jump to address before code block.\n"); |
| 51 return FALSE; |
| 52 } |
| 53 if (address >= state->vlimit) { |
| 54 NaClValidatorPcAddressMessage(LOG_ERROR, state, address, |
| 55 "Jump to address beyond code block limit.\n"); |
| 56 return FALSE; |
| 57 } |
| 58 return TRUE; |
| 59 } |
| 60 |
| 61 static INLINE void NaClAddressSetAddInline(NaClAddressSet set, |
| 62 NaClPcAddress address, |
| 63 NaClValidatorState* state) { |
| 64 if (NaClCheckAddressRange(address, state)) { |
| 65 NaClPcAddress offset = address - state->vbase; |
| 66 DEBUG(NaClLog(LOG_INFO, |
| 67 "Address set add: %"NACL_PRIxNaClPcAddress"\n", address)); |
| 68 set[NaClPcAddressToOffset(offset)] |= NaClPcAddressToMask(offset); |
| 69 } |
| 70 } |
| 71 |
| 72 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_ADDRESS_SETS_IN
L_C__ */ |
| OLD | NEW |