| 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 * 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->codesize) { | |
| 49 NaClValidatorPcAddressMessage(LOG_ERROR, state, address, | |
| 50 "Jump to address outside code segment.\n"); | |
| 51 return FALSE; | |
| 52 } | |
| 53 return TRUE; | |
| 54 } | |
| 55 | |
| 56 static INLINE void NaClAddressSetAddInline(NaClAddressSet set, | |
| 57 NaClPcAddress address, | |
| 58 NaClValidatorState* state) { | |
| 59 if (NaClCheckAddressRange(address, state)) { | |
| 60 DEBUG(NaClLog(LOG_INFO, | |
| 61 "Address set add: %"NACL_PRIxNaClPcAddress"\n", | |
| 62 address)); | |
| 63 set[NaClPcAddressToOffset(address)] |= NaClPcAddressToMask(address); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_ADDRESS_SETS_IN
L_C__ */ | |
| OLD | NEW |