The best articles by Ciro Santilli Updated +Created
These are the best articles ever authored by Ciro Santilli, most of them in the format of Stack Overflow answers.
Ciro posts update about new articles on his Twitter accounts.
A chronological list of all articles is also kept at: Section "Updates".
Some random generally less technical in-tree essays will be present at: Section "Essays by Ciro Santilli".
Open source Updated +Created
DateProjectSizeDescription
2019-04gnuplotWhy does plotting with point labels make plot generation extremely slow?
2019-04GDB DashboardLimit the size of shown arguments in the Stack display
2018-03QEMU2Test record and replay feature. Also here
2018-02pandocAdd option to produce AsciiDoc output without explicit heading ids
2017-10AndroidGLES3 content gles3jni from ndk examples fails with "java.lang.RuntimeException: createContext failed: EGL_BAD_CONFIG"
2017-09Mozilla rrHow to automatically start replay and go directly to main instead of _start?
2017-09Mozilla rrReverse step over time(NULL) enters rr/src/preload/syscall_hook.S and leads to "Cannot find bounds of current function"
2017-08xselWhy maximum 4000 characters output with xsel -b ?
2017-06BuildrootDon't print mutiline struct function arguments on stack when set pretty print on
2017-04GDB DashboardAdd style option to print stack arguments on a single line
2017-05BuildrootBuild fails with "unexpected EOF while looking for matching "'" if PATH contains a newline
2017-04GDB DashboardAdd style option to print stack arguments on a single line
2017-03clBLAS.s[0] + CL_DEVICE_TYPE_ALL
2017-01game-icons.netUse multiple separate paths, allow customizing the color of each component, and give a default color
2017-01game-icons.netdelapouite/originals/svg/brick-wall.svg has some whitespace on top
2017-01OpenAI Gymexamples/agents/keyboard_agent.py fails with "AttributeError: 'TimeLimit' object has no attribute 'viewer'"
2016-12Simple DirectMedia LayerAdd C variable printf debug snippets
2015-03tigAccepted feature.
2014-11GitLabDuplicate
2014-11GitLabBug.
2014-11GitLabSupport.
2014-11Bootstrap Hover DropdownBug confirmed.
2014-11GitLabBug confirmed.
2014-11GitLabTriaging.
2014-11GitLabProblem with the display icons in the left block
2014-11sassBug confirmed.
2014-10GitLabPoint duplicate.
2014-10GitLabBug confirmed.
2014-10GitLabBug confirmed.
2014-10Semaphore CIBug confirmed.
2014-10libgit2Bug confirmed.
2014-10GitLabSupport.
2014-10GitLabPoint duplicate.
2014-09vader.vimAccepted feature.
2014-09GitLabPoint already fixed.
2014-09vader.vimAccepted feature.
2014-09GitLabBug confirmed.
2014-09GitLabBug confirmed.
2014-09GitLabPoint duplicate.
2014-09GitLabPoint already fixed.
2014-08markdownlint/markdownlintAccepted feature.
2014-08softcoverAccepted feature.
2014-08markdownlint/markdownlintAccepted feature.
2014-07GitLabBug confirmed.
2014-07GitLabAccepted feature.
2014-07GitLabAccepted feature.
2014-06GitLabAccepted feature.
2014-06GitLabPoint duplicate.
2014-06karlcow/markdown-testsuiteBug confirmed.
2014-06plasticboy/vim-markdownClose issue.
2014-06plasticboy/vim-markdownReview patch.
2014-06plasticboy/vim-markdownReview and patch patch.
2014-05softcoverAccepted feature.
2014-04karlcow/markdown-testsuiteClose issue with better issues.
2014-03tigAccepted feature.
2014-03GitLabAccepted feature.
2014-03softcoverAccepted feature.
2014-03GitLabAdd useful information.
2014-03GitLabPoint duplicate.
2014-03GitLabPoint duplicate.
2014-03GitLabAccepted feature.
2014-02GitLabPoint duplicate.
2014-02GitLabAccepted feature.
2014-02OverleafFeature generated considerable interest.
2014-02GitLabPoint already fixed.
2014-02GitLabLink feature request to patch.
2013-10yakuakeBug confirmed.
2013-10okularBug confirmed.
2013-06krusaderBug confirmed.
2013-05NumPyBug confirmed + inner cause.
2012-05krusaderAccepted feature.
2012-05krusaderBug confirmed.
2012-05AutoKeyBug confirmed.
Docker (software) Updated +Created
Docker is good.
As a lightweight virtualization however, it does break more often than full proper virtualization like QEMU after some updates.
The images also appear to randomly update slightly and break things, even though you've specified e.g.:
FROM ubuntu:20.04
Fabrice Bellard Updated +Created
Creator of QEMU and FFmpeg, both of which Ciro Santilli deeply respects. And a bunch other random stuff.
What is shocking about Fabrice this is that both are insanely important software that Ciro Santilli really likes, and both seem to be completely unrelated subjects!
Google made billions on top of this dude:
At last but not least, Fabrice also studied in the same school that Ciro Santilli studied in France, École Polytechnique.
It is a shame that he keeps such a low profile, there are no videos of him on the web, and he declines interviews.
Another surprising fact is that Fabrice has not worked for the "Big Tech Companies" as far as can be publicly seen, but rather mostly on smaller companies that he co-founded: www.quora.com/Computer-Programmers/Computer-Programmers-Where-is-Fabrice-Bellard-employed
And he's also into some completely random projcts unsurprisingly:
Bibliography:
Figure 1. . Source. At a restaurant with the author apparently. Plus Miguel De Icaza who was in Paris for some conference, which they all presumably attended.
Figure 2.
Fabrice Bellard with light
. There are no in-focus images of Fabrice on the Internet.
Linux Kernel Module Cheat Updated +Created
This is the most important technical tutorial project that Ciro Santilli has done in his life so far as of 2019.
The scope is insane and unprecedented, and goes beyond Linux kernel-land alone, which is where it started.
It ended up eating every system programming content Ciro had previously written! Including:
so that that repo would better be called "System Programming Cheat". But "Linux Kernel Module Cheat" sounds more hardcore ;-)
Other major things that could be added there as well in the future are:
Due to this project, some have considered Ciro to be (archive):
some kind of Linux kernel god.
which made Ciro smile, although "Linux kernel documenter God" would have been more precise.
[    1.451857] input: AT Translated Set 2 keyboard as /devices/platform/i8042/s1│loading @0xffffffffc0000000: ../kernel_modules-1.0//timer.ko
[    1.454310] ledtrig-cpu: registered to indicate activity on CPUs             │(gdb) b lkmc_timer_callback
[    1.455621] usbcore: registered new interface driver usbhid                  │Breakpoint 1 at 0xffffffffc0000000: file /home/ciro/bak/git/linux-kernel-module
[    1.455811] usbhid: USB HID core driver                                      │-cheat/out/x86_64/buildroot/build/kernel_modules-1.0/./timer.c, line 28.
[    1.462044] NET: Registered protocol family 10                               │(gdb) c
[    1.467911] Segment Routing with IPv6                                        │Continuing.
[    1.468407] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver              │
[    1.470859] NET: Registered protocol family 17                               │Breakpoint 1, lkmc_timer_callback (data=0xffffffffc0002000 <mytimer>)
[    1.472017] 9pnet: Installing 9P2000 support                                 │    at /linux-kernel-module-cheat//out/x86_64/buildroot/build/
[    1.475461] sched_clock: Marking stable (1473574872, 0)->(1554017593, -80442)│kernel_modules-1.0/./timer.c:28
[    1.479419] ALSA device list:                                                │28      {
[    1.479567]   No soundcards found.                                           │(gdb) c
[    1.619187] ata2.00: ATAPI: QEMU DVD-ROM, 2.5+, max UDMA/100                 │Continuing.
[    1.622954] ata2.00: configured for MWDMA2                                   │
[    1.644048] scsi 1:0:0:0: CD-ROM            QEMU     QEMU DVD-ROM     2.5+ P5│Breakpoint 1, lkmc_timer_callback (data=0xffffffffc0002000 <mytimer>)
[    1.741966] tsc: Refined TSC clocksource calibration: 2904.010 MHz           │    at /linux-kernel-module-cheat//out/x86_64/buildroot/build/
[    1.742796] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x29dc0f4s│kernel_modules-1.0/./timer.c:28
[    1.743648] clocksource: Switched to clocksource tsc                         │28      {
[    2.072945] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8043│(gdb) bt
[    2.078641] EXT4-fs (vda): couldn't mount as ext3 due to feature incompatibis│#0  lkmc_timer_callback (data=0xffffffffc0002000 <mytimer>)
[    2.080350] EXT4-fs (vda): mounting ext2 file system using the ext4 subsystem│    at /linux-kernel-module-cheat//out/x86_64/buildroot/build/
[    2.088978] EXT4-fs (vda): mounted filesystem without journal. Opts: (null)  │kernel_modules-1.0/./timer.c:28
[    2.089872] VFS: Mounted root (ext2 filesystem) readonly on device 254:0.    │#1  0xffffffff810ab494 in call_timer_fn (timer=0xffffffffc0002000 <mytimer>,
[    2.097168] devtmpfs: mounted                                                │    fn=0xffffffffc0000000 <lkmc_timer_callback>) at kernel/time/timer.c:1326
[    2.126472] Freeing unused kernel memory: 1264K                              │#2  0xffffffff810ab71f in expire_timers (head=<optimized out>,
[    2.126706] Write protecting the kernel read-only data: 16384k               │    base=<optimized out>) at kernel/time/timer.c:1363
[    2.129388] Freeing unused kernel memory: 2024K                              │#3  __run_timers (base=<optimized out>) at kernel/time/timer.c:1666
[    2.139370] Freeing unused kernel memory: 1284K                              │#4  run_timer_softirq (h=<optimized out>) at kernel/time/timer.c:1692
[    2.246231] EXT4-fs (vda): warning: mounting unchecked fs, running e2fsck isd│#5  0xffffffff81a000cc in __do_softirq () at kernel/softirq.c:285
[    2.259574] EXT4-fs (vda): re-mounted. Opts: block_validity,barrier,user_xatr│#6  0xffffffff810577cc in invoke_softirq () at kernel/softirq.c:365
hello S98                                                                       │#7  irq_exit () at kernel/softirq.c:405
                                                                                │#8  0xffffffff818021ba in exiting_irq () at ./arch/x86/include/asm/apic.h:541
Apr 15 23:59:23 login[49]: root login on 'console'                              │#9  smp_apic_timer_interrupt (regs=<optimized out>)
hello /root/.profile                                                            │    at arch/x86/kernel/apic/apic.c:1052
# insmod /timer.ko                                                              │#10 0xffffffff8180190f in apic_timer_interrupt ()
[    6.791945] timer: loading out-of-tree module taints kernel.                 │    at arch/x86/entry/entry_64.S:857
# [    7.821621] 4294894248                                                     │#11 0xffffffff82003df8 in init_thread_union ()
[    8.851385] 4294894504                                                       │#12 0x0000000000000000 in ?? ()
                                                                                │(gdb)
Code 1.
Terminal dump of a LKMC session with two tmux panes with QEMU on left and GDB on right showing a backtrace of the Linux kernel code currently being under QEMU
.
Run Zephyr on QEMU Updated +Created
Real hardware is for newbs. Real hardware is for newbs.
Tested on Ubuntu 23.10 we approximately follow instructions from: docs.zephyrproject.org/3.4.0/develop/getting_started/index.html stopping before the "Flash the sample" section, as we don't flash QEMU. We just run it.
sudo apt install --no-install-recommends git cmake ninja-build gperf \
  ccache dfu-util device-tree-compiler wget \
  python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
  make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1
