Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/trusted/validator/x86/ncval_seg_sfi/ncvalidate.c

Issue 10116004: Eliminate bundle_size parameter from validator interface. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Merge Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 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 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /* 7 /*
8 * ncvalidate.c 8 * ncvalidate.c
9 * Validate x86 instructions for Native Client 9 * Validate x86 instructions for Native Client
10 * 10 *
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 319
320 /* forward declarations, needed for registration */ 320 /* forward declarations, needed for registration */
321 static Bool ValidateInst(const NCDecoderInst *dinst); 321 static Bool ValidateInst(const NCDecoderInst *dinst);
322 static Bool ValidateInstReplacement(NCDecoderStatePair* tthis, 322 static Bool ValidateInstReplacement(NCDecoderStatePair* tthis,
323 NCDecoderInst *dinst_old, 323 NCDecoderInst *dinst_old,
324 NCDecoderInst *dinst_new); 324 NCDecoderInst *dinst_new);
325 static void NCJumpSummarize(struct NCValidatorState* vstate); 325 static void NCJumpSummarize(struct NCValidatorState* vstate);
326 326
327 struct NCValidatorState *NCValidateInit(const NaClPcAddress vbase, 327 struct NCValidatorState *NCValidateInit(const NaClPcAddress vbase,
328 const NaClPcAddress codesize, 328 const NaClPcAddress codesize,
329 const uint8_t alignment,
330 const int readonly_text, 329 const int readonly_text,
331 const NaClCPUFeaturesX86 *features) { 330 const NaClCPUFeaturesX86 *features) {
332 struct NCValidatorState *vstate = NULL; 331 struct NCValidatorState *vstate = NULL;
332 const int alignment = 32;
Mark Seaborn 2012/04/18 22:58:20 Should this be in a "#define NACL_BUNDLE_SIZE" som
333 333
334 dprint(("NCValidateInit(%"NACL_PRIxNaClPcAddressAll 334 dprint(("NCValidateInit(%"NACL_PRIxNaClPcAddressAll
335 ", %"NACL_PRIxNaClMemorySizeAll", %08x)\n", vbase, codesize, 335 ", %"NACL_PRIxNaClMemorySizeAll", %08x)\n", vbase, codesize,
336 alignment)); 336 alignment));
337 do { 337 do {
338 if (alignment != 16 && alignment != 32) 338 if (features == NULL)
339 break; 339 break;
340 if ((vbase & (alignment - 1)) != 0) 340 if ((vbase & (alignment - 1)) != 0)
341 break; 341 break;
342 if (features == NULL)
343 break;
344 dprint(("ncv_init(%"NACL_PRIxNaClPcAddress", %"NACL_PRIxNaClMemorySize 342 dprint(("ncv_init(%"NACL_PRIxNaClPcAddress", %"NACL_PRIxNaClMemorySize
345 ")\n", vbase, codesize)); 343 ")\n", vbase, codesize));
346 vstate = (struct NCValidatorState *)calloc(1, sizeof(*vstate)); 344 vstate = (struct NCValidatorState *)calloc(1, sizeof(*vstate));
347 if (vstate == NULL) 345 if (vstate == NULL)
348 break; 346 break;
349 /* Record default error reporter here, since we don't construct 347 /* Record default error reporter here, since we don't construct
350 * the decoder state until the call to NCValidateSegment. This allows 348 * the decoder state until the call to NCValidateSegment. This allows
351 * us to update the error reporter in the decoder state properly. 349 * us to update the error reporter in the decoder state properly.
352 */ 350 */
353 vstate->dstate.error_reporter = &kNCNullErrorReporter; 351 vstate->dstate.error_reporter = &kNCNullErrorReporter;
354 vstate->num_diagnostics = kMaxDiagnostics; 352 vstate->num_diagnostics = kMaxDiagnostics;
355 vstate->iadrbase = vbase; 353 vstate->iadrbase = vbase;
356 vstate->codesize = codesize; 354 vstate->codesize = codesize;
357 vstate->alignment = alignment; 355 vstate->alignment = alignment;
358 vstate->alignmask = alignment-1; 356 vstate->alignmask = alignment - 1;
359 vstate->vttable = (uint8_t *)calloc(NCIATOffset(codesize) + 1, 1); 357 vstate->vttable = (uint8_t *)calloc(NCIATOffset(codesize) + 1, 1);
360 vstate->kttable = (uint8_t *)calloc(NCIATOffset(codesize) + 1, 1); 358 vstate->kttable = (uint8_t *)calloc(NCIATOffset(codesize) + 1, 1);
361 vstate->pattern_nonfirst_insts_table = NULL; 359 vstate->pattern_nonfirst_insts_table = NULL;
362 vstate->summarize_fn = NCJumpSummarize; 360 vstate->summarize_fn = NCJumpSummarize;
363 vstate->do_stub_out = 0; 361 vstate->do_stub_out = 0;
364 vstate->readonly_text = readonly_text; 362 vstate->readonly_text = readonly_text;
365 if (vstate->vttable == NULL || vstate->kttable == NULL) 363 if (vstate->vttable == NULL || vstate->kttable == NULL)
366 break; 364 break;
367 dprint((" allocated tables\n")); 365 dprint((" allocated tables\n"));
368 NCStatsInit(vstate); 366 NCStatsInit(vstate);
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 ValidatePrintOffsetError(0, "Bad text segment (zero size)", vstate); 977 ValidatePrintOffsetError(0, "Bad text segment (zero size)", vstate);
980 NCStatsSegFault(vstate); 978 NCStatsSegFault(vstate);
981 return; 979 return;
982 } 980 }
983 NCValidateDStateInit(vstate, mbase, vbase, sz); 981 NCValidateDStateInit(vstate, mbase, vbase, sz);
984 NCDecoderStateDecode(&vstate->dstate); 982 NCDecoderStateDecode(&vstate->dstate);
985 NCDecoderStateDestruct(&vstate->dstate); 983 NCDecoderStateDestruct(&vstate->dstate);
986 } 984 }
987 985
988 int NCValidateSegmentPair(uint8_t *mbase_old, uint8_t *mbase_new, 986 int NCValidateSegmentPair(uint8_t *mbase_old, uint8_t *mbase_new,
989 NaClPcAddress vbase, size_t sz, uint8_t alignment, 987 NaClPcAddress vbase, size_t sz,
990 const NaClCPUFeaturesX86 *features) { 988 const NaClCPUFeaturesX86 *features) {
991 /* TODO(karl): Refactor to use inheritance from NCDecoderStatePair? */ 989 /* TODO(karl): Refactor to use inheritance from NCDecoderStatePair? */
992 NCDecoderStatePair pair; 990 NCDecoderStatePair pair;
993 NCValidatorState* new_vstate; 991 NCValidatorState* new_vstate;
994 NCValidatorState* old_vstate; 992 NCValidatorState* old_vstate;
995 993
996 int result = 0; 994 int result = 0;
997 995
998 /* Verify that we actually have a segment to walk. */ 996 /* Verify that we actually have a segment to walk. */
999 if (sz == 0) { 997 if (sz == 0) {
1000 printf("VALIDATOR: %"NACL_PRIxNaClPcAddress 998 printf("VALIDATOR: %"NACL_PRIxNaClPcAddress
1001 ": Bad text segment (zero size)\n", vbase); 999 ": Bad text segment (zero size)\n", vbase);
1002 return 0; 1000 return 0;
1003 } 1001 }
1004 1002
1005 old_vstate = NCValidateInit(vbase, sz, alignment, FALSE, features); 1003 old_vstate = NCValidateInit(vbase, sz, FALSE, features);
1006 if (old_vstate != NULL) { 1004 if (old_vstate != NULL) {
1007 NCValidateDStateInit(old_vstate, mbase_old, vbase, sz); 1005 NCValidateDStateInit(old_vstate, mbase_old, vbase, sz);
1008 new_vstate = NCValidateInit(vbase, sz, alignment, FALSE, features); 1006 new_vstate = NCValidateInit(vbase, sz, FALSE, features);
1009 if (new_vstate != NULL) { 1007 if (new_vstate != NULL) {
1010 NCValidateDStateInit(new_vstate, mbase_new, vbase, sz); 1008 NCValidateDStateInit(new_vstate, mbase_new, vbase, sz);
1011 1009
1012 NCDecoderStatePairConstruct(&pair, 1010 NCDecoderStatePairConstruct(&pair,
1013 &old_vstate->dstate, 1011 &old_vstate->dstate,
1014 &new_vstate->dstate); 1012 &new_vstate->dstate);
1015 pair.action_fn = ValidateInstReplacement; 1013 pair.action_fn = ValidateInstReplacement;
1016 if (NCDecoderStatePairDecode(&pair)) { 1014 if (NCDecoderStatePairDecode(&pair)) {
1017 result = 1; 1015 result = 1;
1018 } else { 1016 } else {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 } 1052 }
1055 1053
1056 /* check basic block boundaries */ 1054 /* check basic block boundaries */
1057 for (offset = 0; offset < vstate->codesize; offset += vstate->alignment) { 1055 for (offset = 0; offset < vstate->codesize; offset += vstate->alignment) {
1058 if (!NCGetAdrTable(offset, vstate->vttable)) { 1056 if (!NCGetAdrTable(offset, vstate->vttable)) {
1059 ValidatePrintOffsetError(offset, "Bad basic block alignment", vstate); 1057 ValidatePrintOffsetError(offset, "Bad basic block alignment", vstate);
1060 NCStatsBadAlignment(vstate); 1058 NCStatsBadAlignment(vstate);
1061 } 1059 }
1062 } 1060 }
1063 } 1061 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698