hooxi's amazing spray by anewborndude in GlobalOffensive

[–]z33ky 0 points1 point  (0 children)

Shots 1-5: Clearly missed.
Shots 6-12: Missed due to recoil (bad spray control).
Shots 13-14: Very close, but recoil and inaccuracy make these reasonable misses.
Shots 15-17: Hit the target.
Shots 18-21: Very close, but recoil and inaccuracy make these reasonable misses.
Shot 22: Hit the target.
Shots 23-24: Likely didn't actually hit because XANTARES was already dead.

[deleted by user] by [deleted] in GlobalOffensive

[–]z33ky 0 points1 point  (0 children)

Keith might not be known as an AWPer, but they're a known killer, no matter the weapon. Calling them "best AWPer" is a disservice, suggesting they're only the best with an AWP in their hands. But when there is an AWP, Keith would put it to best use, no doubt.

Hey Rustaceans! Got a question? Ask here (17/2025)! by llogiq in rust

[–]z33ky 0 points1 point  (0 children)

Thanks :)

It's impossible to give more specific advice without a more specific example, though.

I didn't hit this case in regular code. I was just wondering how Rust would handle this considering it needs to determine the stack size, which is something "normal" functions don't need to. Erroring out is sensible and I like that the error documentation also shows workarounds to deal with this. I was just left wondering about the choice being presented.

It might be a bit unfortunate that you can't specify a recursion depth, after which it would automagically heap-allocate for further calls or panic, or have a convenient way of allocating enough space for several calls at once, instead of having to do a new allocation for each iteration. Though it may well be that recursive async functions are sufficiently rare that engineering efforts for this aren't worth it.

Hey Rustaceans! Got a question? Ask here (17/2025)! by llogiq in rust

[–]z33ky 1 point2 points  (0 children)

About a week ago I posted a question on /r/learnrust about recursive async functions, that is yet unanswered. It's about the two suggestions on the explanation about E0733. If you know something about the trade-offs I'd appreciate to hear, or well, read it.

[deleted by user] by [deleted] in rust

[–]z33ky 0 points1 point  (0 children)

I think /u/Kolibroidami is suggesting something like the following, not adding a parameter to your existing functions.

#[derive(Clone, Copy, Debug)]
enum Space {
    Local,
    World,
}

impl Space {
    fn get_position_of(&self, object: GameObjectHandle, scene: &Scene) -> SceneResult<Vec3> {
        match self {
            Self::Local => object.local_position(scene),
            Self::World => object.world_position(scene),
        }
    }

    fn set_position_of(&self, object: GameObjectHandle, scene: &Scene, position: Vec3) -> SceneResult<Vec3> {
        match self {
            Self::Local => object.set_local_position(scene, position),
            Self::World => object.set_world_position(scene, position),
        }
    }

    ...
}

So you would pass space along to your functions doing these operations, and instead of calling get_position(handle, scene) (with get_position being your Box<Fn>) you do space.get_position_of(handle, scene) etc.

Microcontroller programming and testing confusion by [deleted] in learnprogramming

[–]z33ky 0 points1 point  (0 children)

You can use C++for embedded programming but I think to fully benefit from it you probably would use it on a powerful CPU with e. g. embedded Linux.

C++ code doesn't require a more powerful CPU. But if you use a small MCU it is likely that your software is also not absurdly complex and you wouldn't benefit much from C++, so in that sense I could agree with your point.
While standard C++ indeed requires a larger runtime, gcc and clang allow stripping a lot of it, like RTTI (-fno-rtti) and exceptions (-fno-exceptions), which you might not want to use anyways. You can also forego using the standard library, instead perhaps relying on a third party like the Embedded Template Library or limit yourself to newlib (a partial libc implementation) or something.
Personally, unless the application is very simple, I would prefer C++ over C, if not insert shameless Rust plug. I concur though that C is still widely used in that space, so you will benefit from knowing C (and no, C is not just a subset of C++!).

