The branch stable/14 has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=4937026659c6b2bfad27ad5392c439048fc03b76

commit 4937026659c6b2bfad27ad5392c439048fc03b76
Author:     Konstantin Belousov <k...@freebsd.org>
AuthorDate: 2025-05-22 06:56:24 +0000
Commit:     Konstantin Belousov <k...@freebsd.org>
CommitDate: 2025-06-12 18:02:50 +0000

    amd64: add ptrace PT_{GET,SET}TLSBASE requests
    
    (cherry picked from commit 7171e591a4c70eb4ee616e33373fd62773ad5a08)
---
 sys/amd64/amd64/ptrace_machdep.c | 21 +++++++++++++++++++++
 sys/x86/include/ptrace.h         |  2 ++
 2 files changed, 23 insertions(+)

diff --git a/sys/amd64/amd64/ptrace_machdep.c b/sys/amd64/amd64/ptrace_machdep.c
index 3fce9826b882..0159c6de49d9 100644
--- a/sys/amd64/amd64/ptrace_machdep.c
+++ b/sys/amd64/amd64/ptrace_machdep.c
@@ -373,6 +373,27 @@ cpu_ptrace(struct thread *td, int req, void *addr, int 
data)
                cpu_ptrace_setbase(td, req, rv);
                break;
 
+       case PT_GETTLSBASE:
+               pcb = td->td_pcb;
+               if ((pcb->pcb_flags & PCB_TLSBASE) != 0)
+                       error = copyout(&pcb->pcb_tlsbase, addr, sizeof(*r));
+               else
+                       error = ESRCH;
+               break;
+
+       case PT_SETTLSBASE:
+               pcb = td->td_pcb;
+               error = copyin(addr, &rv, sizeof(rv));
+               if (error != 0)
+                       break;
+               if (rv >= td->td_proc->p_sysent->sv_maxuser) {
+                       error = EINVAL;
+                       break;
+               }
+               pcb->pcb_tlsbase = rv;
+               set_pcb_flags(pcb, PCB_TLSBASE);
+               break;
+
        default:
                error = EINVAL;
                break;
diff --git a/sys/x86/include/ptrace.h b/sys/x86/include/ptrace.h
index 36ce8870df35..0d5b57234523 100644
--- a/sys/x86/include/ptrace.h
+++ b/sys/x86/include/ptrace.h
@@ -56,6 +56,8 @@
 #define        PT_SETFSBASE    (PT_FIRSTMACH + 8)
 #define        PT_GETGSBASE    (PT_FIRSTMACH + 9)
 #define        PT_SETGSBASE    (PT_FIRSTMACH + 10)
+#define        PT_GETTLSBASE   (PT_FIRSTMACH + 11)
+#define        PT_SETTLSBASE   (PT_FIRSTMACH + 12)
 
 /* Argument structure for PT_GETXSTATE_INFO. */
 struct ptrace_xstate_info {

Reply via email to