python3 -m venv ~/zephyrproject/.venv
source ~/zephyrproject/.venv/bin/activate
pip install west
west init ~/zephyrproject
cd ~/zephyrproject
west update
west zephyr-export
cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.1/zephyr-sdk-0.16.1_linux-x86_64.tar.xz
tar xvf zephyr-sdk-0.16.1_linux-x86_64.tar.xz
cd zephyr-sdk-0.16.1
./setup.sh
The installation procedure install all compiler toolchains for us, so we can then basically compile for any target. It also fetches the latest Git source code of Zephyr under:
~/zephyrproject/zephyr
The "most default" blinky hello world example which blinks an LED is a bit useless for us because QEMU doesn't have LEDs, so instead we are going to use one of the UART examples which will print characters we can see on QEMU stdout.
Let's start with the hello world example on an x86 target:
cd ~/zephyrproject/zephyr
west build -b qemu_x86 samples/hello_world -t run
and it outputs:
Hello World! qemu_x86
The qemu_x64 on the output comes from the CONFIG_BOARD macro github.com/zephyrproject-rtos/zephyr/blob/c15ff103001899ba0321b2c38013d1008584edc0/samples/hello_world/src/main.c#L11
#include <zephyr/kernel.h>

int main(void)
{
	printk("Hello World! %s\n", CONFIG_BOARD);
	return 0;
}
You can also first cd into the directory that you want to build in to avoid typing samples/hello_world all the time:
cd ~/zephyrproject/zephyr/samples/hello_world
zephyr west build -b qemu_x86 -t run
You can also build and run separately with:
west build -b qemu_x86
west build -t run
Another important option is:
west build -t menuconfig
But note that it does not modify your prj.conf automatically for you.
Let's try on another target:
rm -rf build
zephyr west build -b qemu_cortex_a53 -t run
and same output, but on a completely different board! The qemu_cortex_a53 board is documented at: docs.zephyrproject.org/3.4.0/boards/arm64/qemu_cortex_a53/doc/index.html
The list of all examples can be seen under:
ls ~/zephyrproject/zephyr/samples
which for example contains:
zephyrproject/zephyr/samples/hello_world
So run another sample simply select it, e.g. to run zephyrproject/zephyr/samples/synchronization:
west build -b qemu_cortex_a53 samples/synchronization -t run
Super Mario 64 reverse engineering project Updated +Created
OMG, both of those just fucking work on Ubuntu 20.04 with README instructions, it is unbelievable, those people don't have lives. And it builds the ROM byte by byte equal from source!
There are a few different versions:
Tested with the USA ROM at sha1sum 9bef1128717f958171a4afac3ed78ee2bb4e86ce (you need a ROM to extract assets, which the project automates), which is also documented in the project itself: github.com/sm64-port/sm64-port/blob/6b47859f757a40096fedd6237f2bc3573d0bc2a4/sm64.us.sha1. Disclaimer: Ciro Santilli owns a copy of Super Mario 64.
The only dependency missing from Ubuntu packages is the IRIX QEMU user mode which they need for their tooling. The project also has a QEMU fork for that, and provide a working deb.
From this project it was also noticed that certain ROM releases were not compiled with optimizations enabled, presumably because as a release title the compiler had optimization bugs! www.resetera.com/threads/so-apparently-the-ntsc-build-of-mario-64-didnt-use-any-compiler-optimizations.166277/ But now they do have a working compiler, and by turning that switch FPS increases in certain levels!!!
It is good to know that this game will "never die".
Some quick stupid patches:
  • jump really high:
    diff --git a/src/game/mario.c b/src/game/mario.c
    index 5b103fa..83c9f40 100644
    --- a/src/game/mario.c
    +++ b/src/game/mario.c
    @@ -826,7 +826,7 @@ static u32 set_mario_action_airborne(struct MarioState *m, u32 action, u32 actio
             case ACT_JUMP:
             case ACT_HOLD_JUMP:
                 m->marioObj->header.gfx.unk38.animID = -1;
    -            set_mario_y_vel_based_on_fspeed(m, 42.0f, 0.25f);
    +            set_mario_y_vel_based_on_fspeed(m, 200.0f, 0.25f);
                 m->forwardVel *= 0.8f;
                 break;
Interesting entry points:
  • src/game/game_init.c
TODO: enable the level select debug feature! tcrf.net/Super_Mario_64_(Nintendo_64)/Debug_Content#Classic_Debug_Display They actually shipped quite a few debug features into the retail game, and they have been reversed too. I tried this but it didn't work (or I don't know how to enable the level select menu):
diff --git a/src/game/main.c b/src/game/main.c
index 9e53e50..b7443a8 100644
--- a/src/game/main.c
+++ b/src/game/main.c
@@ -65,7 +65,7 @@ s8 sAudioEnabled = 1;
 u32 sNumVblanks = 0;
 s8 gResetTimer = 0;
 s8 D_8032C648 = 0;
-s8 gDebugLevelSelect = 0;
+s8 gDebugLevelSelect = 1;
 s8 D_8032C650 = 0;

 s8 gShowProfiler = FALSE;
The enhancements/ folder contains a few sample patches.
Figure 1.
Screenshot of mupen64Plus running on Ubuntu 20.04 emulating Super Mario 64 with the title screen hacked by Ciro Santilli based on the Super Mario 64 reverse engineering project
. The title was on a string, so the hack was trivial! The patch used was:
diff --git a/include/text_strings.h.in b/include/text_strings.h.in
index 749179b..626f87e 100644
--- a/include/text_strings.h.in
+++ b/include/text_strings.h.in
@@ -131,7 +131,7 @@
  */
 // Main Screens
 #define TEXT_MARIO _("MARIO") // View Score Menu
-#define TEXT_SELECT_FILE _("SELECT FILE")
+#define TEXT_SELECT_FILE _("HACKED BY CIRO")
 #define TEXT_CHECK_FILE _("CHECK FILE")
 #define TEXT_COPY_FILE _("COPY FILE")
 #define TEXT_ERASE_FILE _("ERASE FILE")
Some tutorials of hacking it:
Video 1.
FIXING the ENTIRE SM64 Source Code by Kaze Emanuar (2022)
Source. Now that we have the source, modders like this are going nuts.
The lower level you go into a computer, the harder it is to observe things Updated +Created
This is a general principle of software/hardware design that Ciro feels holds wide applicability.
The most extreme case of this is of course the integrated circuit itself, in which it is essentially impossible (?) to observe the specific value of some indidual wire at some point.
Somewhat on the other extreme, we have high level programming languages running on top of an operating system: at this point, you can just GDB step debug your program, print the value of any variable/memory location, and fully understand anything that you want. Provided that you manage to easily reach that point of interest.
And for anything in between we have various intermediate levels of complication. The most notable perhaps being developing the operating system itself. At this level, you can't so easily step debug (although techniques do exist). For early boot or bootloaders for example, you might want to use JTAG for example on real hardware.
In parallel to this, there is also another very important pair of closely linked tradeoffs:
  • the lower level at which something is implemented, the faster it runs
  • emulation gives you observability back, at the cost of slower runtime
Emulation also has another potential downside: unless you are very careful at implementing things correctly, your model might not be representative of the real thing. Also, there may be important tradeoffs between how much the model looks like the real thing, and how fast it runs. For example, QEMU's use of binary translation allows it to run orders of magnitude faster than gem5. However, you are unable to make any predictions about system performance with QEMU, since you are not modelling key elements like the cache or CPU pipeline.
Instrumentation is another technique that has can be considered to achieve greater observability.
User mode emulation Updated +Created
User mode emulation refers to the ability of certain emulators to emulate userland code running on top of a specific operating system, usually Linux.
For example, QEMU allows you to run a variety of userland ELF programs directly on it, without an underlying Linux kernel running.
User mode emulation is achieved by implementing System calls and special filesystems such as /dev manually on the emulator one by one.
The general tradeoff is that simulation is less acurate as it may lack certain highly advanced kernel functionality you haven't implemented yet. But it is much easier to run executables with it, and you don't have to wait for boot to finish before running, you just run executables directly from the command line.