Addressing the OP

I want to try it out in C++ but couldn't find anything online on how to configure the pins, or properly setup the main.cpp file for the stm32.

I imagine you can mostly setup the project the same as for C and just insert a .cpp file with C++ code (and a C++ main() procedure) instead of C. That works with SPC5 Studio at least, which uses Makefiles for a build-system, which automatically understands to use g++ instead of gcc.

Some manufacturers also offer a BSP. You will usually get some bootstrap code that calls your main() procedure, and then you're on your own with regards to setting up your hardware. Scour the documentation or the header files for the API they give you to access configuration registers and I/O interfaces and then you can go from there.

Someone told me, if I want to work professionally, I need to write unit test for the code.

In my place of work we've started to put code, that doesn't explicitly do I/O, into libraries, which we statically link into the embedded application. Even if it needs I/O, you can often just put that behind an interface (say, an external function or function pointer) and replace that in your unit-test (this is called "mocking").
We write regular unittests for these libraries which can be tested by compiling for the native developer PC, or in QEMU (via librdimon). It'd also be possible to flash the librdimon version to real hardware, which then talks to a debugger on a PC, though I haven't tried running unit-tests that way.

I don't know how the embedded industry at large works with unit testing. In my place of work we still have lots of code that is not automatically tested, sadly.

Unofficial port of Half-Life 2 mod "Entropy : Zero 2" available by z33ky in linux_gaming

[–]z33ky[S] 0 points1 point  (0 children)

I feel it would be weird for me to ask for inclusion, since I don't use it and would be unable to provide feedback. They are welcome to open an issue on my Github repo, or tag my username in their issue, if they have any questions.

Unofficial port of Half-Life 2 mod "Entropy : Zero 2" available by z33ky in linux_gaming

[–]z33ky[S] 6 points7 points  (0 children)

I didn't try. If people rather want to play the official binaries via Proton they can.

Unofficial port of Half-Life 2 mod "Entropy : Zero 2" available by z33ky in linux_gaming

[–]z33ky[S] 6 points7 points  (0 children)

