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

reflect : crash after syscall.FreeLibrary() #24248

Closed
SolarTDX opened this issue Mar 5, 2018 · 5 comments
Closed

reflect : crash after syscall.FreeLibrary() #24248

SolarTDX opened this issue Mar 5, 2018 · 5 comments

Comments

@SolarTDX
Copy link

SolarTDX commented Mar 5, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.10 windows/amd64

gcc 7.3.0

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

windows 7

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\go\
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build018223022=/tmp/go-build -gno-record-gcc-switches

What did you do?

demo.go

package main

import "C"

import (
	"fmt"
	"syscall"
)

//export one
func one(in uintptr) uintptr {
	return in
}

func main() {
	fmt.Println("Please enter some input: ")
l_for:
	for {
		in := ""
		if _, err := fmt.Scanln(&in); err != nil {
			break
		}
		switch in {
		case "wait":
			continue
		case "exit":
			break l_for
		default:
			callOne()
		}
	}
	fmt.Println("success!")
}

func callOne() {
	fmt.Println("in call!")
	var err error
	var h syscall.Handle
	if h, err = syscall.LoadLibrary("one"); err != nil {
		return
	}
	defer syscall.FreeLibrary(h)
	var fn uintptr
	if fn, err = syscall.GetProcAddress(h, "one"); err != nil {
		return
	}
	a, b, c := syscall.Syscall(fn, 1, 0, 0, 0)
	fmt.Println(a, b, c)
	fmt.Println("out call!")
}

I run

D:\go\src\tdx\demo>go build demo.go

D:\go\src\tdx\demo>go build -o one.dll -buildmode=c-shared demo.go

D:\go\src\tdx\demo>demo
Please enter some input:
call
in call!
0 0 The operation completed successfully.
out call!

D:\go\src\tdx\demo>

What did you expect to see?

"success!" in the end of demo

What did you see instead?

crash

@odeke-em
Copy link
Member

odeke-em commented Mar 5, 2018

/cc @alexbrainman @ianlancetaylor

@alexbrainman
Copy link
Member

I think this is a duplicate of #22192

No?

Alex

@SolarTDX
Copy link
Author

SolarTDX commented Mar 5, 2018

@alexbrainman

#22192 This issue can't solve my questions

I think they are different situations

My another project is VS2010 -- exe, Go1.10 -- dll, also crash after "syscall.FreeLibrary()"

In Windbg , I see some threads are running on <Unloaded_one.DLL>, maybe Go-threads of one.dll did not exit after "syscall.FreeLibrary()"
qq 20180305173820

@AlexRouSg
Copy link
Contributor

@alexbrainman
I believe this is #11100 which states that c-shared and plugins once loaded cannot be freed/closed

@alexbrainman
Copy link
Member

#22192 This issue can't solve my questions

I think they are different situations

@SolarTDX issue #22192 is about Go program loading Go DLL. That is what your program above does. Doesn't it? So you get the crash just like user of #22192. That is not supported at this moment.

I believe this is #11100 which states that c-shared and plugins once loaded cannot be freed/closed

@AlexRouSg it is possible. I did not investigate properly. #22192 is bad enough to make program crash immediately. What happens after is not relevant.

Closing this is a duplicate of #22192 and #11100. Please comment if disagree,

Alex

@golang golang locked and limited conversation to collaborators Mar 6, 2019
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

5 participants