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

Side by Side Diff: src/trusted/validator/x86/halt_trim.c

Issue 625923004: Delete old x86 validator. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: rebase master Created 6 years, 2 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
« no previous file with comments | « src/trusted/validator/x86/halt_trim.h ('k') | src/trusted/validator/x86/halt_trim_tests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "native_client/src/trusted/validator/x86/halt_trim.h"
8
9 #include <stdio.h>
10 #include "native_client/src/trusted/validator/x86/ncinstbuffer.h"
11
12 /* Safety buffer size of halts we must keep, so that we guarantee
13 * that we don't trim the last legal instruction in the
14 * code segment. Note: we add 1 to the maximum instruction length just
15 * to be safe.
16 */
17 static const NaClMemorySize kMinHaltKeepLength = MAX_INST_LENGTH + 1;
18
19 /* x86 HALT opcode */
20 static const uint8_t kNaClHalt = 0xf4;
21
22 NaClMemorySize NCHaltTrimSize(uint8_t *mbase, NaClMemorySize sz,
23 uint8_t alignment) {
24 NaClMemorySize i;
25 NaClMemorySize num_halts;
26 for (i = sz - 1; i > 0; --i) {
27 if (kNaClHalt != mbase[i]) break;
28 }
29 num_halts = sz - (i + 1);
30 if (num_halts > kMinHaltKeepLength) {
31 /* May be able to trim off trailing halts. */
32 NaClMemorySize new_size;
33 NaClMemorySize block_overflow;
34 new_size = (sz - num_halts) + kMinHaltKeepLength;
35 /* Round to nearest block alignment. */
36 block_overflow = new_size % alignment;
37 if (block_overflow) {
38 new_size = new_size - block_overflow + alignment;
39 }
40 /* Never increase the segment size. */
41 if (new_size < sz) {
42 return new_size;
43 }
44 }
45 /* No trim performed. */
46 return sz;
47 }
OLDNEW
« no previous file with comments | « src/trusted/validator/x86/halt_trim.h ('k') | src/trusted/validator/x86/halt_trim_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698