]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 1 | /** @file\r |
2 | Implementation of _LongJump() on IA-32.\r | |
3 | \r | |
0aac2f77 | 4 | Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r |
9344f092 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
e1f414b6 | 6 | \r |
7 | **/\r | |
8 | \r | |
1efcc4ae | 9 | \r |
47fc17d8 | 10 | #include "BaseLibInternals.h"\r |
f734a10a | 11 | \r |
e1f414b6 | 12 | \r |
42eedea9 | 13 | /**\r |
14 | Restores the CPU context that was saved with SetJump().\r | |
15 | \r | |
16 | Restores the CPU context from the buffer specified by JumpBuffer.\r | |
17 | This function never returns to the caller.\r | |
18 | Instead is resumes execution based on the state of JumpBuffer.\r | |
19 | \r | |
20 | @param JumpBuffer A pointer to CPU context buffer.\r | |
21 | @param Value The value to return when the SetJump() context is restored.\r | |
22 | \r | |
23 | **/\r | |
e1f414b6 | 24 | __declspec (naked)\r |
25 | VOID\r | |
26 | EFIAPI\r | |
27 | InternalLongJump (\r | |
28 | IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,\r | |
29 | IN UINTN Value\r | |
30 | )\r | |
31 | {\r | |
32 | _asm {\r | |
0aac2f77 JY |
33 | mov eax, [PcdGet32 (PcdControlFlowEnforcementPropertyMask)]\r |
34 | test eax, eax\r | |
35 | jz CetDone\r | |
36 | _emit 0x0F\r | |
37 | _emit 0x20\r | |
38 | _emit 0xE0 ; mov eax, cr4\r | |
39 | bt eax, 23 ; check if CET is enabled\r | |
40 | jnc CetDone\r | |
41 | \r | |
42 | mov edx, [esp + 4] ; edx = JumpBuffer\r | |
43 | mov edx, [edx + 24] ; edx = target SSP\r | |
44 | _emit 0xF3\r | |
45 | _emit 0x0F\r | |
46 | _emit 0x1E\r | |
47 | _emit 0xC8 ; READSSP EAX\r | |
48 | sub edx, eax ; edx = delta\r | |
49 | mov eax, edx ; eax = delta\r | |
50 | \r | |
51 | shr eax, 2 ; eax = delta/sizeof(UINT32)\r | |
52 | _emit 0xF3\r | |
53 | _emit 0x0F\r | |
54 | _emit 0xAE\r | |
55 | _emit 0xE8 ; INCSSP EAX\r | |
56 | \r | |
57 | CetDone:\r | |
58 | \r | |
e1f414b6 | 59 | pop eax ; skip return address\r |
60 | pop edx ; edx <- JumpBuffer\r | |
61 | pop eax ; eax <- Value\r | |
62 | mov ebx, [edx]\r | |
63 | mov esi, [edx + 4]\r | |
64 | mov edi, [edx + 8]\r | |
65 | mov ebp, [edx + 12]\r | |
66 | mov esp, [edx + 16]\r | |
67 | jmp dword ptr [edx + 20]\r | |
68 | }\r | |
69 | }\r | |
70 | \r |