]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 1 | /** @file\r |
2 | Implementation of SetJump() on IA-32.\r | |
3 | \r | |
0aac2f77 | 4 | Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r |
bb817c56 | 5 | This program and the accompanying materials\r |
e1f414b6 | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
e4a34497 | 8 | http://opensource.org/licenses/bsd-license.php.\r |
e1f414b6 | 9 | \r |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
1efcc4ae | 15 | \r |
47fc17d8 | 16 | #include "BaseLibInternals.h"\r |
f734a10a | 17 | \r |
42eedea9 | 18 | /**\r |
19 | Worker function that checks ASSERT condition for JumpBuffer\r | |
e1f414b6 | 20 | \r |
42eedea9 | 21 | Checks ASSERT condition for JumpBuffer.\r |
22 | \r | |
23 | If JumpBuffer is NULL, then ASSERT().\r | |
24 | For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().\r | |
25 | \r | |
26 | @param JumpBuffer A pointer to CPU context buffer.\r | |
27 | \r | |
28 | **/\r | |
e1f414b6 | 29 | VOID\r |
30 | EFIAPI\r | |
31 | InternalAssertJumpBuffer (\r | |
32 | IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer\r | |
33 | );\r | |
34 | \r | |
42eedea9 | 35 | /**\r |
36 | Saves the current CPU context that can be restored with a call to LongJump()\r | |
37 | and returns 0.\r | |
38 | \r | |
39 | Saves the current CPU context in the buffer specified by JumpBuffer and\r | |
40 | returns 0. The initial call to SetJump() must always return 0. Subsequent\r | |
41 | calls to LongJump() cause a non-zero value to be returned by SetJump().\r | |
42 | \r | |
43 | If JumpBuffer is NULL, then ASSERT().\r | |
44 | For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().\r | |
45 | \r | |
46 | @param JumpBuffer A pointer to CPU context buffer.\r | |
47 | \r | |
48 | @retval 0 Indicates a return from SetJump().\r | |
49 | \r | |
50 | **/\r | |
e1f414b6 | 51 | _declspec (naked)\r |
2117989c | 52 | RETURNS_TWICE\r |
e1f414b6 | 53 | UINTN\r |
54 | EFIAPI\r | |
55 | SetJump (\r | |
56 | OUT BASE_LIBRARY_JUMP_BUFFER *JumpBuffer\r | |
57 | )\r | |
58 | {\r | |
59 | _asm {\r | |
60 | push [esp + 4]\r | |
61 | call InternalAssertJumpBuffer\r | |
62 | pop ecx\r | |
63 | pop ecx\r | |
64 | mov edx, [esp]\r | |
0aac2f77 JY |
65 | \r |
66 | xor eax, eax\r | |
67 | mov [edx + 24], eax ; save 0 to SSP\r | |
68 | \r | |
69 | mov eax, [PcdGet32 (PcdControlFlowEnforcementPropertyMask)]\r | |
70 | test eax, eax\r | |
71 | jz CetDone\r | |
72 | _emit 0x0F\r | |
73 | _emit 0x20\r | |
74 | _emit 0xE0 ; mov eax, cr4\r | |
75 | bt eax, 23 ; check if CET is enabled\r | |
76 | jnc CetDone\r | |
77 | \r | |
78 | mov eax, 1\r | |
79 | _emit 0xF3\r | |
80 | _emit 0x0F\r | |
81 | _emit 0xAE\r | |
82 | _emit 0xE8 ; INCSSP EAX to read original SSP\r | |
83 | _emit 0xF3\r | |
84 | _emit 0x0F\r | |
85 | _emit 0x1E\r | |
86 | _emit 0xC8 ; READSSP EAX\r | |
87 | mov [edx + 0x24], eax ; save SSP\r | |
88 | \r | |
89 | CetDone:\r | |
90 | \r | |
e1f414b6 | 91 | mov [edx], ebx\r |
92 | mov [edx + 4], esi\r | |
93 | mov [edx + 8], edi\r | |
94 | mov [edx + 12], ebp\r | |
95 | mov [edx + 16], esp\r | |
96 | mov [edx + 20], ecx\r | |
97 | xor eax, eax\r | |
98 | jmp ecx\r | |
99 | }\r | |
100 | }\r | |
101 | \r |