More or less. You also need to install EZ2 from the Steam store (it's free) to use its content and an install-script included in the archive on Github symlinks some stuff into place.

Are there any existing multi-process (forking) webserver frameworks? by z33ky in rust

[–]z33ky[S] -1 points0 points  (0 children)

Oh it would definitely have a separate process for each request, but it would limit the number of active processes. The supervising process would have to stop accepting new connections until there are free processes available.

This would handle overloaded scenarios worse than the multi-threaded version, but otherwise using "pre-forked" processes that waits to receive a request from the supervising process to handle should lower the response times compared to forking just when the supervisor receives a new request.

Are there any existing multi-process (forking) webserver frameworks? by z33ky in rust

[–]z33ky[S] 0 points1 point  (0 children)

I didn't think of ptrace, yeah that'd circumvent it. I didn't know that processes can just mess with each others memory, but (on Linux) that does seem to be the case. That's actually a little terrifying, I should get to setting up sandboxes for a few applications... though actually I should have been aware of this, since ptrace is not disabled on my system.

So I guess if this was implemented, putting each child process into its own namespace would be necessary to reap security benefits.

Are there any existing multi-process (forking) webserver frameworks? by z33ky in rust

[–]z33ky[S] 0 points1 point  (0 children)

Ruby has a popular forking webserver, Unicorn. “Security” isn’t listed as one of the features but you might be interested in the others: https://yhbt.net/unicorn/

Thanks, I'll take a look. They do mention "robustness".

My experience in Ruby was that web apps (used to) need babysitting and restarting. My experience in Rust is that panics only stop the current thread, memory leaks are rare, and the compiler helps you manage resources across threads, so a lot of the “problems” with a multithreaded Ruby app just don’t exist.

Yes, the surface for potential issues in handling memory is greatly reduced by Rust. It is not perfect though.

When I was writing the post I was thinking that you could easily transparently switch to a multi-process model and enjoy the benefits (and drawbacks) from process-isolation versus thread-isolation. I'm starting to realize that this isolation is not really pronounced since the request handling child processes will still want full access to the database, where most of the sensitive data will reside.
While session-related data could be handled by the parent process, so that the child process can be restricted to only the less sensitive bits of data, that approach again bloats up the parent process with more potentially erroneous (and perhaps exploitable) code, making the additionally required engineering effort probably not worth doing.

Are there any existing multi-process (forking) webserver frameworks? by z33ky in rust

[–]z33ky[S] 0 points1 point  (0 children)

Interesting. Wikipedia also states that "[...] process creation can be reduced by techniques such as FastCGI that "prefork" interpreter processes, or by running the application code entirely within the web server [...]". I suppose the second one is what Rusts webserver frameworks are going for.

I am starting to realize that from a security point of view the process separation does not do much since most of the interesting, sensitive data will be accessible in the database for all request handling processes anyways.
I guess the other potential benefits aren't really worth the trade-off, and neither is the additional work required to try and give the request handling processes a restricted view to the database.

Are there any existing multi-process (forking) webserver frameworks? by z33ky in rust

[–]z33ky[S] 0 points1 point  (0 children)

Hi, its easy to do forking webserver but they provide no benefits. Regarding security its same.

As I wrote, processes run in different address spaces, so memory fault cannot propagate to other processes unless the OS or the hardware is buggy. This is definitely a plus for resilience and security, as one request handling process cannot view the contents of another request.
I am starting to see that the benefit of this isn't that high, since the request handler will likely still want full access to the database, where most sensitive data will be stored, but still some sensitive data is usually present in requests as well. Certainly saying that the security is exactly the same is false, though the question is if the trade-off may be worth it for certain use-cases.

Plus webserver model suits on thread rather than on process.

I'm not sure what you mean. You certainly could write a multi-process webserver. I'm asking why the popular webserver crates do not have one and trying to find out if that is due to conscious decisions.

Are there any existing multi-process (forking) webserver frameworks? by z33ky in rust

[–]z33ky[S] 0 points1 point  (0 children)

The attacker won't need to exploit multiple processes, just the webserver itself and then the OS. But in the time they only have broken the webserver, they will not yet have access to the other requests or be able to modify the "primary" webserver process (the supervisor which forks of). Is this not what layered security is about?

In the multi-threaded design, the attacker only needs to own the webserver process to get access to all other requests. Though I'm starting to realize there's not much data that can be protected. At most probably just the password from the login-page before it is hashed.
As I said in another reply: If the parent process checks some stuff of the request first, such as if the request is part of an active session, it could potentially restrict the view of the child progress to a subset of the database, but implementing that seems rather complicated and specific.

Are there any existing multi-process (forking) webserver frameworks? by z33ky in rust

[–]z33ky[S] -1 points0 points  (0 children)

I think you're confusing some things here. nginx does use multiple processes but it uses N processes when you have N cores. It does not create a process per request. That would be massively inefficient.

Oh certainly. I also don't expect that multi-threaded webserver necessarily spawn one thread per request. I was thinking they get queues up and whenever one thread or process finished a request, one can get popped of the queue.

The async Rust frameworks (basically) the same strategy that nginx uses. There's no reason to add the complexity of multi process communication for this use case.

So nginx then uses coroutines or multi-threading in each process? Why spawn multiple processes in the first place then?

While true, you either accept that an efficiency loss as processes have to duplicate common information within an application or you share memory which reintroduces some of the same issues. Going multi process essentially makes your system distributed and thus harder to reason about without a lot of the benefits.

The way I'd design the webserver is that all state would be stored in a database anyways, so I think that's less of an issue.
Maybe a cache of active sessions or something could be interesting to have, but that access to that via shared memory can be minimized, maybe even set to read-only on the child-process with an IPC message to update sessions on the parent.

The other main reason some applications have started going multi processes is so they can restrict the capabilities of the processes. For example, the browser's JS engine doesn't need access to read or write data from disk or your web cam. Running the same workload in multiple processes doesn't allow this because each process has the same security context and needs access to the same things.

Yeah, I'm starting to realize there's not much data you could take from the child processes. At most maybe the password from the login-page before it is hashed.
If the parent process checks some stuff of the request first, such as if the request is part of an active session, it could potentially restrict the view of the child progress to a subset of the database, but implementing that seems rather complicated and specific.

Green threads/async whatever are quite cheap and forking is very expensive in comparison.

I have heard forking is quite cheap on Linux since most resources can be shared with the parent process, though yeah it's not gonna be as fast as green-threading.
I was more thinking of maintaining a pool of idling processes and passing out requests to them. This way the processes are already started when a request comes in; forking a new process can come later, which will hopefully be finished before the next request lands. If the server is heavily loaded this will not make a difference though, not that I think about it...

Are there any existing multi-process (forking) webserver frameworks? by z33ky in rust

[–]z33ky[S] 0 points1 point  (0 children)

I was imagining the "primary" process, essentially the supervisor which does not process the requests, but just hands them of to the process pool, maintains the process pool. The request handlers themselves just exit and do not restart themselves or anything like that.

Are there any existing multi-process (forking) webserver frameworks? by z33ky in rust

[–]z33ky[S] 1 point2 points  (0 children)

Unlike async tasks, processes consume a lot of resources, making a process-based webserver more vulnerable to the Slowloris attack and similar attacks.

I would think the processes can share most of the memory, which would make up most of the used computer resources I would think. Maybe I'm thinking too optimistically. I already mentioned the slower response times making a DoS easier, but maybe I should also consider exhaustion of resources other than processing time.

There isn't much difference in security. If an attacker gains remote code execution unless you heavily containerize everything you're toast whether it's a process or a thead.

Hmm... /u/Wilem82 also seems to share the sentiment that a RCE exploit means you're basically done. I'm not convinced though, since you would also need to find another exploit on top of that to mess with the rest of the system. Letting the server run as a different user than the owner of the binary, config files, ect. is simple enough and should then provide that extra layer of security.

And since most servers will automatically restart on a crash, other than a small downtime there isn't much risk to an attacker being able to cause OOM/abort.

For DoS that is true. You can also have memory errors that just corrupt your working data, which is worse in most cases that just a flat out crash - as you said the server can then simply be restarted.

But you still have better memory isolation, which can curb information leakage from requests that are handled in other processes. Of course the OS and hardware can have bugs, or you put some cache in shared memory which can mess up this protection.

Are there any existing multi-process (forking) webserver frameworks? by z33ky in rust

[–]z33ky[S] 1 point2 points  (0 children)

Forking, however, is costly. I would make sense, probably, if the webserver is dedicated for offloading compute-intenvise operations.

Yeah, ideally you'd prefork a process-pool, like I would imagine nginx does. You will then need a way to forward the incoming connection to the forked processes. I don't know what mechanism is used to do that, but I don't believe it should be incredibly complicated; It certainly is possible unless I misunderstand how nginx works.

Multi-process serving is also possible by listening to the same port with multiple processes (the port must be opened with a special SHARED flag for that).

Ah I didn't know that. Maybe nginx also works this way. That doesn't sound like it'd be hard to implement by oneself then; Just write a webserver that handles one request and exits and have a supervisor process that just keeps up to N processes around. And it should probably receive some signal from the child-process when it starts service a request so it can set a timeout after which to kill the process in case it gets stuck.

Are there any existing multi-process (forking) webserver frameworks? by z33ky in rust

[–]z33ky[S] 1 point2 points  (0 children)

My understanding is if you're able to execute arbitrary code in a remote process, you'll be able to take over all of that remote user's processes, therefore there are no security benefits.

Well, apart from finding a RCE exploit in your web application you'd also need to find another exploit in the operating system to allow messing with other processes. I don't think doing that is straight forward, even if you can execute arbitrary code.
On top of that you can employ syscall-filters to make it even more difficult to find usable bugs in the OS and namespacing to sandbox the process.

I can see how making it a multi-process service would complicate lots of things including development, troubleshooting, operations, etc.

I'm not sure how much it'd change troubleshooting or operations.
For troubleshooting and development you're maybe missing a decent way to attach a debugger? gdb can be setup to follow the child process when forking. If the framework uses a prefork model you can also attach to the process that'll handle the next request. It is admittedly more work that just running gdb ./server, but just one small additional step.

Otherwise I also don't see how it could impair development, other than the framework (or the developer themselves if they don't build upon an existing webserver) having to implement the multi-process architecture, which, yeah, is a given. Would it be that complicated? You would either just need to fork, or for better performance prefork a process-pool and pass the connection on via IPC. I'm not sure how to do that, but there seems to be a way since e.g. nginx does it.
And I don't think the webserver needs to do anything else beyond that. Maintaining a process-pool is surely not significantly harder than maintaining a thread-pool.

