Coder Social home page Coder Social logo

Stack probe about may HOT 9 OPEN

xudong-huang avatar xudong-huang commented on May 22, 2024
Stack probe

from may.

Comments (9)

vitiral avatar vitiral commented on May 22, 2024 2

I feel the big issue with may is that it does not guard against undefined behavior. I think most use cases don't care that they have to limit their stack size (most co-routines will spawn a single function call!) and wouldn't mind if the coroutine paniced in that case. Undefined behavior, however, is a huge problem.

Is it possible to prevent undefined behavior and instead panic... or even abort?

from may.

vitiral avatar vitiral commented on May 22, 2024 1

cool, thanks for the response!

I think it makes sense for go! to use the stack probe, but allow users to access a coroutine without probed memory (through an unsafe function) if they really want to squeeze performance.

Thanks!

from may.

Xudong-Huang avatar Xudong-Huang commented on May 22, 2024 1

from may.

Xudong-Huang avatar Xudong-Huang commented on May 22, 2024

thanks for the link!
currently May doesn't use guard page for coroutines stacks, this need alloc extra one more page for each coroutine. Now we only has a very unsafe way to probe the stack overflow implemented by checking the footprint of the coroutine stack. So this is why exceed stack could cause undefined behavior.

I check the __rust_probestack src code and find that this function needs to be called in the user's code, not in the May library, because it only used for one big single function frame to detect stack overflow, and for libary design we don't have any information about how the stack frames would grow. If users forget call this for a large stack frame (bigger than one page) function it still triggers undefined behavior even we has a stack gurad page here.

from may.

vitiral avatar vitiral commented on May 22, 2024

I check the __rust_probestack src code and find that this function needs to be called in the user's code, not in the May library, because it only used for one big single function frame to detect stack overflow, and for libary design we don't have any information about how the stack frames would grow.

I may not be understanding, but if it has to be called "in the user's code" then couldn't the go! macro call it?

from may.

Xudong-Huang avatar Xudong-Huang commented on May 22, 2024

@vitiral: go! macro is just a thin wrapper, which doesn't need stack probe at all. only those leaf functions that have very big stack frame would be benefit from __rust_probestack when they are running with a guard page on the stack. But may doesn't have guard pages for coroutines now, so call __rust_probestack is no help.

from may.

Xudong-Huang avatar Xudong-Huang commented on May 22, 2024

yes, it's possible to add a stack guard page for each coroutine. And this would need an extra one page memory allocated. for most cases this is not a big issue which I preferred to add the behavior in future. if stack overflow detected, OS will kill the program with a segment fault(maybe with better output by rust, this is not a UB, I think) just like normal thread stack overflow implemented by rust.

I don't think we can have a panic if stack overflow happened, when panic happened, it will need more stack which would make things worse. If we are using guard page, there is no place to put the panic code, rust run-time takes over the action for stack overflow.

from may.

killme2008 avatar killme2008 commented on May 22, 2024

I think this is a serious issue that prevent people to use may in production.People are not afraid of panic but undefined. 😄

Do you have any plan to fix this issue?

from may.

Xudong-Huang avatar Xudong-Huang commented on May 22, 2024

now the generator lib use guarded stack, may will automatically has the desired behavior.

ref Xudong-Huang/generator-rs#12

from may.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.