Skip to content

Instantly share code, notes, and snippets.

@jvns
jvns / executing-file.md
Last active August 30, 2024 17:24
What happens when I run ./hello
@jvns
jvns / examples.md
Last active June 12, 2022 11:10
Rust examples

Strings

The std::str documentation is also quite good.

// Create a string from a literal
let hello: &'static str = "Hello!";
let hello2: &str = "Hello!";
@jvns
jvns / rust-types.md
Last active October 5, 2021 08:41
Rust type tutorial

I found understanding Rust types really confusing, so I wrote up a small tutorial for myself in an attempt to understand some of them. This is by no means exhaustive. There is a types section in the manual, but it has nowhere near enough examples.

I'm not talking about managed pointers (@) at all. A lot of the difficulty with Rust types is that the language is constantly changing, so this will likely be out of date soon.

First, a few preliminaries: it's easier to play with types if you have a REPL and can interactively check the types of objects. This isn't really possible in Rust, but there are workarounds.

To start out: some help

How to get a Rust REPL

@jvns
jvns / help_what_eep_ack.asm
Created December 5, 2013 18:12
assembly code for absurd keycode situation
.file "blah.rc"
.text
.globl _ZN5stdio12clear_screen19h458d5a7d48ef5f58aj4v0.0E
.align 16, 0x90
.type _ZN5stdio12clear_screen19h458d5a7d48ef5f58aj4v0.0E,@function
_ZN5stdio12clear_screen19h458d5a7d48ef5f58aj4v0.0E:
.cfi_startproc
cmpl %gs:48, %esp
ja .LBB0_2
pushl $8
@jvns
jvns / ridiculous_bug.md
Last active December 30, 2015 09:39
Ridiculous bug that I don't understand

I'm trying to set up keycode handling in my kernel, and I'm having a strange problem with array indexing.

When I run this code, and press 1 several times, it prints |2C |2C |2C |2C |2C |2C |2C |2C |2C .

I am expecting it to print |2C2|2C2|2C2|2C2|2C2|2C2|2C2|2C2|2C2|.

  • the 2 is printed by putc(NUMS[2])
  • the C is printed by putc(65 + keycode). This implies that keycode == 2, since 65 is 'A'
  • the | is printed by putc(NUMS[keycode]) and a delimiter. I would expect this to print 2|. But no.
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('h2').html("Hello, Arielle!");
})
</script>
</head>
<body>
@jvns
jvns / linkers.md
Last active May 17, 2025 11:07
Notes on linkers
@jvns
jvns / linkers_101.md
Last active November 18, 2018 14:38
How to understand what's in a binary, with code!

Step 0: A program, and prerequisites

We're going to be dealing with a "Hello, world!" program. Just one. There's going to be a bunch of fruit for discussion here. I'm going to be assuming you're on Linux, because we're gonna be talking about ELF and Macs use Mach-O and I don't know anything about Mach-O.

#include <stdio.h>

char *penguin = "Penguin";
char array[5] = {'a', 'b', 'c', 'd', 'e'};
@jvns
jvns / how-to-hello-world.md
Last active December 31, 2015 05:19
Steps to "Hello, world!"

I want to compile a 32-bit "Hello, world!" statically-linked ELF binary for Linux, and try to run it in my operating system. I'm trying to understand what I'll have to do. The goal is to get everything just barely working, so that it will print the string to the screen and not crash the whole system.

I asked a question about this a little while ago, and got lots of helpful responses. Now I need to make it a bit more concrete, though.

diff --git a/core/lib.rs b/core/lib.rs
index 5d4bb69..a18ce21 100644
--- a/core/lib.rs
+++ b/core/lib.rs
@@ -15,7 +15,7 @@
#[crate_type = "rlib"];
#[feature(macro_rules)];
-#[cfg(libc)]
+#[cfg(libc, pthread)]