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

Clarify whether inline assembly nomem implies nostack #1350

Closed
lukas-code opened this issue Apr 18, 2023 · 2 comments · Fixed by #1598
Closed

Clarify whether inline assembly nomem implies nostack #1350

lukas-code opened this issue Apr 18, 2023 · 2 comments · Fixed by #1598
Labels
A-asm Area: inline assembly

Comments

@lukas-code
Copy link
Member

Location: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#options

i.e. is the following UB:

pub fn foo() {
    unsafe { core::arch::asm!("push rax", "pop rax", options(nomem)) }
}

This code obviously does write to memory, but the reference only talks about global variables for nomem, which make me think this probably fine? It would be nice to clarify whether nomem inline assembly is allowed to access to stack at all.

@ehuss ehuss added the A-asm Area: inline assembly label Jun 27, 2023
mtoohey31 added a commit to KidneyOS/KidneyOS that referenced this issue Mar 23, 2024
This might be fine, but it's currently unclear so we probably shouldn't.
See rust-lang/reference#1350 for details.
mtoohey31 added a commit to KidneyOS/KidneyOS that referenced this issue Mar 23, 2024
This might be fine, but it's currently unclear so we probably shouldn't.
See rust-lang/reference#1350 for details.
mtoohey31 added a commit to KidneyOS/KidneyOS that referenced this issue Apr 1, 2024
This might be fine, but it's currently unclear so we probably shouldn't.
See rust-lang/reference#1350 for details.
@Freax13
Copy link

Freax13 commented Aug 30, 2024

I think this code would not be UB.

The set of memory locations that assembly code is allowed to read and write are the same as those allowed for an FFI function. [...] If the readonly option is set, then only memory reads are allowed. If the nomem option is set then no reads or writes to memory are allowed. [...] These rules do not apply to memory which is private to the asm code, such as stack space allocated within the asm block.

(source, emphasis mine)

@lukas-code
Copy link
Member Author

@Freax13 Thanks, I must have missed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-asm Area: inline assembly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants