Rust: Calling Functions With Different Calling Conventions From Same File

The other day I had some fun with assembly and wanted to try to call assembly functions from Rust. Each compiler follows a certain calling convention, that specifies how parameters are passed between functions. The calling convention is part of an ABI, an application binary interface. There are two major calling conventions out there: System V ABI and “Microsoft/PE x64”. The latter has no real official name, at least I can’t find one Read more…

Include Assembly Source Files In Rust Project (and Build with Cargo)

Update: Since Rust 1.59, the macros global_asm! and asm! are finally stable! I also updated the blog post a little but it is mostly in the state from back then. In this blog post, I show how you can create assembly files next to Rust files and compile everything by Cargo. What are .S files? Recently I stumbled upon a Rust project, where *.S– and *.rs-files were side by side in the same Read more…

Measuring TTFB (Time to First Byte) for HTTP Requests in Rust

The other day I created a small CLI + library written in Rust, that helps to measure the TTFB (time to first byte) for HTTP GET-Requests in Rust. I had this project on my to-do list for a few months now and finally some time for it. I got inspired by the Dev Tools in Google Chrome. You can see an example screenshot from Chrome down below: I wanted to program something similar. Read more…

How to Find Out if a Binary Runs Inside QEMU

In the previous blog post we talked about how to use QEMUs debugcon feature. To do this responsibly, we should only do this if the binary runs in fact inside QEMU. To find this out, one can use the cpuid instruction. It gives us a lot of information about our environment including information about the CPU brand name or if we run inside a hypervisor. This instruction is specific for the x86-platform. It Read more…

How to Use QEMUs “debugcon”-device (and Write Debug Information to the Terminal or a File)

Update 2024-01-30: The same underlying mechanism was just merged in Cloud Hypervisor as well! It is exposed as –debug-console <target>. This article mostly applies to Cloud Hypervisor as well. Problem: Getting Early Debug Output as Kernel Developer QEMU is a VMM often used for low-level OS/kernel development and testing. When you develop your own kernel or firmware, things can get really hard and difficult to debug sometimes. Especially when something badly fails in Read more…