Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: problems running Windows binary under WINE #5831

Closed
hanwen opened this issue Jul 2, 2013 · 22 comments
Closed

runtime: problems running Windows binary under WINE #5831

hanwen opened this issue Jul 2, 2013 · 22 comments

Comments

@hanwen
Copy link
Contributor

hanwen commented Jul 2, 2013

Hi there,

I'm seeing something that looks like a race condition.

Symptoms:

* on Linux, run GOOS=windows go run standalone.go 

=>

...
fatal error: malloc/free - deadlock
[signal 0xc0000005 code=0x0 addr=0x30 pc=0x41f570]

goroutine 1 [chan receive]:
net/rpc.(*Client).Call(0x8de7300, 0x686860, 0x3, 0x5bf0a0, 0x8de0508, ...)
    /home/hanwen/vc/go/src/pkg/net/rpc/client.go:310 +0xa9
main.main()
    /home/hanwen/go/src/barf/standalone.go:47 +0x312
 

* This is on Ubuntu 12.04 on amd64, with the .exe running on Wine 1.4-0ubuntu4.1.

* When applying works.patch, it goes back to working.  I've also bisected this problem
to https://code.google.com/p/go/source/detail?r=f800157ce425

* It's possible that this a Wine problem, but anecdotally, we've seen frequent runtime
crashes on Windows 7 on VMWare with the original program too (dialog box with "your
program has stopped.").

* If this is a Wine problem, what kind of bugreport should I file with the Wine folks?

* I'm on 

parent: 17191:a1fe2e3fadb0 tip
 misc/vim: Add compiler plugin for Go
branch: default
commit: 3 modified, 5 unknown
update: (current)

Attachments:

  1. standalone.go (6484 bytes)
  2. works.patch (2326 bytes)
@hanwen
Copy link
Contributor Author

hanwen commented Jul 2, 2013

Comment 1:

with Dmitry's extra logging patches and GOTRACEBACK=2, I get
goroutine 0 [idle]:
runtime.throw(0x84f4c0)
    /home/hanwen/vc/go/src/pkg/runtime/panic.c:474 +0x74
runtime.mallocgc(0x10, 0x100000000, 0x1)
    /home/hanwen/vc/go/src/pkg/runtime/zmalloc_windows_amd64.c:34 +0x76
runtime.mal(0x10)
    /home/hanwen/vc/go/src/pkg/runtime/zmalloc_windows_amd64.c:665 +0x44
copyin(0x639a40, 0x2975e2a0, 0x2975e2b8)
    /home/hanwen/vc/go/src/pkg/runtime/iface.c:152 +0x64
runtime.convT2E(0x639a40, 0x84db6e, 0x31, 0x639a40, 0x31, ...)
    /home/hanwen/vc/go/src/pkg/runtime/iface.c:220 +0x40
runtime.newErrorString(0x84db6e, 0x31, 0x2975e2f0)
    /home/hanwen/vc/go/src/pkg/runtime/error.go:74 +0x3d
runtime.panicstring(0x84db6e)
    /home/hanwen/vc/go/src/pkg/runtime/panic.c:487 +0x94
runtime.sigpanic()
    /home/hanwen/vc/go/src/pkg/runtime/os_windows.c:303 +0xca
runtime.mallocgc(0x10, 0x100000000, 0x1)
    /home/hanwen/vc/go/src/pkg/runtime/zmalloc_windows_amd64.c:51 +0x110
runtime.mal(0x10)
    /home/hanwen/vc/go/src/pkg/runtime/zmalloc_windows_amd64.c:665 +0x44
copyin(0x639a40, 0x2975e418, 0x2975e430)
    /home/hanwen/vc/go/src/pkg/runtime/iface.c:152 +0x64
runtime.convT2E(0x639a40, 0x84db6e, 0x31, 0x639a40, 0x31, ...)
    /home/hanwen/vc/go/src/pkg/runtime/iface.c:220 +0x40
runtime.newErrorString(0x84db6e, 0x31, 0x2975e468)
    /home/hanwen/vc/go/src/pkg/runtime/error.go:74 +0x3d
runtime.panicstring(0x84db6e)
    /home/hanwen/vc/go/src/pkg/runtime/panic.c:487 +0x94
runtime.sigpanic()
    /home/hanwen/vc/go/src/pkg/runtime/os_windows.c:303 +0xca
runtime.lock(0x852f60)
    /home/hanwen/vc/go/src/pkg/runtime/lock_sema.c:58 +0x14a
exitsyscall0(0x8e1ec60)
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:1467 +0x5b
runtime.mcall()
    /home/hanwen/vc/go/src/pkg/runtime/asm_amd64.s:172 +0x41
goroutine 1 [chan receive]:
runtime.park(0x40bf00, 0x8e40e30, 0x84e654)
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:1224 +0x74
runtime.chanrecv(0x5c5d20, 0x8e40de0, 0x3a1ea8, 0x0, 0x0)
    /home/hanwen/vc/go/src/pkg/runtime/chan.c:391 +0x209
runtime.chanrecv1(0x5c5d20, 0x8e40de0, 0x3, 0x5bf080, 0x8de0d58, ...)
    /home/hanwen/vc/go/src/pkg/runtime/chan.c:452 +0x38
net/rpc.(*Client).Call(0x8de73c0, 0x686840, 0x3, 0x5bf080, 0x8de0d58, ...)
    /home/hanwen/vc/go/src/pkg/net/rpc/client.go:310 +0xa9
main.main()
    /home/hanwen/go/src/barf/standalone.go:47 +0x312
runtime.main()
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:182 +0x9b
runtime.goexit()
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:1276
goroutine 2 [syscall]:
runtime.asmcgocall(0x4246b0, 0x3bfe78, 0x7b8853c0, 0x2, 0x3bfec0, ...)
    /home/hanwen/vc/go/src/pkg/runtime/asm_amd64.s:518 +0x2b
runtime.stdcall(0x7b8853c0, 0x2, 0x68, 0xea60, 0x1ce77351b670632, ...)
    /home/hanwen/vc/go/src/pkg/runtime/os_windows.c:274 +0x3c
runtime.semasleep(0xdf8475800)
    /home/hanwen/vc/go/src/pkg/runtime/os_windows.c:181 +0x64
runtime.notetsleep(0x3bff58, 0xdf8475800)
    /home/hanwen/vc/go/src/pkg/runtime/lock_sema.c:192 +0xfe
runtime.MHeap_Scavenger()
    /home/hanwen/vc/go/src/pkg/runtime/mheap.c:464 +0xb4
runtime.goexit()
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:1276
created by runtime.main
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:165
goroutine 4 [syscall]:
runtime.asmcgocall(0x4246b0, 0x3bddf8, 0x100000000, 0xffffffffffffffff, 0x8e257a0, ...)
    /home/hanwen/vc/go/src/pkg/runtime/asm_amd64.s:518 +0x2b
runtime.cgocall(0x4246b0, 0x3bddf8)
    /home/hanwen/vc/go/src/pkg/runtime/cgocall.c:166 +0x166
syscall.Syscall(0x7b888830, 0x2, 0x84, 0x0, 0x0, ...)
    /home/hanwen/vc/go/src/pkg/runtime/zsyscall_windows_windows_amd64.c:74 +0x57
main.connectNamedPipe(0x84, 0x0, 0x0, 0x0)
    /home/hanwen/go/src/barf/standalone.go:257 +0x73
main.(*PipeListener).AcceptPipe(0x8e228e0, 0x44b8f3, 0x3bdef8, 0x44b8f3)
    /home/hanwen/go/src/barf/standalone.go:147 +0xa3
main.(*PipeListener).Accept(0x8e228e0, 0x36aad0, 0x8e22e80, 0x36aad0, 0x8e22e80)
    /home/hanwen/go/src/barf/standalone.go:124 +0x2a
net/rpc.(*Server).Accept(0x8e234c0, 0x36aa98, 0x8e228e0)
    /home/hanwen/vc/go/src/pkg/net/rpc/server.go:591 +0x3e
runtime.goexit()
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:1276
created by main.main
    /home/hanwen/go/src/barf/standalone.go:36 +0x1a0
goroutine 5 [syscall]:
runtime.asmcgocall(0x4246b0, 0x3bb970, 0x100000000, 0xffffffffffffffff, 0x8de5500, ...)
    /home/hanwen/vc/go/src/pkg/runtime/asm_amd64.s:518 +0x2b
runtime.cgocall(0x4246b0, 0x3bb970)
    /home/hanwen/vc/go/src/pkg/runtime/cgocall.c:166 +0x166
syscall.Syscall6(0x7b84be30, 0x5, 0x80, 0x8e28000, 0x1000, ...)
    /home/hanwen/vc/go/src/pkg/runtime/zsyscall_windows_windows_amd64.c:97 +0x57
syscall.ReadFile(0x80, 0x8e28000, 0x1000, 0x1000, 0x8de0d48, ...)
    /home/hanwen/vc/go/src/pkg/syscall/zsyscall_windows_amd64.go:265 +0xd0
main.(*PipeConn).Read(0x8e22980, 0x8e28000, 0x1000, 0x1000, 0x0, ...)
    /home/hanwen/go/src/barf/standalone.go:186 +0x75
bufio.(*Reader).fill(0x8de7360)
    /home/hanwen/vc/go/src/pkg/bufio/bufio.go:119 +0x122
bufio.(*Reader).Read(0x8de7360, 0x8de6b90, 0x1, 0x9, 0x1, ...)
    /home/hanwen/vc/go/src/pkg/bufio/bufio.go:187 +0x1b5
io.ReadAtLeast(0x36ab80, 0x8de7360, 0x8de6b90, 0x1, 0x9, ...)
    /home/hanwen/vc/go/src/pkg/io/io.go:284 +0xfc
io.ReadFull(0x36ab80, 0x8de7360, 0x8de6b90, 0x1, 0x9, ...)
    /home/hanwen/vc/go/src/pkg/io/io.go:302 +0x74
encoding/gob.decodeUintReader(0x36ab80, 0x8de7360, 0x8de6b90, 0x9, 0x9, ...)
    /home/hanwen/vc/go/src/pkg/encoding/gob/decode.go:65 +0xaf
encoding/gob.(*Decoder).recvMessage(0x8e27000, 0x8e2703c)
    /home/hanwen/vc/go/src/pkg/encoding/gob/decoder.go:73 +0x50
encoding/gob.(*Decoder).decodeTypeSequence(0x8e27000, 0x8e25900, 0x160)
    /home/hanwen/vc/go/src/pkg/encoding/gob/decoder.go:159 +0x4c
encoding/gob.(*Decoder).DecodeValue(0x8e27000, 0x5bff00, 0x8e25960, 0x160, 0x0, ...)
    /home/hanwen/vc/go/src/pkg/encoding/gob/decoder.go:223 +0x106
encoding/gob.(*Decoder).Decode(0x8e27000, 0x5bff00, 0x8e25960, 0x0, 0x0)
    /home/hanwen/vc/go/src/pkg/encoding/gob/decoder.go:202 +0x1c8
net/rpc.(*gobClientCodec).ReadResponseHeader(0x8e257e0, 0x8e25960, 0x0, 0x0)
    /home/hanwen/vc/go/src/pkg/net/rpc/client.go:218 +0x42
net/rpc.(*Client).input(0x8de73c0)
    /home/hanwen/vc/go/src/pkg/net/rpc/client.go:106 +0xbf
runtime.goexit()
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:1276
created by net/rpc.NewClientWithCodec
    /home/hanwen/vc/go/src/pkg/net/rpc/client.go:196 +0x94
goroutine 6 [syscall]:
runtime.asmcgocall(0x4246b0, 0x3b9880, 0x100000000, 0xffffffffffffffff, 0x8de5500, ...)
    /home/hanwen/vc/go/src/pkg/runtime/asm_amd64.s:518 +0x2b
runtime.cgocall(0x4246b0, 0x3b9880)
    /home/hanwen/vc/go/src/pkg/runtime/cgocall.c:166 +0x166
syscall.Syscall6(0x7b84be30, 0x5, 0x7c, 0x8e2a000, 0x1000, ...)
    /home/hanwen/vc/go/src/pkg/runtime/zsyscall_windows_windows_amd64.c:97 +0x57
syscall.ReadFile(0x7c, 0x8e2a000, 0x1000, 0x1000, 0x8de0da0, ...)
    /home/hanwen/vc/go/src/pkg/syscall/zsyscall_windows_amd64.go:265 +0xd0
main.(*PipeConn).Read(0x8e22e80, 0x8e2a000, 0x1000, 0x1000, 0x0, ...)
    /home/hanwen/go/src/barf/standalone.go:186 +0x75
bufio.(*Reader).fill(0x8de7480)
    /home/hanwen/vc/go/src/pkg/bufio/bufio.go:119 +0x122
bufio.(*Reader).Read(0x8de7480, 0x8de6d60, 0x1, 0x9, 0x1, ...)
    /home/hanwen/vc/go/src/pkg/bufio/bufio.go:187 +0x1b5
io.ReadAtLeast(0x36ab80, 0x8de7480, 0x8de6d60, 0x1, 0x9, ...)
    /home/hanwen/vc/go/src/pkg/io/io.go:284 +0xfc
io.ReadFull(0x36ab80, 0x8de7480, 0x8de6d60, 0x1, 0x9, ...)
    /home/hanwen/vc/go/src/pkg/io/io.go:302 +0x74
encoding/gob.decodeUintReader(0x36ab80, 0x8de7480, 0x8de6d60, 0x9, 0x9, ...)
    /home/hanwen/vc/go/src/pkg/encoding/gob/decode.go:65 +0xaf
encoding/gob.(*Decoder).recvMessage(0x8e270f0, 0x8e2712c)
    /home/hanwen/vc/go/src/pkg/encoding/gob/decoder.go:73 +0x50
encoding/gob.(*Decoder).decodeTypeSequence(0x8e270f0, 0x8e22e00, 0x160)
    /home/hanwen/vc/go/src/pkg/encoding/gob/decoder.go:159 +0x4c
encoding/gob.(*Decoder).DecodeValue(0x8e270f0, 0x5bfec0, 0x8e22ee0, 0x160, 0x0, ...)
    /home/hanwen/vc/go/src/pkg/encoding/gob/decoder.go:223 +0x106
encoding/gob.(*Decoder).Decode(0x8e270f0, 0x5bfec0, 0x8e22ee0, 0x0, 0x0)
    /home/hanwen/vc/go/src/pkg/encoding/gob/decoder.go:202 +0x1c8
net/rpc.(*gobServerCodec).ReadRequestHeader(0x8e25990, 0x8e22ee0, 0x8, 0x100000001)
    /home/hanwen/vc/go/src/pkg/net/rpc/server.go:398 +0x42
net/rpc.(*Server).readRequestHeader(0x8e234c0, 0x36ac70, 0x8e25990, 0x0, 0x0, ...)
    /home/hanwen/vc/go/src/pkg/net/rpc/server.go:549 +0x9e
net/rpc.(*Server).readRequest(0x8e234c0, 0x36ac70, 0x8e25990, 0x8de9400, 0x8e2d0e0, ...)
    /home/hanwen/vc/go/src/pkg/net/rpc/server.go:516 +0xa3
net/rpc.(*Server).ServeCodec(0x8e234c0, 0x36ac70, 0x8e25990)
    /home/hanwen/vc/go/src/pkg/net/rpc/server.go:435 +0x69
net/rpc.(*Server).ServeConn(0x8e234c0, 0x36aad0, 0x8e22e80)
    /home/hanwen/vc/go/src/pkg/net/rpc/server.go:427 +0x143
runtime.goexit()
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:1276
created by net/rpc.(*Server).Accept
    /home/hanwen/vc/go/src/pkg/net/rpc/server.go:595 +0x193
goroutine 12 [finalizer wait]:
runtime.park(0x40bf00, 0x851718, 0x84fc5c)
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:1224 +0x74
runfinq()
    /home/hanwen/vc/go/src/pkg/runtime/mgc0.c:2259 +0x87
runtime.goexit()
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:1276
created by runtime.gc
    /home/hanwen/vc/go/src/pkg/runtime/mgc0.c:1949
goroutine 8 [syscall]:
runtime.asmcgocall(0x4246b0, 0x29641ea0, 0x100000000, 0xffffffffffffffff, 0x8de5890, ...)
    /home/hanwen/vc/go/src/pkg/runtime/asm_amd64.s:518 +0x2b
runtime.cgocall(0x4246b0, 0x29641ea0)
    /home/hanwen/vc/go/src/pkg/runtime/cgocall.c:166 +0x166
syscall.Syscall6(0x7b88a760, 0x5, 0x94, 0x8e2d220, 0x8de0948, ...)
    /home/hanwen/vc/go/src/pkg/runtime/zsyscall_windows_windows_amd64.c:97 +0x57
syscall.GetQueuedCompletionStatus(0x94, 0x8e2d220, 0x8de0948, 0x8de0940, 0xffffffff, ...)
    /home/hanwen/vc/go/src/pkg/syscall/zsyscall_windows_amd64.go:508 +0xa1
net.(*resultSrv).Run(0x8de0938)
    /home/hanwen/vc/go/src/pkg/net/fd_windows.go:150 +0x153
runtime.goexit()
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:1276
created by net.startServer
    /home/hanwen/vc/go/src/pkg/net/fd_windows.go:285 +0x111
goroutine 24 [runnable]:
runtime.exitsyscall()
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:1453 +0x167
runtime.cgocall(0x4246b0, 0x3ef2d0)
    /home/hanwen/vc/go/src/pkg/runtime/cgocall.c:167 +0x16b
syscall.Syscall9(0x7ff34e1b9d80, 0x7, 0xd4, 0x8e4626c, 0x10, ...)
    /home/hanwen/vc/go/src/pkg/runtime/zsyscall_windows_windows_amd64.c:123 +0x57
syscall.connectEx(0xd4, 0x8e4626c, 0x10, 0x0, 0x0, ...)
    /home/hanwen/vc/go/src/pkg/syscall/syscall_windows.go:751 +0xbf
syscall.ConnectEx(0xd4, 0x36ad68, 0x8e46260, 0x0, 0x0, ...)
    /home/hanwen/vc/go/src/pkg/syscall/syscall_windows.go:771 +0x192
net.(*connectOp).Submit(0x8e45280, 0x8e45280, 0x848680)
    /home/hanwen/vc/go/src/pkg/net/fd_windows.go:360 +0x5e
net.(*ioSrv).ExecIO(0x8e2e0f0, 0x36ad90, 0x8e45280, 0x0, 0x0, ...)
    /home/hanwen/vc/go/src/pkg/net/fd_windows.go:210 +0x207
net.(*netFD).connect(0x8e16f00, 0x0, 0x0, 0x36ad68, 0x8e46260, ...)
    /home/hanwen/vc/go/src/pkg/net/fd_windows.go:389 +0x22c
net.socket(0x6907a0, 0x3, 0x2, 0x1, 0x0, ...)
    /home/hanwen/vc/go/src/pkg/net/sock_posix.go:60 +0x348
net.internetSocket(0x6907a0, 0x3, 0x0, 0x0, 0x36a5d0, ...)
    /home/hanwen/vc/go/src/pkg/net/ipsock_posix.go:146 +0x42a
net.dialTCP(0x6907a0, 0x3, 0x0, 0x8e472a0, 0x0, ...)
    /home/hanwen/vc/go/src/pkg/net/tcpsock_posix.go:151 +0x118
net.dial(0x6907a0, 0x3, 0x6a0950, 0xc, 0x0, ...)
    /home/hanwen/vc/go/src/pkg/net/dial.go:156 +0x3d5
net.resolveAndDial(0x6907a0, 0x3, 0x6a0950, 0xc, 0x0, ...)
    /home/hanwen/vc/go/src/pkg/net/fd_windows.go:67 +0x204
net.(*Dialer).Dial(0x8e47210, 0x6907a0, 0x3, 0x6a0950, 0xc, ...)
    /home/hanwen/vc/go/src/pkg/net/dial.go:146 +0x97
net.Dial(0x6907a0, 0x3, 0x6a0950, 0xc, 0x358000, ...)
    /home/hanwen/vc/go/src/pkg/net/dial.go:131 +0x64
main.(*F).L(0x863ef0, 0x8de0d88, 0x8de0d98, 0x0, 0x0)
    /home/hanwen/go/src/barf/standalone.go:19 +0x50
----- stack segment boundary -----
reflect.Value.call(0x6198e0, 0x6271b0, 0x130, 0x685a80, 0x4, ...)
    /home/hanwen/vc/go/src/pkg/reflect/value.go:474 +0xea4
reflect.Value.Call(0x6198e0, 0x6271b0, 0x130, 0x3efee8, 0x3, ...)
    /home/hanwen/vc/go/src/pkg/reflect/value.go:345 +0xa0
net/rpc.(*service).call(0x8e23540, 0x8e234c0, 0x8de0588, 0x8de9400, 0x8e2d0e0, ...)
    /home/hanwen/vc/go/src/pkg/net/rpc/server.go:379 +0x130
runtime.goexit()
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:1276
created by net/rpc.(*Server).ServeCodec
    /home/hanwen/vc/go/src/pkg/net/rpc/server.go:450 +0x381
exit status 2

@hanwen
Copy link
Contributor Author

hanwen commented Jul 2, 2013

Comment 2:

Also reproduces with wine-1.5.27-1.fc19.x86_64

@alexbrainman
Copy link
Member

Comment 3:

hanwen,
Can you, please, try this (amd64 only):
diff --git a/src/pkg/runtime/os_windows.c b/src/pkg/runtime/os_windows.c
--- a/src/pkg/runtime/os_windows.c
+++ b/src/pkg/runtime/os_windows.c
@@ -275,6 +275,14 @@
    return (void*)c.r1;
 }
 
