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

Trampolines twice in unix stack bootstrapping #5

Closed
pchickey opened this issue Feb 9, 2018 · 2 comments
Closed

Trampolines twice in unix stack bootstrapping #5

pchickey opened this issue Feb 9, 2018 · 2 comments

Comments

@pchickey
Copy link

pchickey commented Feb 9, 2018

Hi - I was single-stepping through this code to make sure I understood how it worked, and I discovered that, at least on the x64 unix code (https://github.com/Xudong-Huang/generator-rs/blob/master/src/detail/x86_64_unix.rs), the trampoline ends up running twice.

The first swap context sets stack pointer to sp[-4] (using the sp defined in initialize_call_frame), and then returns into bootstrap_green_task. that function then puts fptr from R14 into sp[-2], returns again into bootstrap_green_task which is at sp[-3]. the copies from r12, r13, and r14 run again, harmlessly, and then finally it returns into fptr.

I believe the only necessary correction is to change mov %r14, 8(%rsp) to mov %r14, (%rsp) in bootstrap_green_task. The assignment of sp[-3] to bootstrap_green_task in initialize_call_frame can then be eliminated as well.

Alternately, you can not put fptr in regs.gpr[r14] at all, and put it directly into sp[-3], and then eliminate the mov %r14 from the bootstrap entirely.

However, it is also possible I have no idea what I'm talking about, because I've only learned Intel assembly programming very recently.

@Xudong-Huang
Copy link
Owner

You are right. The trampoline may run twice. When I was developing this project, I found that debug and release versions have different stack layout that generated by the compiler. we need to make sure on both versions that we can trap into bootstrap_green_task.

But this version is not as sophisticated as the libfringe version. In next release I will switch to the libfringe branch. It's much faster than the method currently used in master branch. please ref #4.

@pchickey
Copy link
Author

pchickey commented Feb 9, 2018

That makes sense. Thanks for the explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants