Skip to content

Instantly share code, notes, and snippets.

View tqinli's full-sized avatar

Qin Li tqinli

View GitHub Profile
@tqinli
tqinli / haproxychash.cs
Created September 14, 2022 21:58
haproxy consistent hashing in csharp
// defined in haproxy/src/hash.c as hash_djb2()
static uint HashDJB2(byte[] input)
{
var key = input;
int i = 0;
uint hash = 5381;
/* the hash unrolled eight times */
var len = input.Length;
for (; len >= 8; len -= 8) {
diff --git a/src/debug/createdump/crashinfo.cpp b/src/debug/createdump/crashinfo.cpp
index 7b5c20bf64..7902c7b5c2 100644
--- a/src/debug/createdump/crashinfo.cpp
+++ b/src/debug/createdump/crashinfo.cpp
@@ -99,6 +99,22 @@ CrashInfo::EnumMemoryRegion(
//
bool
CrashInfo::EnumerateAndSuspendThreads()
+{
+ std::set<pid_t> suspendedTaskIds;
using System.Diagnostics;
using System.Runtime.InteropServices;
using TTD.Common.Diagnostics;
// Console.WriteLine("Dumping...");
// var parent = Process.GetCurrentProcess();
// SysCallInterop.Kill(parent, SigNum.SIGSEGV);
// Console.WriteLine("Dumped!");
Task.Run(
#!/usr/bin/python3
import ctypes
import sys
import os
import time
PTRACE_ATTACH = 16
PTRACE_DETACH = 17
@tqinli
tqinli / hijackprolog.cs
Created September 18, 2020 07:48
HijackThread function prolog repro
using System;
using System.Threading;
namespace HijackThreadFuncPrologRepro
{
class Program
{
static long HugeFunction(
long var000,
long var001,
@tqinli
tqinli / clr-configuration-knobs.md
Created September 10, 2020 23:49
CLR Configuration Knobs

Saved from here: https://github.com/steveharter/dotnet_coreclr/blob/master/Documentation/project-docs/clr-configuration-knobs.md

There are two primary ways to configure runtime behavior: CoreCLR hosts can pass in key-value string pairs during runtime initialization, or users can set special variables in the environment or registry. Today, the set of configuration options that can be set via the former method is relatively small, but moving forward, we expect to add more options there. Each set of options is described below.

Host Configuration Knobs

These can be passed in by a host during initialization. Note that the values are all passed in as strings, so if the type is boolean, the value would be the string "true" or "false", and if it's a numeric value, it would be in the form "123".

Name | Description | Type

@tqinli
tqinli / pal_cs_repro.cpp
Last active April 19, 2020 21:18
A repro for pthread_cond_wait/signal's issue of losing signal (using .net core libcoreclrpal.a)
// To compile (have libcoreclrpal.a in current dir)
// g++ -g -o pal_cs_repro ./pal_cs_repro.cpp -L. -lcoreclrpal -lpthread -ldl
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <assert.h>
@tqinli
tqinli / pthread_cond_repro.c
Last active February 24, 2023 22:52
A repro for pthread_cond_wait/signal's issue of losing signal
// To compile
// gcc -g -o pthread_cond_repro ./pthread_cond_repro.c -lpthread
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <assert.h>