Skip to content

Instantly share code, notes, and snippets.

View jimblandy's full-sized avatar

Jim Blandy jimblandy

View GitHub Profile
@jimblandy
jimblandy / shmem.md
Last active July 1, 2022 08:17
Explanation of Firefox's `mozilla::ipc::Shmem`

ipc::Shmem and friends

The mozilla::ipc::Shmem type represents a block of memory that IPDL messages can transfer between processes without having to copy the contents. IPDL messages can pass and Shmem arguments, as in these examples from PWebGPU.ipdl:

async BufferReturnShmem(RawId selfId, Shmem shmem);
async BufferMap(RawId selfId, WGPUHostMap hostMap, uint64_t offset, uint64_t size) returns (Shmem sm);

Given a Shmem s, you can call s.Size<T> to get the length of the shared memory block considered as an array of T values, and s.get<T> to get a T* pointing to the first element.

A Shmem is usually first constructed with no memory allocated to it, using the default constructor. For example, the[Device::CreateBuffer][cbi] method in Firefox's WebGPU implementation declares a Shmem like this:

@jimblandy
jimblandy / sqrt-2-irrational.md
Last active October 14, 2021 17:59
Proof that the square root of two is irrational

Prep questions:

  • Suppose x is even. If we multiply it by something, is the product always even, always odd, or does it depend?
  • Suppose x is even. Is x^2 always even, always odd, or does it depend?
  • Suppose x is odd. Is x^2 always even, always odd, or does it depend?
  • Suppose p/q is a fraction in lowest terms. Can both the top and bottom be even? Can they both be odd? Can one be even, and one odd?
  • What happens when we square a fraction?
  • What happens when we square a product, say, pq?

Rules:

  • "x is even" means "For some integer k, x = 2k."
@jimblandy
jimblandy / customizations.el
Created July 22, 2021 21:29
My Rust configuration for Emacs. Not tested or really prepared for publication, just offered as-is.
;; Customizations. I think you need to integrate these into the existing calls to `custom-set-variables`
;; and `custom-set-faces`.
(custom-set-variables
'(lsp-keymap-prefix "C-S-l")
'(lsp-rust-all-features t)
'(lsp-rust-analyzer-diagnostics-disabled ["unresolved-proc-macro"])
'(lsp-rust-analyzer-display-chaining-hints t)
'(lsp-rust-analyzer-display-parameter-hints t)
'(lsp-rust-analyzer-server-command '("rust-analyzer-linux"))
@jimblandy
jimblandy / dump-type.py
Last active April 21, 2024 15:09
GDB Python script to define a command for inspecting types.
# Put this in a file BLAH/dump-type.py and then put this in your ~/.gdbinit file
# (or type it at the GDB prompt):
#
# source BLAH/dump-type.py
#
# Then you can say:
#
# (gdb) help jimb-dump-type
#
# and you should get a help message.
@jimblandy
jimblandy / threads-memory.c
Created April 23, 2020 21:34
Program to create N boring threads that do nothing, for measuring minimal per-thread memory use
#include <pthread.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define NUM_THREADS 500
#define BYTES_PER_THREAD 1024 * 1024 // 1 MB
void *child_main(void *num_threads_ready) {
@jimblandy
jimblandy / transforms.html
Created February 12, 2020 22:40
playing with SVG transforms
<html>
<head></head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400">
<rect x="50" y="50" width="100" height="220" fill="none" stroke="black"/>
<rect x="30" y="20" width="60" height="190" fill="none" stroke="gray"/>
<g id="outer">
<g id="inner" transform="rotate(10) translate(200,0)">
<rect id="red" x="50" y="50" height="100" width="100" fill="red"/>
<rect id="blue" x="50" y="170" height="100" width="100" fill="blue"/>
@jimblandy
jimblandy / the-heck-emacs.sh
Created July 2, 2019 16:53
Script for figuring out what (interesting) system calls Emacs is doing
#!/usr/bin/env bash
strace -p "$(pgrep emacs)" \
-e '!pselect6,recvmsg,poll,writev,rt_sigprocmask,rt_sigreturn,read,write,timerfd_settime' \
-e 'signal=!SIGIO'
# -e '!pselect6,rt_sigprocmask,rt_sigreturn,timerfd_settime' \
@jimblandy
jimblandy / weak-references.md
Last active May 15, 2019 00:29
Take a stab at specifying the conditions under which weak references can be cut

From the spec's point of view, all objects live forever. Garbage collection is just an optimization, permitted only because it is undetectable. Even though weak references are generally seen as making GC visible, we can actually specify weak references in a way that preserves the traditional approach: the spec will still assume all objects live forever, and will merely describe when it is permitted to remove certain edges to them.

An object is "relevant" if replacing it with any arbitrary other object could have a visible effect on the future execution of the program.

@jimblandy
jimblandy / jit-comment.patch
Created April 15, 2019 18:21
Fix comment in jit::CanEnterBaselineAtBranch
diff --git a/js/src/jit/BaselineJIT.cpp b/js/src/jit/BaselineJIT.cpp
--- a/js/src/jit/BaselineJIT.cpp
+++ b/js/src/jit/BaselineJIT.cpp
@@ -276,19 +276,19 @@ MethodStatus jit::CanEnterBaselineAtBran
InterpreterFrame* fp) {
if (!CheckFrame(fp)) {
return Method_CantCompile;
}
// This check is needed in the following corner case. Consider a function h,
@jimblandy
jimblandy / bah.js
Created March 27, 2019 21:32
This should print two completions before 'callback', right???
let g = newGlobal({newCompartment: true});
g.eval(`
async function f() {
debugger;
await Promise.resolve(3);
return "ok";
}
`);
let dbg = Debugger(g);