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

debug safety for pointer casting to a struct or union #1119

Open
andrewrk opened this issue Jun 15, 2018 · 0 comments
Open

debug safety for pointer casting to a struct or union #1119

andrewrk opened this issue Jun 15, 2018 · 0 comments
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Jun 15, 2018

Normal Zig structs and unions do not guarantee size or field order. Zig is allowed to insert secret fields. So, for every normal struct that the code does a @ptrCast to or a @fieldParentPtr, insert a secret first field which has 4 bytes generated unique identifier for the type. When we do the cast, verify the id.

Debug safety that makes structs/unions bigger can be disabled with @setRuntimeSafety(false) in a comptime block directly inside a struct. Once #978 is implemented it would be @optimizeFor(.Small).

Of course, these protections are disabled by default in release-fast and release-small modes.

@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Jun 15, 2018
@andrewrk andrewrk added this to the 0.4.0 milestone Jun 15, 2018
@andrewrk andrewrk changed the title debug safety for pointer casting to a struct debug safety for pointer casting to a struct or union Jun 15, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Nov 21, 2018
@andrewrk andrewrk added the accepted This proposal is planned. label Aug 16, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Aug 16, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Feb 10, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 10, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 20, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jun 29, 2023
@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

1 participant