Remove check for ABIVERSION, so that I don't have to rebuild binutils when this is...
[nativeclient.git] / ncv / ncvalidate.h
bloba09dd05817cabb7518de4dbe0f90351374143460
1 /*
2 * Copyright 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef __NCVALIDATE_H__
33 #define __NCVALIDATE_H__
35 * ncvalidate.h: exports for ncvalidate.c
37 * This is the library interface to the NaCl validator.
38 * Basic usage:
39 * rc = NCValidateInit(base, limit, 16)
40 * if rc != 0 fail
41 * for each section:
42 * NCValidateSegment(maddr, vaddr, size);
43 * rc = NCValidateFinish();
44 * if rc != 0 fail
45 * Optional reporting routines
46 * Stats_Print()
48 * See the README file in this directory for more info on the general
49 * structure of the validator.
51 struct NCValidatorState;
54 * NCValidateInit: Initialize NaCl validator internal state
55 * Parameters:
56 * vbase: base virtual address for code segment
57 * vlimit: size in bytes of code segment
58 * alignment: 16 or 32, specifying alignment
59 * Returns:
60 * an initialized struct NCValidatorState * if everything is okay,
61 * else NULL
63 struct NCValidatorState *NCValidateInit(const uint32_t vbase,
64 const uint32_t vlimit,
65 const uint8_t alignment);
67 /* Validate a segment */
68 /* This routine will raise an segmentation exception if you ask
69 * it to check memory that can't be accessed. This should of be
70 * interpreted as an indication that the module in question is
71 * invalid.
73 void NCValidateSegment(uint8_t *mbase, uint32_t vbase, size_t sz,
74 struct NCValidatorState *vstate);
76 /* Check targets and alignment. Returns non-zero if there are */
77 /* safety issues, else returns 1 */
78 /* BEWARE: vstate is invalid after this call */
79 int NCValidateFinish(struct NCValidatorState *vstate);
81 /* BEWARE: this call deallocates vstate. */
82 void NCValidateFreeState(struct NCValidatorState **vstate);
84 /* Print some interesting statistics... */
85 void Stats_Print(FILE *f, struct NCValidatorState *vstate);
87 /* Book-keeping routines called from the decoder. */
88 void OpcodeHisto(const uint8_t byte1,
89 struct NCValidatorState *vstate);
91 #endif /* __NCVALIDATE_H__ */