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.
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
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__
19 #include "native_client/src/trusted/validator/x86/ncval_reg_sfi/address_sets.h"
21 /* Model the offset created by removing the bottom three bits of a PcAddress. */
22 typedef NaClPcAddress NaClPcOffset;
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 };
28 /* Convert the 3 lower bits of an address into the corresponding address mask
31 static INLINE uint8_t NaClPcAddressToMask(NaClPcAddress address) {
32 return nacl_pc_address_masks[(int) (address & (NaClPcAddress)0x7)];
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.
39 static INLINE NaClPcOffset NaClPcAddressToOffset(NaClPcAddress address) {
43 /* Returns true if the given address is within the code segment. Generates
44 * error messages if it isn't.
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");
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",
63 set[NaClPcAddressToOffset(address)] |= NaClPcAddressToMask(address);
67 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_ADDRESS_SETS_INL_C__ */