context-rs icon indicating copy to clipboard operation
context-rs copied to clipboard

Inline assembly code

Open zonyitoo opened this issue 8 years ago • 2 comments

Right now the assembly is in a stand alone .S file with AT&T style. To easily make it compilable under windows without depending on gcc, i think those code could be inlined inside a Rust function.

zonyitoo avatar Oct 19 '15 03:10 zonyitoo

Encountered problems:

  1. Every Rust function will first push %rbp onto the stack to save the frame pointer

zonyitoo avatar Oct 19 '15 03:10 zonyitoo

That's not Rust-specific thing. AFAIK almost any compiler adds code to push/pop stack frame base. It's used mostly to reference arguments located on stack. I wouldn't depend on Rust compiler generating exactly this code every time. For inline assembly to work something like #[naked] is necessary.

And #[inline(always)] isn't an option - there should be function call, so we'll have return IP on top of stack.

target-san avatar Oct 23 '15 09:10 target-san