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 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVALIDATE_ERROR_H__ | |
8 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVALIDATE_ERROR_H__ | |
9 | |
10 /* | |
11 * Defines an API for reporting error messages by the validator. The | |
12 * API is a struct of function pointers (i.e. virtuals) which will | |
13 * be called by the validator to print out error messages. | |
14 * | |
15 * The typical error message is generated using the form: | |
16 * | |
17 * error_reporter->printf(format, ...) | |
18 * | |
19 * Note: Levels are assumed to be defined by the constants | |
20 * LOG_INFO, LOG_WARNING, LOG_ERROR, and LOG_FATAL defined | |
21 * by header file native_client/src/shared/platform/nacl_log.h" | |
22 */ | |
23 | |
24 #include <stdarg.h> | |
25 #include "native_client/src/include/portability.h" | |
26 | |
27 EXTERN_C_BEGIN | |
28 | |
29 struct NaClErrorReporter; | |
30 | |
31 /* Enumeration defining type of expected error reporter, based on | |
32 * model of instructions to be printed. | |
33 */ | |
34 typedef enum NaClErrorReporterSupported { | |
35 /* The following defines the null error reporter, which reports | |
36 * no errors, and therefore, can support any model of instructions | |
37 * to be printed. | |
38 */ | |
39 NaClNullErrorReporter, | |
40 | |
41 /* The following defines that the error reporter handles calls | |
42 * to NaClPrintInst using a NaClInstState* instruction argument. | |
43 */ | |
44 NaClInstStateErrorReporter, | |
45 | |
46 /* The following defines that the error reporter handles calls | |
47 * to NaClPrintInst using a NCDecoderInst* instruction argument. | |
48 */ | |
49 NCDecoderInstErrorReporter | |
50 } NaClErrorReporterSupported; | |
51 | |
52 /* Returns the name of the NaClErrorReporterSupported value. */ | |
53 const char* NaClErrorReporterSupportedName(NaClErrorReporterSupported kind); | |
54 | |
55 /* Method to print out a formatted string. */ | |
56 typedef void (*NaClPrintfMessage)( | |
57 struct NaClErrorReporter* self, const char* format, ...); | |
58 | |
59 /* Method to print out a formatted string. */ | |
60 typedef void (*NaClPrintfVMessage)(struct NaClErrorReporter* self, | |
61 const char* format, | |
62 va_list ap); | |
63 | |
64 /* Method to print out a parsed instruction. | |
65 * WARNING: the inst parameter is either a NaClInstState* (if the | |
66 * iterator parser is being used), or NCDecoderInst* (if the callback | |
67 * parser is being used). Be sure to use the correct error reporter | |
68 * for the parser being used. | |
69 */ | |
70 typedef void (*NaClPrintInst)(struct NaClErrorReporter* self, void* inst); | |
71 | |
72 /* The virtual (base) class of virtual printing methods. */ | |
73 typedef struct NaClErrorReporter { | |
74 NaClErrorReporterSupported supported_reporter; | |
75 NaClPrintfMessage printf; | |
76 NaClPrintfVMessage printf_v; | |
77 NaClPrintInst print_inst; | |
78 } NaClErrorReporter; | |
79 | |
80 /* Default null printf function for error reporter. */ | |
81 void NaClNullErrorPrintf(NaClErrorReporter* self, | |
82 const char* format, ...); | |
83 | |
84 /* Default null printf_v function for error reporter. */ | |
85 void NaClNullErrorPrintfV(NaClErrorReporter* self, | |
86 const char* format, | |
87 va_list ap); | |
88 | |
89 /* Default verbose printf function that reports to NaClLogGetGio(). */ | |
90 void NaClVerboseErrorPrintf(NaClErrorReporter* self, | |
91 const char* format, ...); | |
92 | |
93 /* Default verbose printf_v function that reports to NaClLogGetGio(). */ | |
94 void NaClVerboseErrorPrintfV(NaClErrorReporter* self, | |
95 const char* format, | |
96 va_list ap); | |
97 | |
98 EXTERN_C_END | |
99 | |
100 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVALIDATE_ERROR_H__ */ | |
OLD | NEW |