sys::prctl: Adding set_vma_anon_name.#2378
Conversation
d79553f to
c808911
Compare
|
|
||
| /// Set an identifier (or reset it) to the address memory range. | ||
| pub fn set_addr_name(addr: NonNull<c_void>, length: NonZeroUsize, name: &CStr) -> Result<()> { | ||
| let res = unsafe { libc::prctl(libc::PR_SET_VMA, libc::PR_SET_VMA_ANON_NAME, addr.as_ptr(), length, name.as_ptr()) }; |
There was a problem hiding this comment.
From the manual, to reset the name, the arg5 has to be NULL:
If arg5 is NULL, the name of the appropriate anonymous virtual memory areas will be reset.
Maybe we should change the name argument to Option<&CStr>?
| } | ||
|
|
||
| /// Set an identifier (or reset it) to the address memory range. | ||
| pub fn set_addr_name(addr: NonNull<c_void>, length: NonZeroUsize, name: &CStr) -> Result<()> { |
There was a problem hiding this comment.
I kinda think we should rename this function to set_vma_anon_name() so that it is consistent with the attribute name SET_VMA_ANON_NAME, though I do agree that set_addr_name is the clearer one.
| sz, | ||
| CStr::from_bytes_with_nul(b"Nix\0").unwrap(), | ||
| ) | ||
| .unwrap_or_default(); |
There was a problem hiding this comment.
Why are we using .unwrap_or_default() here
There was a problem hiding this comment.
because of the comment above, the kernel might not support the feature.
There was a problem hiding this comment.
Sorry about missing that!
Google search shows that this option is a C macro defined in the kernel code, and if it is not defined, then this prctl call would return EINVAL:
> +#else /* CONFIG_ANON_VMA_NAME */
> +static int prctl_set_vma(unsigned long opt, unsigned long start,
> + unsigned long size, unsigned long arg)
> +{
> + return -EINVAL;
> +}
> +#endif /* CONFIG_ANON_VMA_NAME */Seems that there is no explicit way to check if this option is set or not?
0ca2a2a to
565c830
Compare
| pub fn set_vma_anon_name(addr: NonNull<c_void>, length: NonZeroUsize, name: Option<&CStr>) -> Result<()> { | ||
| let nameref = match name { | ||
| Some(n) => n.as_ptr(), | ||
| _ => std::ptr::null_mut() |
There was a problem hiding this comment.
Looks like we should use null() here
| _ => std::ptr::null_mut() | |
| _ => std::ptr::null() |
| sz, | ||
| CStr::from_bytes_with_nul(b"Nix\0").unwrap(), | ||
| ) | ||
| .unwrap_or_default(); |
There was a problem hiding this comment.
Sorry about missing that!
Google search shows that this option is a C macro defined in the kernel code, and if it is not defined, then this prctl call would return EINVAL:
> +#else /* CONFIG_ANON_VMA_NAME */
> +static int prctl_set_vma(unsigned long opt, unsigned long start,
> + unsigned long size, unsigned long arg)
> +{
> + return -EINVAL;
> +}
> +#endif /* CONFIG_ANON_VMA_NAME */Seems that there is no explicit way to check if this option is set or not?
to set a name for an `anonymous` region for Linux/Android.
565c830 to
9f9484a
Compare
No and in this case it does not really matter, this feature is more the "icing of top of cake" kind, so if it does not work it s just a no-op :) |
to set a name for an
anonymousregion for Linux/Android.What does this PR do
Checklist:
CONTRIBUTING.md