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.
8 * Collects histogram information as a validator function.
10 * Note: The following functions are used to define a validator function
11 * for collecting this information. See header file ncvalidator_iter.h
12 * for more information on how to register these functions as a validator
16 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_NC_OPCODE_HISTOGRAPH_H__
17 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_NC_OPCODE_HISTOGRAPH_H__
19 #include "native_client/src/include/portability.h"
20 #include "native_client/src/shared/utils/types.h"
22 /* Defines a validator state. */
23 struct NaClValidatorState;
25 /* Defines an instruction iterator that processes a code segment. */
28 /* Defines a data structure that holds data defining the opcode histogram
29 * being collected. Holds a histogram of the (first) byte of the found
30 * opcodes for each instruction.
32 typedef struct NaClOpcodeHistogram {
33 uint32_t opcode_histogram[256];
34 } NaClOpcodeHistogram;
36 /* Command line flag controlling whether an opcode histogram is
37 * collected while validating.
39 extern Bool NACL_FLAGS_opcode_histogram;
41 /* Initializes opcode histogram data in the validator state. */
42 void NaClOpcodeHistogramInitialize(struct NaClValidatorState* state);
44 /* Validator function to record histgram value for current instruction. */
45 void NaClOpcodeHistogramRecord(struct NaClValidatorState* state);
47 /* Validator print function to print out collected histogram. */
48 void NaClOpcodeHistogramPrintStats(struct NaClValidatorState* state);
50 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_NC_OPCODE_HISTOGRAPH_H__ */