Skip to content

Instantly share code, notes, and snippets.

@ikskuh
ikskuh / async_await.zig
Last active July 11, 2022 08:41
Async Await in 60 LOC
const std = @import("std");
// usage:
fn asyncMain() !void {
// Start two interleaving tasks
var task_a = async waitUntilAndPrint(start + 1000, start + 1200, "task a");
var task_b = async waitUntilAndPrint(start + 500, start + 1300, "task b");
var task_c = async waitUntilAndPrint(start + 800, start + 1100, "task c");
await task_a;

Emscripten as a linker for Zig and C

This shows how to build a nontrivial program using Zig+Emscripten or C+Emscripten. In both cases Emscripten is only used as a linker, that is the frontend is either zig or clang.

"Nontrivial" here means the program uses interesting Emscripten features:

  • Asyncify
  • Full GLES3 support
  • GLFW3 support
@moyix
moyix / killbutmakeitlooklikeanaccident.sh
Created February 5, 2022 22:51
Script to inject an exit(0) syscall into a running process. NB: only x86_64 for now!
#!/bin/bash
gdb -p "$1" -batch -ex 'set {short}$rip = 0x050f' -ex 'set $rax=231' -ex 'set $rdi=0' -ex 'cont'