You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/2024/books.md
+28-13
Original file line number
Diff line number
Diff line change
@@ -11,69 +11,84 @@ tags = []
11
11
12
12
This year I planed to venture out of my comfort zone and read more non-fiction, but in the end allmost all of my favorite books still ended up being sci-fi.
A world you can easily get lost in, filled with intrigues, politics, and a very unique culture. A diverse cast of characters with their own motivations and goals, that doesn't feel forced or tokenized. Definitely one of my favorite series of all time, and I'm looking forward to more books set in this universe.
17
19
20
+
<br />
21
+
18
22
# [The Murderbot Diaries](https://www.goodreads.com/series/191900-the-murderbot-diaries) by Martha Wells
19
23
20
24
If you need something a bit more light-hearted, I can highly recommend the Murderbot Diaries. It's a series of novellas about a murderous robot that just wants to be left alone to watch TV. Even though he's not human, Martha Wells does a fantastic job of creating an empathetic character. While there's quite a few books already, most of them are pretty short and you won't be able to put them down. The latest book in the series came out at the end of 2023 and I'm looking forward to more books in the series.
21
25
26
+
<br />
27
+
22
28
# [The Hitchhiker's Guide to the Galaxy](https://www.goodreads.com/series/40957-the-hitchhiker-s-guide-to-the-galaxy) by Douglas Adams
23
29
24
30
The movie was never really my thing, but I'm glad I finally read the book. Douglas Adams's writing style is just so fun, but sometimes it can be a bit too much.
25
31
It has something for everyone, but I recommend stopping after 'So Long, and Thanks for All the Fish', probably the best book in the series.
26
32
A couple of days ago I've also started reading [Colour of Magic](https://www.goodreads.com/book/show/8695.The_Colour_of_Magic) by Terry Pratchett, and so far it's a very similar style of humor, without as much absurdity - I'm looking forward to reading more of Discworld.
27
33
34
+
<br />
35
+
28
36
# [Ra](https://www.goodreads.com/book/show/57891607-ra) by Sam Hughes
29
37
30
38
A very unique and super creative take on "Magic Systems", but don't let that fool you, this is a hard sci-fi book. Most of the abstracts and summaries I've seen online don't do it justice, and it's worth to finish the book even if you're not sure about it at the start, great plot twists and a very satisfying ending.
31
39
I also recommend [Valuable Humans in Transit and Other Stories](https://www.goodreads.com/book/show/63198504-valuable-humans-in-transit-and-other-stories?ref=nav_sb_ss_1_26) and [There Is No Antimemetics Division](https://www.goodreads.com/book/show/54870256-there-is-no-antimemetics-division?ref=rae_2) by Qntm/Sam Hughes, they're both free on [his website](https://qntm.org/scp).
32
40
41
+
<br />
42
+
33
43
# [The Metamorphosis of Prime Intellect](https://www.goodreads.com/book/show/64341.The_Metamorphosis_of_Prime_Intellect) by Roger Williams
34
44
35
45
I found this book from a recommendation on a [Podcast](https://www.youtube.com/watch?v=dNrTrx42DGQ) about AI safety and AGI. It explores some interesting topics around the nature of consciousness, immortality, and Singularity but I definitely have to warn you that the book can be pretty dark and disturbing at times. It takes place in a world with no moral constraints and the author doesn't shy away from the darker sides of human nature.
36
46
37
47
[A Casino Odyssey in Cyberspace](https://www.goodreads.com/book/show/41569567-a-casino-odyssey-in-cyberspace) is a sequel to this book, kind of going more into a post-scarcity world,
38
48
and if you liked the first book you should definitely also check his [The Mortal Passage Trilogy](https://www.goodreads.com/book/show/24237204-the-mortal-passage-trilogy?ac=1&from_search=true&qid=DT495nnrDR&rank=1). Most of his books are available for free on his [website](http://localroger.com/prime-intellect/).
39
49
50
+
<br />
51
+
40
52
# [Do Androids Dream of Electric Sheep?](https://www.goodreads.com/book/show/36402034-do-androids-dream-of-electric-sheep) by Philip K. Dick
41
53
42
54
I don't know how I've not read it or watched the movies until now, such well made and thought provoking world building.
43
55
There's soo much of the same story on self aware robots, but PKD's somehow over 50 years old book still feels fresh.
44
56
The most interesting part for me was the societies view on animals, and how they've become a symbol of status and empathy.
45
57
58
+
<br />
59
+
46
60
# [UNIX: A History and a Memoir](https://www.goodreads.com/book/show/53011383-unix) by Brian W. Kernighan
47
61
48
62
A surprisingly inspiring book about the history of UNIX and the people behind it. Just makes you jealous the meeting all of these people working at Bell Labs and the early days of computing. The book goes a bit into the philosophy of UNIX and the design decisions that made it so successful, but it's more so focused on the people and the history of the project.
49
63
64
+
<br />
65
+
50
66
# [The Phantom Tollbooth](https://www.goodreads.com/book/show/378.The_Phantom_Tollbooth) by Norton Juster
51
67
52
68
Essentially a children's book, but I still found it very enjoyable as an adult. It's just so clever and fun, definitely something that can make a bad day better, and I'm sure I'll be reading it again in the future. Helps you remember to slow down and enjoy the journey.
53
69
70
+
<br />
71
+
54
72
# Honorable Mentions
55
73
56
74
As a honorable mention I also want to mention some books that I read this year. These held up surprisingly well and all of them are worth a read (or re-read).
57
75
58
-
## [Brave New World](https://www.goodreads.com/book/show/5129.Brave_New_World) by Aldous Huxley
76
+
## > [Brave New World](https://www.goodreads.com/book/show/5129.Brave_New_World) by Aldous Huxley
59
77
60
-
## [1984](https://www.goodreads.com/book/show/40961427-1984) by George Orwell
78
+
## > [1984](https://www.goodreads.com/book/show/40961427-1984) by George Orwell
61
79
62
-
## [Fahrenheit 451](https://www.goodreads.com/book/show/13079982-fahrenheit-451) by Ray Bradbury
80
+
## > [Fahrenheit 451](https://www.goodreads.com/book/show/13079982-fahrenheit-451) by Ray Bradbury
63
81
64
-
## [The Time Machine](https://www.goodreads.com/book/show/2493.The_Time_Machine?ref=nav_sb_ss_5_9) by H.G. Wells
82
+
## > [The Time Machine](https://www.goodreads.com/book/show/2493.The_Time_Machine?ref=nav_sb_ss_5_9) by H.G. Wells
65
83
66
-
## [Ender’s Game](https://www.goodreads.com/book/show/375802.Ender_s_Game) by Orson Scott Card
84
+
## > [Ender’s Game](https://www.goodreads.com/book/show/375802.Ender_s_Game) by Orson Scott Card
67
85
68
-
## [Sidhartha](https://www.goodreads.com/book/show/52036.Siddhartha) by Hermann Hesse
86
+
## > [Sidhartha](https://www.goodreads.com/book/show/52036.Siddhartha) by Hermann Hesse
69
87
70
-
## [The Count of Monte Cristo](https://www.goodreads.com/book/show/7126.The_Count_of_Monte_Cristo) by Alexandre Dumas
88
+
## > [The Count of Monte Cristo](https://www.goodreads.com/book/show/7126.The_Count_of_Monte_Cristo) by Alexandre Dumas
71
89
72
-
## [Slaughterhouse-Five](https://www.goodreads.com/book/show/4981.Slaughterhouse_Five) by Kurt Vonnegut
90
+
## > [Slaughterhouse-Five](https://www.goodreads.com/book/show/4981.Slaughterhouse_Five) by Kurt Vonnegut
73
91
74
-
I hope you found something interesting in this list, and for more recommendations you can check out my [Goodreads page](https://www.goodreads.com/review/list/129153443-henry?shelf=read) or [my reading list](https://www.goodreads.com/review/list/129153443-henry?shelf=to-read).
75
-
76
-
<br/>
77
-
<br/>
92
+
<br />
78
93
79
-
Oh, and a new post on my [Rust OS series](/series/rust-os/) is coming soon, some great new things have happened in the Rust embedded space in the last couple of months.
94
+
I hope you found something interesting in this list, and for more recommendations you can check out my [Goodreads page](https://www.goodreads.com/review/list/129153443-henry?shelf=read) or [my reading list](https://www.goodreads.com/review/list/129153443-henry?shelf=to-read).
title: "TinyWasm: How I wrote my own WebAssembly Runtime"
3
+
date: 2024-10-06
4
+
draft: true
5
+
---
6
+
7
+
<!--
8
+
Talk about how big scary words and jargon don't matter. Bruteforceing your way through works. don't be afraid to throw away code. **Be** afraid to ask for help: with the right mindset, you can figure it out yourself (might not work for everyone ?).
9
+
-->
10
+
11
+
After a long hiatus from writing on this blog, I'm back with a small update on what I've been working on lately (or rather slowly catchin op on the backlog of posts I wanted to write).
12
+
13
+
This summer, I finally finished writing my bachelor's thesis on the topic of WebAssembly and Edge Computing. More on that (probably) in a later post, but for now, I wanted to talk about another project I worked on earlier this year that inspired a lot of the work I did for my thesis: TinyWasm.
14
+
15
+
## <u>**TinyWasm**</u>
16
+
17
+
When writing my posts on [OS Development](https://blog.henrygressmann.de/series/rust-os/) last year, I got really interested in the topic of WebAssembly and wanted to try it out inside of the kernel. I was kind of got fed up with writing context switching and memory management code and WebAssembly it looked like an easy way to run existing code in the operating system.
18
+
I had a look at the existing interpreters and compilers for WebAssembly, but they were all either too complex or had too many dependencies for my taste (I was going for embedded systems, so it had to be lightweight).
19
+
20
+
So, without only minimal prior experience with both WebAssembly and compilers/interpreters, I now had the topic for my capstone project: A tiny WebAssembly runtime. I've been pretty burned on a lot of (unneccessarily) complex projects in the past, so, to keep myself on track, I decided to set out some constraints at the start to actually finish it on time:
21
+
22
+
1.**No Platform-Specific Code**: My first goal was to remove all dependencies on platform-specific code, so everything could work in Rust's `no_std` environment. This also meant that I couldn't use many of the existing libraries for WebAssembly. Thankfully, a really good crate for parsing WebAssembly binaries already existed: [`wasmparser`](https://github.com/bytecodealliance/wasm-tools) (however with no `no_std` support at the time).
23
+
24
+
2.**Build the MVP**: Just focus on the initial version of WebAssembly, so no threads, no SIMD, no garbage collection, etc.
25
+
26
+
3.**Keep it simple**: I wanted the codebase to be as small and readable as possible to make it easier to integrate into other projects such as my OS. No premature optimization.
27
+
28
+
4.**No Unsafe Code**: This one came a bit later, but I decided to avoid unsafe Rust code entirely (maybe something for another post).
29
+
30
+
I started out by taking a simple "Hello World" WebAssembly program and tried to infer everything I needed from there. Surprisingly, this worked pretty well and in a super short amount of time. This gave me some slightly missplaced confidence that everything was going to be smooth sailing from here on out.
31
+
32
+
{{ figure(caption = "I couldn't find a good XKCD comic for this, so here's one on graphs instead.", position="center", src="./assets/image.png", invert=true, mixblend=true, link="https://www.xkcd.com/688/") }}
33
+
34
+
With this newly gained confidence, I scrapped the initial codebase and started from scratch. Starting with a simple public API, I did something very unlike me: TDD. Now, I'm sorry for subjecting you to this, but essentially following a long document that outlines everything about WebAssembly (the [specification](https://webassembly.github.io/spec/core/index.html)), you just have to write tests for everything. Thankfully, I didn't actually have to write any of these tests myself, as the reference interpreter conveniently already has thousands of them covering a lot of edge cases (that are also often not clear from the specification). Plumbing these tests into my own test suite was a bit of a pain, but in the end I had a sweet script that would run all of the relevant tests and give me a nice graph of how many tests I had passed (and some dopamine hits when the number went up).
Now was about the time my newly found confidence started to decline.
39
+
40
+
Not to throw the blame on the specification, but it's hard to grasp as someone from the outside. A lot of abstraction, (probably?) needless complexity and leaving things up to the implementer. I spent about a week just looking at different interpreters and their APIs to get a better understanding of what I was supposed to do. Most of the time, I just ended up taking a couple of tests from one of the test suites and trying to get them to pass, which worked suprisingly well. Slowly but surely, the numbers went up and more and more tests passed.
41
+
42
+
Predictably, once I reached only about 80/2000+ tests left, I still had about 20% of my work and a couple of long nights ahead of me. But finally, once all tests passed, I just compiled the interpreter to WebAssembly and ran it using TinyWasm itself. It worked on the first try. I was completely confused, but I guess LLVM randomly did the right optimizations that made it work.
43
+
44
+
I was super happy with the results, and I'm still pushing the odd update here and there. As of now, it's at the point of supporting WebAssembly V2 (without SIMD and threads) and a couple of proposals. I also posted it on HN and Reddit, where I got some nice feedback and a couple of stars on GitHub (obviously the most important part).
0 commit comments