-
Notifications
You must be signed in to change notification settings - Fork 672
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
sys::prctl: Adding set_vma_anon_name. #2378
Conversation
d79553f
to
c808911
Compare
src/sys/prctl.rs
Outdated
|
||
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
?
src/sys/prctl.rs
Outdated
@@ -213,3 +215,10 @@ pub fn set_thp_disable(flag: bool) -> Result<()> { | |||
pub fn get_thp_disable() -> Result<bool> { | |||
prctl_get_bool(libc::PR_GET_THP_DISABLE) | |||
} | |||
|
|||
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we using .unwrap_or_default()
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because of the comment above, the kernel might not support the feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
src/sys/prctl.rs
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx!
to set a name for an
anonymous
region for Linux/Android.What does this PR do
Checklist:
CONTRIBUTING.md