+#pragma textflag 7
+void
+runtime·osyield(void)
+{
+   extern void runtime·asmosyield(void*);
+   runtime·asmcgocall(runtime·asmosyield, nil);
+}
+
 uint32
 runtime·issigpanic(uint32 code)
 {
diff --git a/src/pkg/runtime/sys_windows_amd64.s b/src/pkg/runtime/sys_windows_amd64.s
--- a/src/pkg/runtime/sys_windows_amd64.s
+++ b/src/pkg/runtime/sys_windows_amd64.s
@@ -322,7 +322,7 @@
 TEXT runtime·remove_exception_handler(SB),7,$0
    RET
 
-TEXT runtime·osyield(SB),7,$8
+TEXT runtime·asmosyield(SB),7,$8
    // Tried NtYieldExecution but it doesn't yield hard enough.
    // NtWaitForSingleObject being used here as Sleep(0).
    // The CALL is safe because NtXxx is a system call wrapper:
See if this fixes your problem. I am not certain I didn't miss something. But if that
works, we will ask others to review it.
Alex

@hanwen
Copy link
Contributor Author

hanwen commented Jul 10, 2013

Comment 4:

Yes, this seems to fix things.

@minux
Copy link
Member

minux commented Jul 10, 2013

Comment 5:

can we make it only do cgocall when running under wine?
the original code is fine for normal windows, and arguably, this is a
bug of wine not emulating export functions in ntdll.dll well enough.

@rsc
Copy link
Contributor

rsc commented Jul 11, 2013

Comment 6:

See my reply on https://golang.org/cl/7563043.
If someone can make it work, it should be cheap enough to do always.

@alexbrainman
Copy link
Member

Comment 7:

Russ,
Here is CL https://golang.org/cl/11266043/ that changes both usleep and osyield
to run on os stack. But it is crashing in misc/cgo/test during cgo callback, because m
is not set (see below). It is crashing in usleep, not osyield, but I think it just
matter of luck. So I think we cannot assume m is set, therefore we cannot switch stacks
here.
Alex
C:\go\root\misc\cgo\test>c:\bin\gdb --args  test.test.exe -test.run=Cthread
GNU gdb (GDB) 7.5.50.20130118
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>;
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>;.
This binary was built by Equation Solution <http://www.Equation.com>;...
Reading symbols from C:\go\root\misc\cgo\test\test.test.exe...done.
(gdb) r
Starting program: C:\go\root\misc\cgo\test\test.test.exe "-test.run=Cthread"
[New Thread 4788.0x9c0]
[New Thread 4788.0xeb8]
[New Thread 4788.0x1848]
[New Thread 4788.0x1210]
[New Thread 4788.0xaa4]
[New Thread 4788.0x638]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 4788.0x638]
runtime.usleep1 (duration=void)
    at C:/go/root/src/pkg/runtime/sys_windows_386.s:338
338             MOVL    m(CX), BP
(gdb) disas
Dump of assembler code for function runtime.usleep1:
   0x00420b00 <+0>:     mov    0x4(%esp),%ebx
   0x00420b04 <+4>:     mov    $0x420b30,%eax
   0x00420b09 <+9>:     mov    %fs:0x14,%ecx
=> 0x00420b10 <+16>:    mov    0x4(%ecx),%ebp
   0x00420b13 <+19>:    mov    0x0(%ebp),%esi
   0x00420b16 <+22>:    cmp    %esi,(%ecx)
   0x00420b18 <+24>:    jne    0x420b1d <runtime.usleep1+29>
   0x00420b1a <+26>:    call   *%eax
   0x00420b1c <+28>:    ret
   0x00420b1d <+29>:    mov    0x10(%esi),%esi
   0x00420b20 <+32>:    mov    %esp,-0x4(%esi)
   0x00420b23 <+35>:    lea    -0x4(%esi),%esp
   0x00420b26 <+38>:    call   *%eax
   0x00420b28 <+40>:    mov    (%esp),%esp
   0x00420b2b <+43>:    ret
End of assembler dump.
(gdb) info reg
eax            0x420b30 4328240
ecx            0x0      0
edx            0x0      0
ebx            0xa      10
esp            0x314afeb0       0x314afeb0
ebp            0x314aff30       0x314aff30
esi            0xa      10
edi            0x0      0
eip            0x420b10 0x420b10 <runtime.usleep1+16>
eflags         0x10206  [ PF IF RF ]
cs             0x1b     27
ss             0x23     35
ds             0x23     35
es             0x23     35
fs             0x3b     59
gs             0x0      0
(gdb) bt
#0  runtime.usleep1 (duration=void)
    at C:/go/root/src/pkg/runtime/sys_windows_386.s:338
#1  0x00410442 in runtime.usleep (us=void)
    at C:/go/root/src/pkg/runtime/os_windows.c:292
#2  0x00413dcd in lockextra (nilokay=void)
    at C:/go/root/src/pkg/runtime/proc.c:765
#3  0x00413b31 in runtime.needm (x=void)
    at C:/go/root/src/pkg/runtime/proc.c:625
#4  0x0041ff8c in runtime.cgocallback_gofunc (fn=void, frame=void,
    framesize=void) at C:/go/root/src/pkg/runtime/asm_386.s:533
#5  0x0041ff61 in runtime.cgocallback (fn=void, frame=void, framesize=void)
    at C:/go/root/src/pkg/runtime/asm_386.s:511
#6  0x00433050 in _cgoexp_a69528917655_Add (a=void, n=void)
    at C:/DOCUME~1/brainman/LOCALS~1/Temp/go-build810375227/_/C_/go/root/misc/cgo/test/_test/_cgo_defun.c:446
#7  0x0048b72b in crosscall2 () at C:/go/root/src/pkg/runtime/cgo/asm_386.s:22
#8  0x00000000 in ?? ()
(gdb)

@minux
Copy link
Member

minux commented Jul 15, 2013

Comment 8:

you're right. both osyield and usleep are in the call path of runtime.needm where it's
running on unknown C stack, so they can't use m or g.
i'm afraid even runtime·asmcgocall won't fix the problem.

@alexbrainman
Copy link
Member

Comment 9:

runtime·asmcgocall will do the same. And I run out of stack when I use
runtime·asmcgocall to call usleep - I tried that first.
Alex

Status changed to Accepted.

@dvyukov
Copy link
Member

dvyukov commented Jul 15, 2013

Comment 10:

I suspect there are many more OS functions that can be called with limited stack (not on
g0 stack). E.g. chan operations use mutexes which use Events; chan operations make
goroutines runnable which can trigger OS thread creation.

@dvyukov
Copy link
Member

dvyukov commented Jul 15, 2013

Comment 11:

>runtime.needm where it's running on unknown C stack, so they can't use m or g.
If there is no m, then you can simply skip stack switch -- C stack should be large
enough to call OS functions.

@rsc
Copy link
Contributor

rsc commented Jul 15, 2013

Comment 12:

Yes, please try not switching when m is nil.

@alexbrainman
Copy link
Member

Comment 13:

Done: https://golang.org/cl/11266043/
Alex

Status changed to Started.

@alexbrainman
Copy link
Member

Comment 14:

This issue was closed by revision 45cff65.

Status changed to Fixed.

@hanwen
Copy link
Contributor Author

hanwen commented Jul 16, 2013

Comment 15:

my repro case now seems to pass without problems (thanks!), but the stdlib test suite
still barfs, eg. 
$ GOOS=windows go test unicode/utf16
fatal error: malloc/free - deadlock
[signal 0xc0000005 code=0x0 addr=0x30 pc=0x41dfb0]
goroutine 1 [running]:
    goroutine running on other thread; stack unavailable
goroutine 2 [runnable]:
runtime.MHeap_Scavenger()
    /home/hanwen/vc/go/src/pkg/runtime/mheap.c:438
runtime.goexit()
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:1289
created by runtime.main
    /home/hanwen/vc/go/src/pkg/runtime/proc.c:165
FAIL    unicode/utf16   4.575s

@alexbrainman
Copy link
Member

Comment 16:

hanwenn,
Your stack dump is not very useful. I have seen "stack unavailable" message before
https://golang.org/issue/5873. Please try and see if you can get
better stack trace somehow. Perhaps use gdb to discover where it fails.
Thank you.
Alex

Status changed to Accepted.

@remyoudompheng
Copy link
Contributor

Comment 17:

Labels changed: added os-windows.

@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 18:

Once issue #5873 is fixed maybe we can get more information about Han-Wen's current
problem.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 19:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 20:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 21:

Labels changed: added repo-main.

@rsc rsc removed the os-windows label Apr 10, 2015
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc added OS-Windows and removed accepted labels Apr 14, 2015
@AlekSi
Copy link
Contributor

AlekSi commented Jul 5, 2016

Linked issue #5873 is fixed.

@thanm thanm closed this as completed Dec 12, 2022
@golang golang locked and limited conversation to collaborators Dec 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants