svn commit: r232584 - in head/sys/mips: include mips

Juli Mallett jmallett at FreeBSD.org
Tue Mar 6 07:50:45 UTC 2012


Author: jmallett
Date: Tue Mar  6 07:50:45 2012
New Revision: 232584
URL: http://svn.freebsd.org/changeset/base/232584

Log:
  Fix two and a half oversights in COMPAT_FREEBSD32 related to contexts and
  TLS:
  o) The mc_tls field used to store the TLS base when doing context gets and
     restores was left a pointer and not converted to a 32-bit integer.  This
     had the bug of not correctly capturing the TLS value desired by the user,
     and the extra nastiness of making the structure the wrong size.
  o) The mc_tls field was not being saved by sendsig.  As a result, the TLS base
     would always be set to NULL when restoring from a signal handler.
  
  Thanks to gonzo for helping track down a bunch of other TLS bugs that came out
  of tracking these down.

Modified:
  head/sys/mips/include/ucontext.h
  head/sys/mips/mips/freebsd32_machdep.c

Modified: head/sys/mips/include/ucontext.h
==============================================================================
--- head/sys/mips/include/ucontext.h	Tue Mar  6 07:47:28 2012	(r232583)
+++ head/sys/mips/include/ucontext.h	Tue Mar  6 07:50:45 2012	(r232584)
@@ -73,7 +73,7 @@ typedef struct __mcontext32 {
 	int		mc_fpused;
 	int32_t		mc_fpregs[33];
 	int32_t		mc_fpc_eir;
-	void		*mc_tls;
+	int32_t		mc_tls;
 	int		__spare__[8];
 } mcontext32_t;
 

Modified: head/sys/mips/mips/freebsd32_machdep.c
==============================================================================
--- head/sys/mips/mips/freebsd32_machdep.c	Tue Mar  6 07:47:28 2012	(r232583)
+++ head/sys/mips/mips/freebsd32_machdep.c	Tue Mar  6 07:50:45 2012	(r232584)
@@ -222,7 +222,7 @@ get_mcontext32(struct thread *td, mconte
 	for (i = 0; i < 33; i++)
 		mcp->mc_fpregs[i] = mcp64.mc_fpregs[i];
 	mcp->mc_fpc_eir = mcp64.mc_fpc_eir;
-	mcp->mc_tls = mcp64.mc_tls;
+	mcp->mc_tls = (int32_t)(intptr_t)mcp64.mc_tls;
 
 	return (0);
 }
@@ -244,7 +244,7 @@ set_mcontext32(struct thread *td, const 
 	for (i = 0; i < 33; i++)
 		mcp64.mc_fpregs[i] = mcp->mc_fpregs[i];
 	mcp64.mc_fpc_eir = mcp->mc_fpc_eir;
-	mcp64.mc_tls = mcp->mc_tls;
+	mcp64.mc_tls = (void *)(intptr_t)mcp->mc_tls;
 
 	return (set_mcontext(td, &mcp64));
 }
@@ -395,6 +395,7 @@ freebsd32_sendsig(sig_t catcher, ksiginf
 	sf.sf_uc.uc_mcontext.mc_pc = regs.r_regs[PC];
 	sf.sf_uc.uc_mcontext.mullo = regs.r_regs[MULLO];
 	sf.sf_uc.uc_mcontext.mulhi = regs.r_regs[MULHI];
+	sf.sf_uc.uc_mcontext.mc_tls = (int32_t)(intptr_t)td->td_md.md_tls;
 	sf.sf_uc.uc_mcontext.mc_regs[0] = UCONTEXT_MAGIC;  /* magic number */
 	for (i = 1; i < 32; i++)
 		sf.sf_uc.uc_mcontext.mc_regs[i] = regs.r_regs[i];


More information about the svn-src-all mailing list