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: avoid functions forbidden on Windows 10 UWP #21805

Open
maxhora opened this issue Sep 8, 2017 · 16 comments
Open

runtime: avoid functions forbidden on Windows 10 UWP #21805

maxhora opened this issue Sep 8, 2017 · 16 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@maxhora
Copy link

maxhora commented Sep 8, 2017

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

go version go1.9 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\maxr\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\maxr\AppData\Local\Temp\go-build474350779=/tmp/go-build -gno-record-gcc-switches
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

What did you do?

  1. Created static library with func defined in Go and exported to be used in C++
    Command line: go build -buildmode=c-archive puregodll.go

  2. Linked puregodll.a static library generated on previous step into the shared MinGW dll library.
    Command line:

gcc -dumpspecs | sed -e 's/-lmingwex/-lwinstorecompat -lmingwex -lwinstorecompat -lole32 -lruntimeobject/' >./specfile
gcc -specs=./specfile -shared -o goDLL.dll goDLL.c -Wl,--dynamicbase -Wl,--whole-archive puregodll.a -Wl,--no-whole-archive -lWinMM -lntdll -lWS2_32 -lsetupapi

It produces goDLL.dll as result.

  1. Running script to adjust binary PE header of produced goDLL.dll to be compatible with Windows 10 UWP platform (it expects appcontainer bit set in PE header)

  2. Created Windows 10 UWP project with latest Visual Studio 2017 and P/Invoke goDLL.dll to call func initially defined in puregodll.go

  3. Run Windows Store Certification Kit for Supported APIs Test on generated Windows Store appx bundle and getting list of forbidden API calls, it seems, used in go-runtime:

API AddVectoredExceptionHandler in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API ExitProcess in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API FreeEnvironmentStringsW in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API GetConsoleMode in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API GetEnvironmentStringsW in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API GetProcessAffinityMask in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API GetStdHandle in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API LoadLibraryA in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API RtlAddFunctionTable in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API RtlCaptureContext in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API RtlVirtualUnwind in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API SetConsoleCtrlHandler in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API SetProcessPriorityBoost in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API VirtualAlloc in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API WriteConsoleW in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API timeBeginPeriod in winmm.dll is not supported for this application type. goDLL.dll calls this API.
API timeEndPeriod in winmm.dll is not supported for this application type. goDLL.dll calls this API.

What did you expect to see?

I expect to have a way for go runtime to not use API calls which are forbidden on Windows 10 UWP platform

@maxhora maxhora changed the title Consuming MinGW DLL to Windows 10 UWP application and passing Certification Kit security checks Consuming MinGW DLL with Go Runtime to Windows 10 UWP application and passing Certification Kit security checks Sep 8, 2017
@alexbrainman
Copy link
Member

API AddVectoredExceptionHandler in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API ExitProcess in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API FreeEnvironmentStringsW in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API GetConsoleMode in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API GetEnvironmentStringsW in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API GetProcessAffinityMask in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API GetStdHandle in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API LoadLibraryA in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API RtlAddFunctionTable in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API RtlCaptureContext in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API RtlVirtualUnwind in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API SetConsoleCtrlHandler in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API SetProcessPriorityBoost in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API VirtualAlloc in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API WriteConsoleW in kernel32.dll is not supported for this application type. goDLL.dll calls this API.
API timeBeginPeriod in winmm.dll is not supported for this application type. goDLL.dll calls this API.
API timeEndPeriod in winmm.dll is not supported for this application type. goDLL.dll calls this API.

What are the replacement functions that provide this functionality on Windows 10 UWP?

I expect to have a way for go runtime to not use API calls which are forbidden on Windows 10 UWP platform

I don't think Go is supported on Windows 10 UWP platform. What is that you are building for Windows 10 UWP?

Alex

@maxhora
Copy link
Author

maxhora commented Sep 9, 2017

Hello @alexbrainman ,

What are the replacement functions that provide this functionality on Windows 10 UWP?

I believe, some functions doesn't have replacement, since UWP doesn't support console output and maybe some others limitations also.

Possibly good reading why Go should support UWP platform can be the announcement of UWP support for Qt(C++) framework with some explanations why it was done:
http://blog.qt.io/blog/2015/04/29/windows-10-support-in-qt/

Basically, UWP apps can be placed in Windows 10 Store and distributed to any kind of device with Windows 10 ( package should has multiple builds for x86, x64 and arm platforms, but only x64 can be supported too ).

I don't think Go is supported on Windows 10 UWP platform. What is that you are building for Windows 10 UWP?

On Windows it's possible to build static library with CGO using MSYS2/MinGW-w64 toolchain and link static library to MinGW DLL to be P/Invoked from UWP application.

Ideally, CGO should support msvc compiler toolchain to eliminate some difficulties to support UWP platform, but because MinGW already is supported and it's possible to bring MinGW DLL with exported C-functions to UWP, it might be not so much additional work to support UWP platform.

I'm trying to consume the go module to Windows 10 UWP platform, which is already used cross-platform for iOS and Android. The main benefit of UWP platform is that UWP port of react-native library already exists + Windows 10 Store publishing will be available for final application.

Thanks

@maxhora
Copy link
Author

maxhora commented Sep 10, 2017

What are the replacement functions that provide this functionality on Windows 10 UWP?

https://docs.microsoft.com/en-us/cpp/cppcx/crt-functions-not-supported-in-universal-windows-platform-apps

@alexbrainman
Copy link
Member

@Maxris thank you for explaining. Unfortunately I have no plan to work on this. So, if you are interested, you have to do it yourself. I am happy to answer any questions you have along the way.

Alex

@maxhora
Copy link
Author

maxhora commented Sep 12, 2017

@alexbrainman thank you! I've started looking into this, so definitely will have some questions soon...

@maxhora
Copy link
Author

maxhora commented Sep 19, 2017

Hello @alexbrainman ,
It seems that support of UWP will require extending Go with new GOARCH.
I'm planning to start adding of "windows_amd64_uwp" GOARCH support.
Going to start looking into extending of src\cmd\dist bootstrap tool with new UWP arch.

@ianlancetaylor ianlancetaylor changed the title Consuming MinGW DLL with Go Runtime to Windows 10 UWP application and passing Certification Kit security checks runtime: avoid functions forbidden on Windows 10 UWP Sep 19, 2017
@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows labels Sep 19, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Sep 19, 2017
@ianlancetaylor
Copy link
Contributor

I assume you mean a new GOOS, not a new GOARCH.

If you intend your work to be added back to the main Go distribution, please discuss it on the golang-dev mailing list. If this really needs a new GOOS value--I don't really know--there are various requirements that need to be addressed. See https://golang.org/wiki/PortingPolicy.

@alexbrainman
Copy link
Member

@Maxris what Ian said. It is a big job.
You can also just copy Go source code, change it for yourself and see if it is useful to you. I would say you should do it anyway - you need something working and useful before it can be merged back into main Go repo.

Alex

PS: See related (but, probably, not relevant today) https://groups.google.com/d/topic/golang-dev/ZfmKRl5V6kw/discussion

@maxhora
Copy link
Author

maxhora commented Sep 20, 2017

Thank you @ianlancetaylor @alexbrainman !
Links should be very helpful!
My best guess, is that new GOARCH should suit better, because it's the same Windows OS, but some API calls can't be used. That's the only difference.
Maybe even new ARCH is too much for such small difference, but after looking a little bit at source, it seems should be more cleaner way to implement, than put some additional checks into source code for Windows platform.

@ianlancetaylor
Copy link
Contributor

Just to be clear, it can not be a new GOARCH value. It could possibly be a new GOOS value.

But I would hope that it can be done without changing either GOARCH or GOOS.

@maxhora
Copy link
Author

maxhora commented Sep 20, 2017

Okay, @ianlancetaylor thanks!

@tfriedel6
Copy link

Just wanted to say that I am also interested in building UWP apps in Go. @Maxris have you been able to get something running yes?

@maxhora
Copy link
Author

maxhora commented Nov 1, 2017

@tfriedel6 , not yet, but still planning to work on this. Sample project might be used as starting point to bring dll built with MinGW to UWP platform. As suggested above, some discussion should be started.

@ghost
Copy link

ghost commented May 10, 2018

Can anyone tell me the status of this ?

About a week ago Microsoft finally stabilised their winrt c/c++ runtime so that you don't need to use their weird cx API.
Chrome uses the c / c++ winrt runtime for example.

So does this mean a new golang GIOS is not needed and I can use golang on Windows 10 and call the winrt runtime now ?

@ghost
Copy link

ghost commented May 10, 2018

@rsc could you comment on this please ? It's really important that golang is not locked out of Windows 10 desktops for me. Especially the new appx and windows store

@eliasnaur
Copy link
Contributor

This 2019 post says the venerable win32 API is now has "full support" in their windows store:

https://news.xbox.com/en-us/2019/05/30/microsoft-approach-to-pc-gaming

Look for "Supporting Win32 Games on Windows 10".

Is this issue still relevant?

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
Status: Triage Backlog
Development

No branches or pull requests

9 participants