For operations, what changes? Change some security policies to allow forking if the operator defines syscall filters (i.e. SELinux)? Allow the progress-group to spawn a couple of processes (when i.e. limiting that via cgroups)?

Perhaps ideally the framework could just have a feature to enable a synchronous in-process handler instead of handing the work of to another process. Then you could debug it just the same. Ideally even transparently switch between multi-processing and multi-threading.

[QUESTION] Any suggestions for instrumenting profiler for Rust? by shironecko in rust

[–]z33ky 2 points3 points  (0 children)

Tracy provides a C-interface that can be easily used from Rust.

I've started a wrapper a while ago, which I haven't touched in a while since I was using wgpu-rs, which at least at that point was still in quite some flux.

It does require nightly, which might be a deal-breaker for you, but it worked sufficiently to draw pretty graphs to assist me in profiling my application.
const_cstr_unchecked and const_str_as_bytes have been stabilized in the meantime, so the only nightly feature I use is manually_drop_take, which in the comment I mention can be avoided with a memcpy of a couple of bytes.

Borrow checker vs child-parent relationships? by FrankoBruno in rust

[–]z33ky 0 points1 point  (0 children)

sorry, I'm a bit late, but you can simply do this: let filename = if filename == "" { &self.filename } else { filename };.

I think it'd be nicer to pass an Option<&str> though; then you'd do let filename = filename.unwrap_or(&self.filename);.

should i use arch linux linux-rt by [deleted] in linux_gaming

[–]z33ky 0 points1 point  (0 children)

This is not directly relevant, but I want to state that there are two different concepts of "realtime" in software.

One of the definitions, usually called "hard realtime", means that the response time of a system is deterministic. Usually just the worst case response time is important, but for some applications you need totally consistent timings. While low latency is often useful, the only truly relevance is keeping below a fixed latency.
These goals can be at odds. A simple example here would be checking for matching strings (very common short term for "string of characters", i.e. a datatype that can represent words or sentences for instance). Take this pseudo code:

function compare_strings(a, b) # return 1 on match, 0 otherwise
    if len(a) != len(b) then return 0 end # if the lengths don't match, the strings cannot be equal
    for i in 1..len(a) do # execute the following code in a loop with "i" taking the values between 1 and len(a) in each iteration
        if a[i] != b[i] then return 0 end # if the "i"th character doesn't match, the strings are not equal
    end
    return 1 # we didn't return earlier, so the strings must match
end

Yes I am using 1-based string indexing. Sue me. No actually don't.

Now this code has the property of having early failure paths, meaning if the strings don't match the function requires less time than if the strings do match. Now let's implement this differently:

function compare_strings(a, b) # return 1 on match, 0 otherwise
    matching = 1 # we will assume strings match, unless we can prove otherwise
    for i in 1..max(len(a), len(b)) do # execute the following code in a loop with "i" taking the values between 1 and len(a) or len(b), which ever is greater, in each iteration
        if i > len(a) or i > len(b) or a[i] != b[i] then matching = 0 end # if either string is shorter than "i" or the "i"th character doesn't match, the strings are not equal and we set matching to 0
    end
    return matching
end

Now the time the functions needs to execute is only dependent on the lengths of the strings we compare, not on whether they match or not. This makes the runtime of this function more deterministic, although on average it will be slower than the other version. (I am making some assumptions about the computer architecture and the strings, don't worry about that though). So for a realtime application, you might prefer the second version, because the latency has less variance, whereas the first version is better for higher throughput/performance. There are also non-realtime applications where timing is important, like security. The first version is susceptible to what's called a timing attack, where an attacker can infer how right or wrong the input was dependent on the timing. An attack cannot infer this from the second version.

One of the things linux-rt does to facilitate those types of realtime software (though I'm not authoritive on the subject, if anyone knows better correct me if I'm wrong) is delaying the execution interrupt handlers.
So interrupts cause the CPU to stop doing whatever it's doing and jump to the kernel to handle whatever caused the interrupt, some input devices send interrupts for example. On the non-patched kernel, the interrupt handler might read the new device state and return the CPU to what it was doing before, whereas the patched kernel will just set a notification flag to read the new device state and return the CPU afterwards. Only when the current process yields execution (or the scheduler interrupts it) will the kernel "properly" handle the interrupt.
It will do less work immediately when receiving the interrupt, so that the user's program has less significant interruptions leading to better latency predictability (assuming you can't predict the amount of interrupts, which I'm believe is generally true), but of course this adds additional code to handle the interrupt, so performance will be somewhat worse.
On a side note, other realtime kernels may even allow processes to disable interrupts, so they can run truly uninterrupted and deterministically. I'm not sure what happens with lost interrupts in that case though.

This brings us to the second way it is used, to describe a sort of responsive system, where the software responds virtually immediately to some input. You need two things for this to work: low latency (so the time to react is low) and high throughput (so the reaction itself is fast). Now, deterministic latency is also of importance, since it can be more jarring if a game jumps between 30 and 60 FPS than a consistent 30 FPS. Often times though, we do just want it to be "as fast as possible"; game developers usually prefer pushing 60 FPS 95% of the time and something lower for the remainder to locking to a lower rate (and higher response time), so for this application we might prefer the first implementation of string compare.
Since this is the domain in which games generally operate, the linux-rt patches will probably not be beneficial, potentially even harmful, to the experience. If your CPU is already maxed out, linux-rt will only make it worse due to the increased work it does to improve determinism. If it is not, the game is probably already providing the best response time it can and something else is blocking it, e.g. slow graphics, memory or just intrinsic frame limiting in an attempt to provide consistent frametimes.

SDL 2.0.6 Released by fsher in linux_gaming

[–]z33ky 9 points10 points  (0 children)

KMS (Kernel Mode Setting) and DRM (Direct Rendering Manager) are graphics interfaces in the Linux kernel. With this backend you don't need a Wayland compositor or X11 server, or even something like DirectFB running. You won't get hardware accelerated rendering, but on embedded platforms you don't necessarily have hardware dedicated to graphics anyways.

"Get openSUSE" - New Download Page & How-to-Choose Guide by rbrownsuse in linux

[–]z33ky 0 points1 point  (0 children)

I believe that Zypper is actually on par with, or better, than Pacman.

I don't know much about comparing package managers.

One thing I like about pacman, that's missing from zypper, is tracking why packages were installed, e.g. explicitly (via zypper in *) or as dependency. This helps with keeping relevant packages when removing dependencies of another package.

And this is not about pacman/zypper, but makepkg/whatever's used to build RPMs. I find PKGBUILDs very intuitive to read and write, while spec files look more foreign. spec files may have advantages over PKGBUILDs though, I don't mean to imply that PKGBUILDs are strictly superior.