Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/usermode Implement cpu_lwp_setprivate(). This remov...



details:   https://anonhg.NetBSD.org/src/rev/016bc56b4f96
branches:  trunk
changeset: 319424:016bc56b4f96
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Tue May 29 07:35:39 2018 +0000

description:
Implement cpu_lwp_setprivate(). This removes the need for the cpu_switch()
hack.

Programs with TLS work fine now, including gdb!

diffstat:

 sys/arch/usermode/dev/cpu.c       |  32 +++++++++++++++++++-------------
 sys/arch/usermode/include/types.h |   3 ++-
 2 files changed, 21 insertions(+), 14 deletions(-)

diffs (78 lines):

diff -r a8692be5e1df -r 016bc56b4f96 sys/arch/usermode/dev/cpu.c
--- a/sys/arch/usermode/dev/cpu.c       Tue May 29 07:09:21 2018 +0000
+++ b/sys/arch/usermode/dev/cpu.c       Tue May 29 07:35:39 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.77 2018/05/29 07:09:21 reinoud Exp $ */
+/* $NetBSD: cpu.c,v 1.78 2018/05/29 07:35:40 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -30,7 +30,7 @@
 #include "opt_hz.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.77 2018/05/29 07:09:21 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.78 2018/05/29 07:35:40 reinoud Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -193,6 +193,22 @@
 {
 }
 
+int
+cpu_lwp_setprivate(lwp_t *l, void *ptr)
+{
+       struct pcb *pcb = lwp_getpcb(l);
+
+       /* set both ucontexts up for TLS just in case */
+       pcb->pcb_ucp.uc_mcontext._mc_tlsbase =
+               (uintptr_t) ptr;
+       pcb->pcb_ucp.uc_flags |= _UC_TLSBASE;
+
+       pcb->pcb_userret_ucp.uc_mcontext._mc_tlsbase =
+               (uintptr_t) ptr;
+       pcb->pcb_userret_ucp.uc_flags |= _UC_TLSBASE;
+
+       return 0;
+}
 
 static
 void
@@ -214,18 +230,8 @@
                oldpcb->pcb_errno = thunk_geterrno();
 
        thunk_seterrno(newpcb->pcb_errno);
-
-       /* set both ucontexts up for TLS just in case */
+       curlwp = newlwp;
 
-       newpcb->pcb_ucp.uc_mcontext._mc_tlsbase =
-               (uintptr_t) newlwp->l_private;
-       newpcb->pcb_ucp.uc_flags |= _UC_TLSBASE;
-
-       newpcb->pcb_userret_ucp.uc_mcontext._mc_tlsbase =
-               (uintptr_t) newlwp->l_private;
-       newpcb->pcb_userret_ucp.uc_flags |= _UC_TLSBASE;
-
-       curlwp = newlwp;
        splx(s);
 
        if (thunk_setcontext(&newpcb->pcb_ucp))
diff -r a8692be5e1df -r 016bc56b4f96 sys/arch/usermode/include/types.h
--- a/sys/arch/usermode/include/types.h Tue May 29 07:09:21 2018 +0000
+++ b/sys/arch/usermode/include/types.h Tue May 29 07:35:39 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.12 2017/01/26 15:55:10 christos Exp $ */
+/* $NetBSD: types.h,v 1.13 2018/05/29 07:35:39 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -67,6 +67,7 @@
 #endif
 
 #define __HAVE_CPU_DATA_FIRST
+#define __HAVE_CPU_LWP_SETPRIVATE
 #define __HAVE_MM_MD_KERNACC
 #define        __HAVE_COMPAT_NETBSD32
 



Home | Main Index | Thread Index | Old Index