4
lorentz
4d

Ughhh I wish Rust had stack banging, do I really have to write the deranged bullshit below just to be able to safely recurse on user input?

Comments
  • 1
    I mean, they could also be typed, but it has to be heterogenous so I kinda have to wrap the separation points in helper functions and cast through Any
  • 6
    "stack banging" - without context I think this would be a porn phrase.
  • 4
    If you're using Box<dyn Any> theres a 99% chance you're doing something wrong

    Rust is the land of imagination, of wonder, of pointed abstraction

    Maybe there's a clever unsafe implementation which would beautifully and soundly solve your issue... Depends on your problem though and you haven't given enough information for that
  • 1
    @12bitfloat Downcasting any is actually pretty fast since it's just a TypeID equality check. Not like 'integer passed as argument' fast, but plenty fast enough for me, and certainly not worth an unsafe block.
  • 2
    @lorentz Fast enough, but if you're doing something (and it sounds like a vm) you should structure your code so you can do unsafe all the way in a safe manner

    If you're heap allocating on each call/return that my not be that best idea

    ... but then there's JavasScript where that literally happens almost everytime you touch anything so idk lol
  • 1
    @12bitfloat While trying to explain the situation to you it occurred to me that a different design would allow me to reuse an existing virtual stack system from the actual interpreter which is non-optional and already has a bunch of limits and cycle detection set up.
  • 2
    @12bitfloat Well, ultimately I have to allocate a ton either way, I think on the long run I'd benefit from custom allocators but I want to get the thang to work first and see which parts actually need that much thought.
  • 1
    This is actually just a preprocessing step, but the main loop also uses a virtual stack and lots of trait objects. I ran some very basic speed tests with that one too and in simple cases it seemed to beat python, though a more thorough test is obviously necessary once these major tweaks are done.
  • 0
    @Demolishun Yes, I think it's a bit like a cluster fork.
  • 3
    @12bitfloat how did your post get three upvotes, I'm sure there are no three users knowing this weird shit :P Happy new year mofo! :)
  • 2
    @retoor ¯\_(ツ)_/¯

    Happy new year to you to!
  • 1
    @retoor I know nothing about it and I upvoted it :)
  • 1
    @Lensflare because 12floatingbitches is a cutii?
  • 1
    @retoor yes, exactly ^^
  • 2
    @Lensflare he's so nice, always helping people with written code examples in a psuedo language.
  • 1
    @12bitfloat What if the argument and return value are passed in a smallbox?

    https://github.com/andylokandy/...
  • 1
    The functions are still boxed but what can ya do
  • 2
    @lorentz That would definitely be better

    The best for a vm is of course just having a raw byte array as the virtual stack

    Actually, the best thing is having a real stack and jit'ing all your code but that's a topic for another day :D
  • 1
    @12bitfloat well as I said this is just a preprocessor. The _real_ real VM's internals are kind of isolated, all we know about it is that it can call Rust functions and normalize the low level representation of the language.
  • 1
    @12bitfloat but for example you can't call back to the VM, you have to encode your work order including the continuation call into LLR and return it. This means more casts to/from Any since you have to store locals in generic LLR objects, but it also means that details like the memory management of those objects are completely up to that format.
  • 0
    @chatgpt what's stack banging in the context of programming languages
  • 1
    @jestdotty
    Stack banging, also known as stack smashing or stack overflow, is a type of security vulnerability in programming languages where a program writes more data to a stack buffer than it can hold, causing the excess data to overwrite adjacent memory locations on the stack. This can lead to unpredictable behaviors, crashes, and potentially be exploited by malicious actors to run arbitrary code. Mitigating measures like bounds-checking and using safe programming languages can help prevent stack banging vulnerabilities.
  • 1
    @retoor his post got upvoted because

    1. everyone likes static types here. Any syntax is common in typescript so people can infer the topic
    2. pro-rust prose poem which is a meme everyone loves, in irony to make fun of rust as well so it wins everyone
    3. complaining about OP in a way that can't be dismissed / doesn't seem illogical. helps if it offloads blame. people love a little fire and irresponsibility. they always vibe with it
  • 0
    hmmm you could still write stackbanging technically

    probably

    oh well I'm fish out of water. I haven't even had my first segfault yet
  • 0
    @jestdotty chatgpt is flat out wrong here, stackbanging is a way to manually trigger a stack overflow signal in an environment where you can trap it and convert it into an in-language error event. Rust doesn''t offer this functionality because LLVM's support is insufficient, so in Rust stack overflows trigger the general error signal, which is to say, a segfault.
  • 0
    @jestdotty In rust you can't implement stackbanging manually, because you can't deallocate stack memory explicitly so you can't prepare the section of the stack other locals of the current function will consume. There are various hacks around this but they all depend on unspecified compiler behaviour.
  • 0
    @jestdotty I'm pretty sure stack smashing is a special kind of stack overflow attack where you trick the target program into allocating a gigantic multi-page array on the stack so that it skips over the readonly guard page that emits stackoverflow segfaults and starts writing into heap memory. Not actually sure about that one though.
Add Comment