-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/sys/unix: standardize Kevent_t Udata as integer, not pointer #32153
Comments
|
Udata field types:
|
Using |
@ianlancetaylor Any idea why |
@wI2L It's an |
@tklauser Understood. Can we override this to use a |
There is no perfect choice here, but it seems better for the field to consistently be |
Merged #32192 into this one, so we can have one discussion instead of two. |
Aren't these structures held inside the kernel and passed back to user space? If so, isn't storing a Go pointer in them - and hiding that pointer in the kernel, invisible to the garbage collector - going to cause problems? If so, it seems like an int type would be preferable. It's unclear how much we can change at all right now, of course. |
You're right, of course, it does have to be an integer. This is x/sys/unix, so we don't have strict backward compatibility. |
We should probably unify the different architectures and OS's to the greatest extent possible. If it's an opaque word then it should probably be uintptr; else uint64. Using unsafe.Pointer would technically be OK but would certainly encourage bad behavior (you could only safely put non-Go pointers there). It looks like we got it wrong everywhere, and Kevent udata should be uintptr. For EpollEvent, I am a little worried about the union having both a uint64 and an |
It looks like we should definitely eliminate any unsafe.Pointer in Kevent and change to uintptr. For epoll, does anyone know of any kernel APIs that require the use of one field or another? If there is only one field (in particular, we suspect fd) then we should keep that field being the one that's exposed. |
Following up on #32153 (comment), I'm going to split the two seeming outcomes by system. First Kevent. Our
Based on the discussion above, it sounds like we should standardize on |
Next EpollEvent. All our Linux structs say:
On 32-bit systems the |
Based on the previous two comments, it sounds like the right outcome here is to fix up Kevent_t to not use pointers and leave EpollEvent alone. I will retitle this and would like to hear feedback from people who agree or disagree, especially @wI2L. |
@rsc Thanks for the follow-up on this issue. Regarding Finally, I'd like to bubble up one the subjects of the original issue I filled that has been ignored so far, regarding the |
@wI2L, as far as uintptr vs int32/int64, it just seems more consistent with all the other fields and the like to keep using sized integers. We don't use uintptr in those generated structs very often, if at all. Re SetKevent, that's really a more general problem, that field types that vary size across system or architecture are difficult to initialize. It might make sense to think about how to address that problem in a general way that applies to all the syscall structs, not just Kevent. (For example, the package has a special case TimeToTimespec function, but nothing for most of the other structs.) It's unclear what to do in general but maybe someone will come up with a clever general solution. Let's keep this issue just about the type of the field for now; feel free to file a separate issue about SetKevent if you think that's the right path forward. Using int32/int64 for udata in Kevent_t (as currently titled) seems like a likely accept. Leaving a week for any final objections before accepting. |
Marked this last week as likely accept w/ call for last comments (#32153 (comment)). |
unix.SetKevent
only takesmode
(eg.Filter
field) andflags
parameter.Other fields also have different types depending on the ach/platform, say
Udata
which is either a*byte
or aint32
.Since Go1 compat promise prevent us from changing the
SetKevent
function, perhaps it could be feasible to add new methods to theKevent_t
type to set the others fields, similar to*Iovec.SetLen
for example.Fflags
andData
methods looks straightforward to implement, on the model ofSetKevent
, since types are integers on all platforms/archs.However, so far, I am unsure about the type of the
Udata
parameter for the eponym method. I typically would dokev.Udata = (*byte)(unsafe.Pointer(&foobar))
on my own currently for darwin/amd64, but I guess that exposingunsafe.Pointer
as a parameter type is not a good solution.The text was updated successfully, but these errors were encountered: