Skip to content

Instantly share code, notes, and snippets.

View KJTsanaktsidis's full-sized avatar

KJ Tsanaktsidis KJTsanaktsidis

View GitHub Profile
[INFO log_pending_events()] (no pending events)
[RecordSession] 1142629: handle_ptrace_event PTRACE_EVENT_SECCOMP: event (none)
[RecordSession] traced syscall entered: execve
[RecordSession] EXEC_SYSCALL_ENTRY: status=0x7057f (PTRACE_EVENT_SECCOMP)
[RecordTask] Wrote event SYSCALLBUF_FLUSH for time 42069
[RecordTask] Syscallbuf flushed with num_rec_bytes=80
[RecordTask] Wrote event SYSCALL: execve for time 42070
[RecordTask] Syscallbuf reset
[RecordTask] Wrote event SYSCALLBUF_RESET for time 42071
[RecordSession] after cont: status=0x7057f (PTRACE_EVENT_SECCOMP)
@KJTsanaktsidis
KJTsanaktsidis / utf8_validation_benchmark.rb
Created February 13, 2024 00:39
utf8_validation_benchmark.rb
# frozen_string_literal: true
puts "setting up gems..."
require 'bundler/inline'
gemfile do
gem 'activesupport', '~> 7'
gem 'benchmark-ips', '~> 2'
gemspec path: '.'
end
@KJTsanaktsidis
KJTsanaktsidis / uffd.c
Created January 10, 2024 23:25
User fault handling example
#define _GNU_SOURCE
#include <err.h>
#include <fcntl.h>
#include <linux/userfaultfd.h>
#include <poll.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@KJTsanaktsidis
KJTsanaktsidis / gai_debug.c
Created December 8, 2023 09:40
Bug #20048 debugging
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <errno.h>
#include <string.h>
#include <stdbool.h>
# frozen_string_literal: true
module TrapDetection
def trap(signal, action = nil, &block)
# A block might or might not be given, and action might be absent, a string, or
# a callable. It's actually legal to pass both action and block to Signal.trap, but
# in that case the block is ignored.
if action.respond_to?(:call)
action = Thunk.new(action)
end
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Flame Graph</title>
<meta name="template_version" content="4.0.7"><script>!function(t){var n={};function e(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,e),i.l=!0,i.exports}e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var i in t)e.d(r,i,function(n){return t[n]}.bind(null,i));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProp
Thread 1 locks the mutex
Thread 1 can get the resource
Thread 1 sleeps for a while ("sleep with resource #1")
Thread 2 tries to lock the mutex, gets put on the waitq
Thread 3 tries to lock the mutex, now the waitq is [2, 3]
Thread 1 returns the resource and unlocks the mutex
Thread 1 signals thread 2, since it's first on the waitq
Thread 2 is eligible for running now (according to ruby) but it's blocked waiting for the GVL
Thread 1 locks the mutex again
Thread 1 takes the resource again
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>
(gdb) info threads
Id Target Id Frame
* 1 LWP 100729 of process 15250 _umtx_op_err () at /usr/src/lib/libthr/arch/amd64/amd64/_umtx_op_err.S:40
2 LWP 105716 of process 15250 _umtx_op_err () at /usr/src/lib/libthr/arch/amd64/amd64/_umtx_op_err.S:40
(gdb) thread 1
[Switching to thread 1 (LWP 100729 of process 15250)]
#0 _umtx_op_err () at /usr/src/lib/libthr/arch/amd64/amd64/_umtx_op_err.S:40
40 in /usr/src/lib/libthr/arch/amd64/amd64/_umtx_op_err.S
(gdb) bt
#0 _umtx_op_err () at /usr/src/lib/libthr/arch/amd64/amd64/_umtx_op_err.S:40
(gdb) info threads
Id Target Id Frame
* 1 LWP 944671 of process 58279 _sigprocmask () at _sigprocmask.S:4
2 LWP 944703 of process 58279 "Timeout stdlib thre" thr_kill () at thr_kill.S:4
(gdb) bt
#0 _sigprocmask () at _sigprocmask.S:4
#1 0x000034cbaa077b44 in handle_signal (actp=actp@entry=0x34cba58367c0, sig=sig@entry=26, info=info@entry=0x34cba5836bb0, ucp=ucp@entry=0x34cba5836840) at /usr/src/lib/libthr/thread/thr_sig.c:288
#2 0x000034cbaa07711f in thr_sighandler (sig=26, info=0x0, _ucp=0x0) at /usr/src/lib/libthr/thread/thr_sig.c:246
#3 <signal handler called>
#4 _umtx_op_err () at /usr/src/lib/libthr/arch/amd64/amd64/_umtx_op_err.S:40