Skip to content

Remove usage of unsafe.Pointer in winc #1556

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

Merged
merged 6 commits into from
Jul 18, 2022

Conversation

leaanthony
Copy link
Member

@leaanthony leaanthony commented Jul 13, 2022

Compiling with -race causes a standard windows app to crash. This fixes that. Potential fix for #1554

@leaanthony leaanthony requested a review from stffabi July 13, 2022 09:12
@leaanthony
Copy link
Member Author

Not sure this is the correct fix, but it does fix the problem.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 13, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 847857a
Status: ✅  Deploy successful!
Preview URL: https://9367ccce.wails-website.pages.dev
Branch Preview URL: https://bugfix-windows-race-detectio.wails-website.pages.dev

View logs

@stffabi
Copy link
Collaborator

stffabi commented Jul 13, 2022

The MakeIntResource which normally is a macro in win32 is very special.

It returns a pointer whose value is equal to the int value, so it does not point to an address with the int value but to an address equal to the int value. I think this might be only fixable by changing the return type to an uintptr. But since the recieving method could also be called with an string pointer it would be maybe the best to directly call the loadicon with the uintptr.

@stffabi
Copy link
Collaborator

stffabi commented Jul 13, 2022

So I think we now return the wrong value.

@leaanthony
Copy link
Member Author

@stffabi - yeah, I understand the problem a bit more now. It appears that the use of unsafe pointer and casting to a *uint16 is how most projects on GitHub do this. Any thoughts?

@stffabi
Copy link
Collaborator

stffabi commented Jul 17, 2022

I think we would need to work with a uintptr type instead of a *uint16. Which would need some changes on the caller side but I think that might be the only way to satisfy the race detector.

@leaanthony If you would like I could add a proposal to this PR.

@leaanthony
Copy link
Member Author

Thanks @stffabi ! I did try changing to uintptr and got reasonably far but it didn't appear to change anything. I was probably doing it wrong

@stffabi
Copy link
Collaborator

stffabi commented Jul 17, 2022

Thanks @stffabi ! I did try changing to uintptr and got reasonably far but it didn't appear to change anything. I was probably doing it wrong

You have still seen the race error or the missing icon?

@stffabi
Copy link
Collaborator

stffabi commented Jul 17, 2022

I've added a proposal, with this the icon will be displayed correctly. I wasn't able to test the --race because it seems like it's not supported on arm64 and I only have Windows ARM64.

@leaanthony
Copy link
Member Author

I've just pushed a fix for EnumProc which was failing in a similar way.

@stffabi
Copy link
Collaborator

stffabi commented Jul 17, 2022

I think there might be still one edge case, the &monitorContainer pointer should be passed as unsafe.Pointer and not uintptr here:

succeeded := w32.EnumDisplayMonitors(dc, nil, syscall.NewCallback(EnumProc), uintptr(unsafe.Pointer(&monitorContainer)))

Otherwise go might not know that this pointer is escaping to the syscall and when growing the stack the pointer might become invalid.

@leaanthony
Copy link
Member Author

Good catch. I've pushed a commit that I think fixes what you raised. Please review @stffabi 👍

Copy link
Collaborator

@stffabi stffabi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@stffabi
Copy link
Collaborator

stffabi commented Jul 18, 2022

Just for doc purposes, if one needs to just have the checkptr active without go race (which needs CGO) one can just use the following flags.

go build -gcflags "all=-N -l -d=checkptr"

@leaanthony leaanthony merged commit af1c530 into master Jul 18, 2022
@leaanthony leaanthony deleted the bugfix/windows_race_detection branch July 18, 2022 08:22
leaanthony added a commit that referenced this pull request Jul 21, 2022
* Add troubleshooting for `Not Found` error (#1586)

Issues with Vite's optimizer

* Remove usage of unsafe.Pointer in winc (#1556)

* Remove usage of unsafe.Pointer

* [windows] Remove MakeIntResource and add overloads for Load functions

* Fix `EnumProc` race condition.

* Refactor `EnumDisplayMonitors` to use `unsafe.Pointer` instead of `uintptr`

Co-authored-by: stffabi <stffabi@users.noreply.github.com>

* [windows] Fix stack corruption when using ICoreWebView2HttpHeadersCollectionIterator (#1589)

The API expects a `BOOL *` with `typedef int BOOL` therefore
we need to use a `int32` on the stack.

* Docs/better homepage (#1591)

* Better carousel width

* Learn more button

* Learn more button

* Fix button/width

* Update introduction

* Fix outline colour

* remove custom css

* remove default css

* use secondary button

* Update sponsors. Improve website for mobile.

* v2.0.0-beta.39

* fix docs again

(cherry picked from commit 0a9ae0d)

* Fix docs for good

* Docs FTLOG

* Fix docs again!

* Fix Varly link

* Fix Varly link

* Update example for macOS Menu (#1600)

* Update example for macOS compatibility

Reference #1588

* Add comments, remove duplicates

* Add compatibility for Go1.17 (#1605)

* v2.0.0-beta.39.2

* [v2] Fix plain template (#1609)

* [template] Add missing main.go file to plain template

* [dev] If wails could not be find in go.mod output a gracefull error message

* Install dev dependencies before starting dev mode (#1615)

* Add Show() and Hide() to runtime to show/hide application (#1599)

* Add Show() and Hide() to runtime to show/hide application

* Fix devserver

* Update API docs

* Fix container size (#1616)

* Update Crowdin configuration file

* Update Crowdin configuration file

* Update Crowdin configuration file

* Bump terser from 4.8.0 to 4.8.1 in /runtime/js (#1625)

Bumps [terser](https://github.com/terser/terser) from 4.8.0 to 4.8.1.
- [Release notes](https://github.com/terser/terser/releases)
- [Changelog](https://github.com/terser/terser/blob/master/CHANGELOG.md)
- [Commits](https://github.com/terser/terser/commits)

---
updated-dependencies:
- dependency-name: terser
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump terser from 5.12.0 to 5.14.2 in /website (#1627)

Bumps [terser](https://github.com/terser/terser) from 5.12.0 to 5.14.2.
- [Release notes](https://github.com/terser/terser/releases)
- [Changelog](https://github.com/terser/terser/blob/master/CHANGELOG.md)
- [Commits](https://github.com/terser/terser/commits)

---
updated-dependencies:
- dependency-name: terser
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Co-authored-by: Antonio <acheong@student.dalat.org>
Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
Co-authored-by: stffabi <stffabi@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants