-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8de20e4
commit 048ed27
Showing
8 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//--from | ||
func tryExec() error { | ||
//--to | ||
func tryExec() error { | ||
return fmt.Errorf("can't probe for exec support") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//--from | ||
func HasGoBuild() bool { | ||
//--to | ||
func HasGoBuild() bool { | ||
return false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//--from | ||
static void | ||
threadentry(void *v) | ||
{ | ||
//--to | ||
static int getproccount() { | ||
static int proccount = 0; | ||
if (!proccount) { | ||
SYSTEM_INFO info; | ||
GetSystemInfo(&info); | ||
proccount = info.dwNumberOfProcessors; | ||
} | ||
return proccount; | ||
} | ||
|
||
static void | ||
threadentry(void *v) | ||
{ | ||
SetThreadAffinityMask(GetCurrentThread(), (1<<getproccount())-1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
//--from | ||
//go:cgo_import_dynamic runtime._GetConsoleMode GetConsoleMode%2 "kernel32.dll" | ||
//--to | ||
//--from | ||
//go:cgo_import_dynamic runtime._SetConsoleCtrlHandler SetConsoleCtrlHandler%2 "kernel32.dll" | ||
//--to | ||
//--from | ||
//go:cgo_import_dynamic runtime._WriteConsoleW WriteConsoleW%5 "kernel32.dll" | ||
//--to | ||
//go:cgo_import_dynamic runtime._OutputDebugStringW OutputDebugStringW%1 "kernel32.dll" | ||
//--from | ||
_GetConsoleMode, | ||
//--to | ||
//--from | ||
_SetConsoleCtrlHandler, | ||
//--to | ||
//--from | ||
_WriteConsoleW, | ||
//--to | ||
_OutputDebugStringW, | ||
//--from | ||
// We call these all the way here, late in init, so that malloc works | ||
// for the callback functions these generate. | ||
var fn any = ctrlHandler | ||
ctrlHandlerPC := compileCallback(*efaceOf(&fn), true) | ||
stdcall2(_SetConsoleCtrlHandler, ctrlHandlerPC, 1) | ||
//--to | ||
//--from | ||
func write1(fd uintptr, buf unsafe.Pointer, n int32) int32 { | ||
const ( | ||
_STD_OUTPUT_HANDLE = ^uintptr(10) // -11 | ||
_STD_ERROR_HANDLE = ^uintptr(11) // -12 | ||
) | ||
var handle uintptr | ||
switch fd { | ||
case 1: | ||
handle = stdcall1(_GetStdHandle, _STD_OUTPUT_HANDLE) | ||
case 2: | ||
handle = stdcall1(_GetStdHandle, _STD_ERROR_HANDLE) | ||
default: | ||
// assume fd is real windows handle. | ||
handle = fd | ||
} | ||
isASCII := true | ||
b := (*[1 << 30]byte)(buf)[:n] | ||
for _, x := range b { | ||
if x >= 0x80 { | ||
isASCII = false | ||
break | ||
} | ||
} | ||
|
||
if !isASCII { | ||
var m uint32 | ||
isConsole := stdcall2(_GetConsoleMode, handle, uintptr(unsafe.Pointer(&m))) != 0 | ||
// If this is a console output, various non-unicode code pages can be in use. | ||
// Use the dedicated WriteConsole call to ensure unicode is printed correctly. | ||
if isConsole { | ||
return int32(writeConsole(handle, buf, n)) | ||
} | ||
} | ||
var written uint32 | ||
stdcall5(_WriteFile, handle, uintptr(buf), uintptr(n), uintptr(unsafe.Pointer(&written)), 0) | ||
return int32(written) | ||
} | ||
//--to | ||
func write1(fd uintptr, buf unsafe.Pointer, n int32) int32 { | ||
const ( | ||
_STD_OUTPUT_HANDLE = ^uintptr(10) // -11 | ||
_STD_ERROR_HANDLE = ^uintptr(11) // -12 | ||
) | ||
var handle uintptr | ||
switch fd { | ||
case 1: | ||
handle = stdcall1(_GetStdHandle, _STD_OUTPUT_HANDLE) | ||
case 2: | ||
handle = stdcall1(_GetStdHandle, _STD_ERROR_HANDLE) | ||
default: | ||
// assume fd is real windows handle. | ||
handle = fd | ||
} | ||
if fd == 1 || fd == 2 { | ||
// Note that handle is not used anyway. | ||
return int32(writeConsole(handle, buf, n)) | ||
} | ||
var written uint32 | ||
stdcall5(_WriteFile, handle, uintptr(buf), uintptr(n), uintptr(unsafe.Pointer(&written)), 0) | ||
return int32(written) | ||
} | ||
//--from | ||
func writeConsoleUTF16(handle uintptr, b []uint16) { | ||
l := uint32(len(b)) | ||
if l == 0 { | ||
return | ||
} | ||
var written uint32 | ||
stdcall5(_WriteConsoleW, | ||
handle, | ||
uintptr(unsafe.Pointer(&b[0])), | ||
uintptr(l), | ||
uintptr(unsafe.Pointer(&written)), | ||
0, | ||
) | ||
return | ||
} | ||
//--to | ||
func writeConsoleUTF16(handle uintptr, b []uint16) { | ||
b = b[:len(b)+1] | ||
b[len(b)-1] = 0 | ||
l := uint32(len(b)) | ||
if l <= 1 { | ||
return | ||
} | ||
stdcall1(_OutputDebugStringW, | ||
uintptr(unsafe.Pointer(&b[0])), | ||
) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//--from | ||
func syscall_SyscallN(fn uintptr, args ...uintptr) (r1, r2, err uintptr) { | ||
//--to | ||
func syscall_SyscallN(fn uintptr, args ...uintptr) (r1, r2, err uintptr) { | ||
if fn == 0 { | ||
panic("fn must not be 0 at SyscallN") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//--from | ||
func TestNumCPU(t *testing.T) { | ||
//--to | ||
func TestNumCPU(t *testing.T) { | ||
t.Skip("creating a new process with os.Args[0] doesn't work in this environment") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters