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

syscall/zsyscall_windows.go CreateFileMapping may be missing one case if the object exists before the function call #44539

Closed
VolcanoKing opened this issue Feb 23, 2021 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows

Comments

@VolcanoKing
Copy link

This is the description in the Microsoft API Documentation:

Return value
If the function succeeds, the return value is a handle to the newly created file mapping object.

If the object exists before the function call, the function returns a handle to the existing object (with its current size, not the specified size), and GetLastError returns ERROR_ALREADY_EXISTS.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

https://docs.microsoft.com/zh-cn/windows/win32/api/memoryapi/nf-memoryapi-createfilemappingw

I think we should write it this way to handle errors, for example.

func CreateFileMapping(...) {
	...
	handle = Handle(r0)
	err = errnoErr(e1)
	return
}
@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows labels Feb 24, 2021
@networkimprov
Copy link

cc @alexbrainman @zx2c4

@zx2c4
Copy link
Contributor

zx2c4 commented Feb 28, 2021

Fixed in x/sys/windows. Sending CL.

I'll leave syscall alone, however. The broken behavior will persist there.

@gopherbot
Copy link

Change https://golang.org/cl/297332 mentions this issue: windows: always return last error for CreateFileMapping

@VolcanoKing
Copy link
Author

In https://golang.org/cl/297332 windows/zsyscall_windows.go, I find that CreateMutex and CreateEvent had the same problem.
@alexbrainman @zx2c4 @gopherbot

@zx2c4
Copy link
Contributor

zx2c4 commented Mar 1, 2021

Thanks. I've fixed those too in the same CL.

@golang golang locked and limited conversation to collaborators Mar 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants