Module Name: src
Committed By: reinoud
Date: Tue May 29 07:35:40 UTC 2018
Modified Files:
src/sys/arch/usermode/dev: cpu.c
src/sys/arch/usermode/include: types.h
Log Message:
Implement cpu_lwp_setprivate(). This removes the need for the cpu_switch()
hack.
Programs with TLS work fine now, including gdb!
To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/usermode/dev/cpu.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/usermode/include/types.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/usermode/dev/cpu.c
diff -u src/sys/arch/usermode/dev/cpu.c:1.77 src/sys/arch/usermode/dev/cpu.c:1.78
--- src/sys/arch/usermode/dev/cpu.c:1.77 Tue May 29 07:09:21 2018
+++ src/sys/arch/usermode/dev/cpu.c Tue May 29 07:35:40 2018
@@ -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 <[email protected]>
@@ -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 @@ cpu_need_proftick(struct lwp *l)
{
}
+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 @@ cpu_switchto_atomic(lwp_t *oldlwp, lwp_t
oldpcb->pcb_errno = thunk_geterrno();
thunk_seterrno(newpcb->pcb_errno);
-
- /* set both ucontexts up for TLS just in case */
-
- 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))
Index: src/sys/arch/usermode/include/types.h
diff -u src/sys/arch/usermode/include/types.h:1.12 src/sys/arch/usermode/include/types.h:1.13
--- src/sys/arch/usermode/include/types.h:1.12 Thu Jan 26 15:55:10 2017
+++ src/sys/arch/usermode/include/types.h Tue May 29 07:35:39 2018
@@ -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 <[email protected]>
@@ -67,6 +67,7 @@ typedef long int __register_t;
#endif
#define __HAVE_CPU_DATA_FIRST
+#define __HAVE_CPU_LWP_SETPRIVATE
#define __HAVE_MM_MD_KERNACC
#define __HAVE_COMPAT_NETBSD32