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

cmd/cgo: add #cgo noescape/nocallback annotations #60399

Closed
wants to merge 14 commits into from

Conversation

doujiang24
Copy link
Contributor

@doujiang24 doujiang24 commented May 24, 2023

When passing pointers of Go objects from Go to C, the cgo command generate _Cgo_use(pN) for the unsafe.Pointer type arguments, so that the Go compiler will escape these object to heap.

Since the C function may callback to Go, then the Go stack might grow/shrink, that means the pointers that the C function have will be invalid.

After adding the #cgo noescape annotation for a C function, the cgo command won't generate _Cgo_use(pN), and the Go compiler won't force the object escape to heap.

After adding the #cgo nocallback annotation for a C function, which means the C function won't callback to Go, if it do callback to Go, the Go process will crash.

Fixes #56378

@gopherbot
Copy link

This PR (HEAD: 14cb5e6) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/497837 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from xie cui:

Patch Set 1: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 1: TryBot-Result+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from DeJiang Zhu (doujiang):

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 1:

(10 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: 1383297) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/497837 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

This PR (HEAD: 8cff4bc) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/497837 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from DeJiang Zhu (doujiang):

Patch Set 3:

(11 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from xie cui:

Patch Set 3: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 3: TryBot-Result-1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: a310150) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/497837 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Macrombi Lux:

Patch Set 4:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from xie cui:

Patch Set 4: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 4:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 4:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 4: TryBot-Result-1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: 203f3dd) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/497837 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from xie cui:

Patch Set 5: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 5:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 5:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 5: TryBot-Result-1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: 2cad086) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/497837 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from xie cui:

Patch Set 6: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 6:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 6: TryBot-Result+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 6:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: f01351d) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/497837.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to register for Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link

Message from DeJiang Zhu (doujiang):

Patch Set 10:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 10: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 10:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 10: TryBot-Result+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 10:

(11 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

Signed-off-by: doujiang24 <doujiang24@gmail.com>
@gopherbot
Copy link

This PR (HEAD: d5dd38d) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/497837.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to register for Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link

Message from DeJiang Zhu (doujiang):

Patch Set 10:

(12 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 11: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 11:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 11: TryBot-Result+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 11:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

Signed-off-by: doujiang24 <doujiang24@gmail.com>
@gopherbot
Copy link

This PR (HEAD: 6e4adbc) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/497837.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to register for Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link

Message from DeJiang Zhu (doujiang):

Patch Set 12:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 12: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 12:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 12: TryBot-Result+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 12: Auto-Submit+1 Code-Review+2 Run-TryBot+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Bryan Mills:

Patch Set 12: Code-Review+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

Signed-off-by: doujiang24 <doujiang24@gmail.com>
@gopherbot
Copy link

This PR (HEAD: f1a17b0) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/497837.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to register for Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link

Message from DeJiang Zhu (doujiang):

Patch Set 13:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Bryan Mills:

Patch Set 13: Auto-Submit+1 Code-Review+1 Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gopher Robot:

Patch Set 13:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/497837.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request Aug 25, 2023
When passing pointers of Go objects from Go to C, the cgo command generate _Cgo_use(pN) for the unsafe.Pointer type arguments, so that the Go compiler will escape these object to heap.

Since the C function may callback to Go, then the Go stack might grow/shrink, that means the pointers that the C function have will be invalid.

After adding the #cgo noescape annotation for a C function, the cgo command won't generate _Cgo_use(pN), and the Go compiler won't force the object escape to heap.

After adding the #cgo nocallback annotation for a C function, which means the C function won't callback to Go, if it do callback to Go, the Go process will crash.

Fixes #56378

Change-Id: Ifdca070584e0d349c7b12276270e50089e481f7a
GitHub-Last-Rev: f1a17b0
GitHub-Pull-Request: #60399
Reviewed-on: https://go-review.googlesource.com/c/go/+/497837
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@gopherbot
Copy link

This PR is being closed because golang.org/cl/497837 has been merged.

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.

cmd/cgo: add #cgo noescape/nocallback annotations
2 participants