mb/asus/p8z77-m: Drop GPIO by I/O
[coreboot2.git] / src / arch / x86 / stack_canary_breakpoint.c
blobd1dc3c3658b892edc088db9add84ddb17ce3fd1d
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <arch/breakpoint.h>
4 #include <arch/stack_canary_breakpoint.h>
5 #include <arch/symbols.h>
6 #include <bootstate.h>
7 #include <console/console.h>
8 #include <types.h>
9 #include <symbols.h>
11 static struct breakpoint_handle stack_canary_bp;
13 static int handle_stack_canary_written(struct breakpoint_handle handle, struct eregs *regs)
15 #if ENV_X86_64
16 printk(BIOS_ERR, "Stack corruption detected at rip: 0x%llx\n", regs->rip);
17 #else
18 printk(BIOS_ERR, "Stack corruption detected at eip: 0x%x\n", regs->eip);
19 #endif
20 return 0;
23 static void create_stack_canary_breakpoint(uintptr_t *addr)
25 enum breakpoint_result res =
26 breakpoint_create_data(&stack_canary_bp, addr, sizeof(uintptr_t), true);
28 if (res != BREAKPOINT_RES_OK) {
29 printk(BIOS_ERR, "Failed to create stack canary breakpoint\n");
30 return;
33 breakpoint_set_handler(stack_canary_bp, &handle_stack_canary_written);
34 breakpoint_enable(stack_canary_bp, true);
37 void stack_canary_breakpoint_init(void)
39 uintptr_t *addr;
41 if (CONFIG(RESET_VECTOR_IN_RAM)) {
42 addr = (uintptr_t *)_earlyram_stack;
43 } else if (ENV_CACHE_AS_RAM) {
44 addr = (uintptr_t *)_car_stack;
45 } else {
46 addr = (uintptr_t *)_stack;
49 create_stack_canary_breakpoint(addr);
52 void stack_canary_breakpoint_remove(void)
54 breakpoint_remove(stack_canary_bp);
57 static void stack_canary_breakpoint_remove_hook(void *unused)
59 stack_canary_breakpoint_remove();
62 BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, stack_canary_breakpoint_remove_hook, NULL);
63 BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, stack_canary_breakpoint_remove_hook, NULL);