From: Akshat Kumar Date: Fri, 5 Oct 2012 20:23:30 +0000 (-0400) Subject: runtime: mask SSE exceptions on plan9/amd64 X-Git-Tag: go1.1rc2~2249 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=23599ca2f6a25aa43c24e24962dcd7616a83d508;p=gostls13.git runtime: mask SSE exceptions on plan9/amd64 The Go run-time assumes that all SSE floating-point exceptions are masked so that Go programs are not broken by such invalid operations. By default, the 64-bit version of the Plan 9 kernel masks only some SSE floating-point exceptions. Here, we mask them all on a per-thread basis. R=rsc, rminnich, minux.ma CC=golang-dev https://golang.org/cl/6592056 --- diff --git a/src/pkg/runtime/os_plan9.h b/src/pkg/runtime/os_plan9.h index ce746b3f3d..7002897efa 100644 --- a/src/pkg/runtime/os_plan9.h +++ b/src/pkg/runtime/os_plan9.h @@ -18,6 +18,7 @@ int32 runtime·plan9_semrelease(uint32 *addr, int32 count); int32 runtime·notify(void (*fn)(void*, byte*)); int32 runtime·noted(int32); void runtime·gonote(void*, byte*); +void runtime·setfpmasks(void); /* open */ enum diff --git a/src/pkg/runtime/sys_plan9_386.s b/src/pkg/runtime/sys_plan9_386.s index cdcf0b2798..1b4d52be1f 100644 --- a/src/pkg/runtime/sys_plan9_386.s +++ b/src/pkg/runtime/sys_plan9_386.s @@ -110,3 +110,7 @@ TEXT runtime·rfork(SB),7,$0 CALL SI // fn() CALL runtime·exit(SB) RET + +// Only used by the 64-bit runtime. +TEXT runtime·setfpmasks(SB),7,$0 + RET diff --git a/src/pkg/runtime/sys_plan9_amd64.s b/src/pkg/runtime/sys_plan9_amd64.s index f376620924..d2ccfb2328 100644 --- a/src/pkg/runtime/sys_plan9_amd64.s +++ b/src/pkg/runtime/sys_plan9_amd64.s @@ -121,3 +121,12 @@ TEXT runtime·rfork(SB),7,$0 // This is needed by asm_amd64.s TEXT runtime·settls(SB),7,$0 RET + +TEXT runtime·setfpmasks(SB),7,$8 + STMXCSR 0(SP) + MOVL 0(SP), AX + ANDL $~0x3F, AX + ORL $(0x3F<<7), AX + MOVL AX, 0(SP) + LDMXCSR 0(SP) + RET diff --git a/src/pkg/runtime/thread_plan9.c b/src/pkg/runtime/thread_plan9.c index 5098864680..6fd1ba7225 100644 --- a/src/pkg/runtime/thread_plan9.c +++ b/src/pkg/runtime/thread_plan9.c @@ -14,6 +14,9 @@ int32 runtime·postnote(int32, int8*); void runtime·minit(void) { + // Mask all SSE floating-point exceptions + // when running on the 64-bit kernel. + runtime·setfpmasks(); } static int32