HNHacker News
TopNewBestAskShowJobs

fwsgonzo

1,688 karma · joined June 6, 2017

submissionscomments
fwsgonzo··on Fast RISC-V-based scripting back end for game engines
This is completely ignoring that RVScript has really nice APIs both ways. While being lower latency.
fwsgonzo··on Fast RISC-V-based scripting back end for game engines
Only for binary translation or just-in-time compilation (basically producing native code). If you're interpreting RISC-V you can just pretend the registers are an array of register-sized integers. Which is what they are.
fwsgonzo··on Fast RISC-V-based scripting back end for game engines
The game is quite complex actually, but the script is not doing overmuch right now. The script is doing things that makes sense for a growing modding API, while the engine still does the brunt of the work. That said, there are functions that end up being called billions of times simply because you want that flexibility, and that's where the low latency script pays off.
fwsgonzo··on Fast RISC-V-based scripting back end for game engines
Hm, if you don't actually need a sandbox then I think just using the C# run-time makes a lot of sense. I also like C#, but I've never been in a situation to try the fairly new AOT support. Sounds like a good idea, though. C# is a very good language.
fwsgonzo··on Fast RISC-V-based scripting back end for game engines
Yes, precompilation is not optional. I've used many languages in sandboxes over the years developing both this and other emulators.

I really like Nim the most. It's Python spiritually, but with types. Types just really really necessary, and it does have FFI support so you can forward arguments either from a wrapper or use {.cdecl} directly. It's still not a barneskirenn (as we say in Norway), but definitely the most fun I've had using another language in my various sandboxes.

Nelua and Zig are close seconds. Both are just so easy to work with C-based FFI. Nelua is probably not safe to use, as it's still a work in progress. At least last I checked. Zig is very much ready to use. Maybe not your cup of tea, though.

Golang has a complex run-time and I don't recommend using it. It's definitely possible though as my sandbox does have a full MMU. Just expect integration to be long and ardous. And the ABI changes potentially every version.

Rust is one of the easier ones. I didn't find it fun to work with though. It has by far the best inline assembly, but too much fighting with the compiler. I know that people love Rust, and it is fully supported in my emulator.

C/C++ has the benefit of having the ability to have their underlying functions overridden by native helper system calls. Eg. replacing memcpy() with a system call that has native performance. It's too long a long topic to talk about here, but Nim and Nelua also falls under this umbrella along with other languages that can compile to C/C++.

Kotlin is definitely possible to use. A bit hard to understand how the native stuff actually works, but I did manage to run a hello world program in several sandboxes with some effort. I'm not 100% sure but I think I managed to convert a C API header directly to something kotlin understands using a one-liner in the terminal. I would say it scores high just on that. Again, just a bit hard to understand how to talk to Kotlin from an external FFI looking in.

JavaScript is of course possible with both jitless v8 and QuickJS. v8 requires writing some C++ scaffolding + host API functions, and QuickJS requires the same in C. Either works.

And I think that's all the languages I have tried. If you think there's a missing language here, then I would love to try it!

fwsgonzo··on Fast RISC-V-based scripting back end for game engines
The sandbox is interpreting RISC-V, just very quickly. It's platform independent. I am actually making a game with a derivative of this repo, and in the server I am building the programs at the same time as the server. Once the server starts, it loads all the programs, and then sends compressed programs to each client, so that everyone who connects has the same scripts. Easy and convenient, but most likely just that because I did it from the start.
fwsgonzo··on Fast RISC-V-based scripting back end for game engines
The fast bytecode is reduced to a simple operation that excludes certain knowns. For example if you have an instruction that stores A0 = A1 + 0, then knowing the immediate is zero, this can be reduced from reading a complex bit pattern to a bytecode that moves from one register to another, basically MV dst=A0, src=A1.
fwsgonzo··on Fast RISC-V-based scripting back end for game engines
He might be talking about having to implement a register allocator/file in order to interpret stack machines faster. Something you get from the compilers on register architectures like RISC-V, ARM and x86.

wasmtime uses cranelift, which has a complex register allocator. wasm3 uses a simple register file.

> In M3/Wasm, the stack machine model is translated into a more direct and efficient "register file" approach.

https://github.com/wasm3/wasm3/blob/main/docs/Interpreter.md

fwsgonzo··on Fast RISC-V-based scripting back end for game engines
Very cool! One tip: Take the execute segment and produce fast bytecodes instead of interpreting each instruction as a bit pattern. Producing faster bytecodes is something that even WASM emulators do, despite it being a bytecode format.
fwsgonzo··on Building a baseline JIT for Lua automatically (2023)
http://lua-users.org/wiki/SandBoxes

There is a lot of information there, but it doesn't seem to be able to handle resource exhaustion, execution time limits or even give any guarantees. It does indicate that it's possible to use as a sandbox, and has a decent example of the most restrictive setup. But I would for example compare it with Luau's SECURITY.md.

From https://github.com/luau-lang/luau/blob/master/SECURITY.md:

> Luau provides a safe sandbox that scripts can not escape from, short of vulnerabilities in custom C functions exposed by the host. This includes the virtual machine and builtin libraries. Notably this currently does not include the work-in-progress native code generation facilities.

> Any source code can not result in memory safety errors or crashes during its compilation or execution. Violations of memory safety are considered vulnerabilities.

> Note that Luau does not provide termination guarantees - some code may exhaust CPU or RAM resources on the system during compilation or execution.

So, even luau will have trouble with untrusted code, but it does give certain guarantees, and writes specifically about what is not covered. I think that's fair. And then libriscv.

From https://github.com/fwsGonzo/libriscv/blob/master/SECURITY.md:

> libriscv provides a safe sandbox that guests can not escape from, short of vulnerabilities in custom system calls installed by the host. This includes the virtual machine and the native helper libraries. Do not use binary translation in production at this time. Do not use linux filesystem or socket system calls in production at this time.

> libriscv provides termination guarantees and default resource limits - code should not be able to exhaust CPU or RAM resources on the system during initialization or execution. If blocking calls are used during system calls, use socket timeouts or timers + signals to cancel.

So, it is possible to provide limits while still running fast. I imagine many WebAssembly emulators can give the same guarantees.

fwsgonzo··on Building a baseline JIT for Lua automatically (2023)
Ah yes, it is indeed going to be faster.
fwsgonzo··on Building a baseline JIT for Lua automatically (2023)
There is already Luau if you need a sandbox. Neither Lua nor LuaJIT are sandboxes. There is also my libriscv project if you need a low latency sandbox, without JIT.

See: http://lua-users.org/lists/lua-l/2011-02/msg01582.html

I'm not sure what you mean by code generation constraints though.

fwsgonzo··on BunkerWeb: Nginx-based open-source Web Application Firewall (WAF)
It's just a wrapper around the abandoned ModSecurity waf.
fwsgonzo··on Unity Software cutting 25% of staff in 'company reset' continuation
They've fired so many employees that they (the employees) may as well band together to create a new game engine.
fwsgonzo··on Ask HN: What's your biggest code smell?
Spaghetti. I know that people like mentioning inheritance, factory and template hells, but trust me. If you've seen spaghetti, where there is no reusability in the entire codebase, then you know.

There is a reason we like to think of objects as something that when constructed is valid and reusable, regardless of language. Even most decent C code looks like conservative object-oriented programming.

fwsgonzo··on Micro Beast: Self contained 8-bit computer kit in a box
Yes, you're right. I don't know if you can see this: https://i.redd.it/vtswj6s8wh321.jpg

But what it says is that it required 24MB of HDD (12MB after installation), and a 386 or equivalent computer. An i386 is quite powerful, to be honest. It even has protected mode!

And, 4MB RAM, which is more than what I had on my 286 laptop back in the day.

fwsgonzo··on Sanitizing static freestanding nolibc programs?
For undefined-sanitizer, you can implement your own at least. I did it here: https://github.com/fwsGonzo/barebones

Undefined-sanitizer also has a minimal-run-time mode designed to be able to run in production: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#...

As for ASan and MSan I think that will be quite a bit of work. I have worked in embedded a lot, and my advice here is to split off your project into static libraries, and make it so that you can run parts of it as a regular Linux program. I don't know if that's possible for you.

For example, when I was fuzzing a network stack, I would just use TAP devices to fuzz almost all of it, except the actual devices. So I partially compiled the operating system as a regular Linux program.

fwsgonzo··on Browsers are the most likely disruptor of the mobile duopoly
That's pretty good if you ask me! I was using an image encoder that had a WebAssembly SIMD CMake option, which is nice, but it only had half of native performance. I suppose it will continue to improve over time.
fwsgonzo··on Browsers are the most likely disruptor of the mobile duopoly
75% is a stretch. The last time I tested it, it was ~50% of my native program despite my best efforts, with AOT. Which is still good btw, just not as constantly advertised.
fwsgonzo··on Tell HN: Merry Christmas
Merry Christmas from Norway!
fwsgonzo··on Medium.com Down?
Yep, it's down for me, and they seem to be aware: https://medium.statuspage.io/

EDIT: Back up!

fwsgonzo··on Mindustry: Open-source automation tower defense game
Does it make sense to publish Deb packages for this game?

Also this commit: https://github.com/Anuken/Mindustry/commit/5548e727501793479...

fwsgonzo··on Atree: A simple and efficient pointer-free tree implementation
It is always like that when you venture off the well trodden path. I am studying low latency emulation and it's also isolating.
fwsgonzo··on Ask HN: Embedded NN Libraries
I've embedded llama.cpp for a while now. There may be a point where it's not embeddable anymore, but for now it works great. My experience with the others is don't bother. The build systems and dependency management is truly awful.

Also, I'm obviously talking about porting here. You will need to tailor the code to your needs, thinking of it as a library. You cannot run an unmodified program.

fwsgonzo··on The best WebAssembly runtime may be no runtime
Cool. I watched it twice! I thought you meant the stack switching done by wasmtime, which is not "a handful of cycles," but I stand corrected: It's fiber/coro switching. Alfred, a friend of mine, gave a talk on using those on a bare metal unikernel we were creating back in the day! :)
fwsgonzo··on The best WebAssembly runtime may be no runtime
That's an impressive feat if true, but I wonder when you would need it outside of a seriously threaded architecture. That is, the server you are embedded in has one thread per client or backend. In a modern server architecture I suspect you could still use KVM if you put your mind to it. For example, switching between internal processes doesn't have to be done according to Linux scheduling. KVM is just a hypervisor architecture, and even though it requires you to call it from the current thread, you can still build fast process isolation on it. Source: I have done it.

Launching a new VM is not something that should be done outside of a restart or reconfiguration.

I think for me, what WASM brings to the table is perhaps reduced Linux-isms. Everything has become a little bit Linux-or-nothing, and if WASM presents a unified API towards all operating systems that is a good thing. I'm still not happy that Browsers are de-facto operating systems now, and with WASM even more so.

fwsgonzo··on The best WebAssembly runtime may be no runtime
Not just that, but which device today doesn't have hardware virtualization where you are literally in a sandbox, running on the actual CPU with all the advanced instruction set extensions available to you?

Some of these WASM run-times are literally hundreds of thousands of lines of code running just-in-time compilation. Inferno-level safety hazard.

fwsgonzo··on Is RISC-V ready for HPC? Evaluating the 64-core Sophon SG2042 RISC-V CPU
I feel the same way. I think RISC-V has changed my opinion on the hardware aspect of things, and now for the first time I want to try to create a simple CPU at home.

There is even a simpler RV32E spec, for those (like me) with little hardware experience. Perhaps RV32E is reasonable to start with?

https://five-embeddev.com/riscv-isa-manual/latest/rv32e.html

fwsgonzo··on Ask HN: As tech companies scale bigger, they scale down customer support
Levers. Each company has MBAs that can pull a certain amount of levers each quarterly. Every now and then, the quarterly lever is the quality of customer support, until there's nothing left.

In theory, companies make room for others when customers get pissed off and move on. It's hard to move on from these tech giants though.

fwsgonzo··on Tesla sues Swedish state agency over number plate blockage
The Swedish Transport Agency says they are only able to ship license plates using PostNord according to regulation, so I'm not sure how exactly Tesla thought they were going to win this lawsuit.
← PreviousPage 6 of 21Next →