git: 7f49a62e3c5f - main - amd64: add helpers to set up thread state on trap
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 29 Oct 2026 05:49:59 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=7f49a62e3c5ff15d87afcce9ab7fe787319a3f7f
commit 7f49a62e3c5ff15d87afcce9ab7fe787319a3f7f
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-10-29 02:16:42 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-10-29 05:48:49 +0000
amd64: add helpers to set up thread state on trap
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
---
sys/amd64/amd64/trap.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c
index c8df3c5a55c0..788fc6e859f5 100644
--- a/sys/amd64/amd64/trap.c
+++ b/sys/amd64/amd64/trap.c
@@ -356,6 +356,15 @@ static const struct sfhandler sfhandlers[] = {
},
};
+static void
+trap_update_thread(struct thread *td, struct trapframe *frame)
+{
+ td->td_pticks = 0;
+ td->td_frame = frame;
+ if (td->td_cowgen != atomic_load_int(&td->td_proc->p_cowgen))
+ thread_cow_update(td);
+}
+
/*
* Exception, fault, and trap interface to the FreeBSD kernel.
* This common code is called from assembly language IDT gate entry
@@ -404,11 +413,8 @@ trap(struct trapframe *frame)
/* user trap */
trap_check_intr_user(td, frame);
- td->td_pticks = 0;
- td->td_frame = frame;
+ trap_update_thread(td, frame);
addr = frame->tf_rip;
- if (td->td_cowgen != atomic_load_int(&p->p_cowgen))
- thread_cow_update(td);
switch (type) {
case T_PRIVINFLT: /* privileged instruction fault */
@@ -1591,6 +1597,12 @@ trap_fred_u_noperm(struct trapframe_fred *frame, ksiginfo_t *ksi)
ksi->ksi_addr = (void *)frame->tf_idt.tf_rip;
}
+static void
+trap_fred_update_thread(struct thread *td, struct trapframe_fred *frame)
+{
+ trap_update_thread(td, &frame->tf_idt);
+}
+
int fred_verbose_events;
void trap_fred_u(struct trapframe_fred *frame);
@@ -1654,10 +1666,7 @@ trap_fred_u(struct trapframe_fred *frame)
&frame->tf_idt, frame->tf_idt.tf_trapno) != 0)
return;
#endif
- td->td_pticks = 0;
- td->td_frame = &frame->tf_idt;
- if (td->td_cowgen != atomic_load_int(&td->td_proc->p_cowgen))
- thread_cow_update(td);
+ trap_fred_update_thread(td, frame);
trap_fred_handle_u_exc(td, frame, vec, &ksi, &do_trapsig);
break;
case TF_FRED_EVINFO2_TYPE_INTn: