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

proposal: runtime: export runtime.getAuxv() #68089

Closed
florianl opened this issue Jun 20, 2024 · 2 comments
Closed

proposal: runtime: export runtime.getAuxv() #68089

florianl opened this issue Jun 20, 2024 · 2 comments
Labels
Milestone

Comments

@florianl
Copy link
Contributor

florianl commented Jun 20, 2024

Proposal Details

This proposal is based on the initiative started with go.dev/issue/67401 to lock down future use of //go:linkname. runtime.getAuxv() is one of the functions in runtime that is used with //go:linkname in other Go packages.

At program start, auxiliary vectors provide a way for the kernel to share essential details about the system with user processes. An auxiliary vector holds an even number of elements, (tag, value) pairs. The possible types can be added and exposed via golang.org/x/sys/unix. For the Linux kernel, the types are defined in include/uapi/linux/auxvec.h. To some extent, the information that is shared with the user process can be retrieved in other ways. As an example, the real uid (AT_UID) can also be retrieved using os.Getuid(). But the auxiliary vector also provides information that is not covered by other packages, like AT_CLKTCK (Frequency of times()) or AT_SYSINFO_EHDR. Due to security related restrictions or isolation techniques, it is not possible in some environments to access /proc/<PID>/auxv to retrieve the auxiliary vector.

As only the Go runtime does have access to the auxiliary vector, this proposal advocates on adding runtime.GetAuxv() as API to the runtime.

func Getauxv() []uintptr

The exact format of the newly added API for GetAuxv() is subject to change and up for discussion with this proposal.

For platforms where the auxiliary vector is not an established concept, like windows, runtime.GetAuxv() should return nil.

Exposing runtime.GetAuxv() should not impact future internal or external changes to the runtime. The runtime should only expose the information it holds of the auxiliary vector that it receives at startup.

With go.dev/cl/458256 access to runtime.getAuxv() (via //go:linkname) was added to golang.org/x/sys/cpu. @prattmic mentioned in the review of this CL that some sort of access to the auxiliary vectors should be added in the future.

An alternative, also mentioned in go.dev/issue/67839#issuecomment-2150542705, to runtime.Getauxv() could be to make the auxiliary vector available via golang.org/x/sys/unix by limiting the access to runtime.getAuxv() to golang.org/x/sys/unix only.

Related issue(s):

  • go.dev/issue/67839 - major difference here is the idea to expose the auxiliary vector via the os package.
@adonovan
Copy link
Member

The unix package seems like the more appropriate place for this feature, since it is UNIX-specific. (The closest analogue in Windows is the Process Environment Block, but its structure and function are completely different in the details.)

@ianlancetaylor
Copy link
Contributor

Let's treat this as a dup of #67839. I don't think we need two different proposals for the same idea. Thanks.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants