Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
cet.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 */
7
8#ifndef ZEPHYR_INCLUDE_ARCH_X86_CET_H_
9#define ZEPHYR_INCLUDE_ARCH_X86_CET_H_
10
11#ifndef _ASMLANGUAGE
12
13#ifdef CONFIG_HW_SHADOW_STACK
14
15extern FUNC_NORETURN void z_thread_entry(k_thread_entry_t entry,
16 void *p1, void *p2, void *p3);
17
18typedef uintptr_t arch_thread_hw_shadow_stack_t;
19
20#define ARCH_THREAD_HW_SHADOW_STACK_SIZE(size_) \
21 MAX(ROUND_UP((CONFIG_HW_SHADOW_STACK_PERCENTAGE_SIZE * (size_) / 100), \
22 CONFIG_X86_CET_SHADOW_STACK_ALIGNMENT), \
23 CONFIG_HW_SHADOW_STACK_MIN_SIZE)
24
25#define ARCH_THREAD_HW_SHADOW_STACK_DECLARE(sym, size) \
26 extern arch_thread_hw_shadow_stack_t sym[size / sizeof(arch_thread_hw_shadow_stack_t)]
27
28#define ARCH_THREAD_HW_SHADOW_STACK_ARRAY_DECLARE(sym, nmemb, size) \
29 extern arch_thread_hw_shadow_stack_t \
30 sym[nmemb][size / sizeof(arch_thread_hw_shadow_stack_t)]
31
32#define ARCH_THREAD_HW_SHADOW_STACK_ARRAY_DEFINE(name, nmemb, size) \
33 arch_thread_hw_shadow_stack_t Z_GENERIC_SECTION(.x86shadowstack.arr_ ##name) \
34 __aligned(CONFIG_X86_CET_SHADOW_STACK_ALIGNMENT) \
35 name[MAX(nmemb, 1)][size / sizeof(arch_thread_hw_shadow_stack_t)] = \
36 { \
37 [0][0] = nmemb, \
38 }
39
40#ifdef CONFIG_X86_64
41#define ARCH_THREAD_HW_SHADOW_STACK_DEFINE(name, size) \
42 arch_thread_hw_shadow_stack_t Z_GENERIC_SECTION(.x86shadowstack) \
43 __aligned(CONFIG_X86_CET_SHADOW_STACK_ALIGNMENT) \
44 name[size / sizeof(arch_thread_hw_shadow_stack_t)] = \
45 { [size / sizeof(arch_thread_hw_shadow_stack_t) - 5] = \
46 (uintptr_t)name + size - 4 * sizeof(arch_thread_hw_shadow_stack_t) + 1, \
47 [size / sizeof(arch_thread_hw_shadow_stack_t) - 4] = \
48 (uintptr_t)name + size - 1 * sizeof(arch_thread_hw_shadow_stack_t), \
49 [size / sizeof(arch_thread_hw_shadow_stack_t) - 3] = \
50 (uintptr_t)z_thread_entry, \
51 [size / sizeof(arch_thread_hw_shadow_stack_t) - 2] = \
52 (uintptr_t)X86_KERNEL_CS }
53
54#else /* CONFIG_X86_64 */
55
56#ifdef CONFIG_X86_DEBUG_INFO
57extern void z_x86_thread_entry_wrapper(k_thread_entry_t entry,
58 void *p1, void *p2, void *p3);
59#define ___x86_entry_point z_x86_thread_entry_wrapper
60#else
61#define ___x86_entry_point z_thread_entry
62#endif
63
64#define ARCH_THREAD_HW_SHADOW_STACK_DEFINE(name, size) \
65 arch_thread_hw_shadow_stack_t Z_GENERIC_SECTION(.x86shadowstack) \
66 __aligned(CONFIG_X86_CET_SHADOW_STACK_ALIGNMENT) \
67 name[size / sizeof(arch_thread_hw_shadow_stack_t)] = \
68 { [size / sizeof(arch_thread_hw_shadow_stack_t) - 4] = \
69 (uintptr_t)name + size - 2 * sizeof(arch_thread_hw_shadow_stack_t), \
70 [size / sizeof(arch_thread_hw_shadow_stack_t) - 3] = 0, \
71 [size / sizeof(arch_thread_hw_shadow_stack_t) - 2] = \
72 (uintptr_t)___x86_entry_point, \
73 }
74#endif /* CONFIG_X86_64 */
75
76int arch_thread_hw_shadow_stack_attach(struct k_thread *thread,
77 arch_thread_hw_shadow_stack_t *stack,
78 size_t stack_size);
79
80#endif /* CONFIG_HW_SHADOW_STACK */
81
82#endif /* _ASMLANGUAGE */
83#endif /* ZEPHYR_INCLUDE_ARCH_X86_CET_H_ */
void(* k_thread_entry_t)(void *p1, void *p2, void *p3)
Thread entry point function type.
Definition arch_interface.h:48
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Thread Structure.
Definition thread.h:262