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 : /* Implement the ApplyValidatorVerbosely API for the x86-32 architecture. */
8 :
9 : #include "native_client/src/trusted/validator/ncvalidate.h"
10 :
11 : #include "native_client/src/shared/platform/nacl_log.h"
12 : #include "native_client/src/trusted/validator/x86/nacl_cpuid.h"
13 : #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate_detailed.h"
14 : #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncdecode_verbose.h"
15 : #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate.h"
16 : #include "native_client/src/trusted/validator/x86/32/ncvalidate.h"
17 : #include <assert.h>
18 :
19 : /* Be sure the correct compile flags are defined for this. */
20 : #if NACL_ARCH(NACL_TARGET_ARCH) != NACL_x86
21 : # error("Can't compile, target is for x86-32")
22 : #else
23 : # if NACL_TARGET_SUBARCH != 32
24 : # error("Can't compile, target is for x86-32")
25 : # endif
26 : #endif
27 :
28 : static NaClValidationStatus NCApplyValidatorVerbosely_x86_32(
29 : uintptr_t guest_addr,
30 : uint8_t *data,
31 : size_t size,
32 : int bundle_size,
33 3 : NaClCPUFeaturesX86 *cpu_features) {
34 3 : int validator_result = 0;
35 : struct NCValidatorState *vstate;
36 :
37 3 : vstate = NCValidateInitDetailed(guest_addr, size, bundle_size, cpu_features);
38 3 : if (vstate == NULL) return NaClValidationFailedOutOfMemory;
39 3 : NCValidateSetNumDiagnostics(vstate, -1); /* Reports all errors. */
40 3 : NCValidateSetErrorReporter(vstate, &kNCVerboseErrorReporter);
41 3 : NCValidateSegment(data, guest_addr, size, vstate);
42 3 : validator_result = NCValidateFinish(vstate);
43 3 : NCValidateFreeState(&vstate);
44 3 : return (validator_result == 0)
45 : ? NaClValidationSucceeded : NaClValidationFailed;
46 : }
47 :
48 : NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorVerbosely, x86, 32)
49 : (enum NaClSBKind sb_kind,
50 : NaClApplyValidationKind kind,
51 : uintptr_t guest_addr,
52 : uint8_t *data,
53 : size_t size,
54 : int bundle_size,
55 3 : NaClCPUFeaturesX86 *cpu_features) {
56 3 : NaClValidationStatus status = NaClValidationFailedNotImplemented;
57 3 : assert(NACL_SB_DEFAULT == sb_kind);
58 3 : if (bundle_size == 16 || bundle_size == 32) {
59 3 : if (!NaClArchSupported(cpu_features))
60 0 : return NaClValidationFailedCpuNotSupported;
61 3 : switch (kind) {
62 : case NaClApplyCodeValidation:
63 3 : status = NCApplyValidatorVerbosely_x86_32(
64 : guest_addr, data, size, bundle_size, cpu_features);
65 3 : break;
66 : case NaClApplyValidationDoStubout:
67 0 : status = NCApplyValidatorStubout_x86_32(
68 : guest_addr, data, size, bundle_size, cpu_features);
69 : break;
70 : default:
71 : /* If reached, it isn't implemented (yet). */
72 : break;
73 : }
74 : }
75 3 : return status;
76 : }
|