1 : // Copyright 2015 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #include "syzygy/assm/unittest_util.h"
16 :
17 m : namespace testing {
18 :
19 : // Definitions of various length NOP codes for 32-bit X86. We use the same
20 : // ones that are typically used by MSVC and recommended by Intel in
21 : // the Intel Architecture Software Developer's manual, page 4-8.
22 :
23 : // NOP (XCHG EAX, EAX)
24 m : const uint8 kNop1[1] = { 0x90 };
25 : // 66 NOP
26 m : const uint8 kNop2[2] = { 0x66, 0x90 };
27 : // LEA REG, 0 (REG) (8-bit displacement)
28 m : const uint8 kNop3[3] = { 0x66, 0x66, 0x90 };
29 : // NOP DWORD PTR [EAX + 0] (8-bit displacement)
30 m : const uint8 kNop4[4] = { 0x0F, 0x1F, 0x40, 0x00 };
31 : // NOP DWORD PTR [EAX + EAX*1 + 0] (8-bit displacement)
32 m : const uint8 kNop5[5] = { 0x0F, 0x1F, 0x44, 0x00, 0x00 };
33 : // LEA REG, 0 (REG) (32-bit displacement)
34 m : const uint8 kNop6[6] = { 0x66, 0x0F, 0x1F, 0x44, 0x00, 0x00 };
35 : // LEA REG, 0 (REG) (32-bit displacement)
36 m : const uint8 kNop7[7] = { 0x0F, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00 };
37 : // NOP DWORD PTR [EAX + EAX*1 + 0] (32-bit displacement)
38 m : const uint8 kNop8[8] = { 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 };
39 : // NOP WORD PTR [EAX + EAX*1 + 0] (32-bit displacement)
40 m : const uint8 kNop9[9] = {
41 m : 0x66, // Prefix,
42 m : 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 // kNop8.
43 m : };
44 m : const uint8 kNop10[10] = {
45 m : 0x66, 0x66, // Prefix,
46 m : 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 // kNop8.
47 m : };
48 m : const uint8 kNop11[11] = {
49 m : 0x66, 0x66, 0x66, // Prefix,
50 m : 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 // kNop8.
51 m : };
52 :
53 : // Collect all of the various NOPs in an array indexable by their length.
54 m : const uint8* kNops[12] = { NULL, kNop1, kNop2, kNop3, kNop4, kNop5, kNop6,
55 m : kNop7, kNop8, kNop9, kNop10, kNop11 };
56 :
57 m : } // namespace testing
|