Skip to content

Instantly share code, notes, and snippets.

View flounderK's full-sized avatar
💭
Screaming in confusion

Clif Wolfe flounderK

💭
Screaming in confusion
  • Good god I’m lost
View GitHub Profile
#ifndef INTRUSIVE_LIST_H
#define INTRUSIVE_LIST_H
#include <stddef.h>
/* Basic intrusive doubly-linked list node */
struct list_head {
struct list_head *next, *prev;
};
@flounderK
flounderK / build_kernel.sh
Created May 25, 2025 18:56
Build linux kernel in a different output directory
git clone https://github.com/torvalds/linux.git
cd linux
mkdir -p build
KBUILD_OUTPUT=build make O=build -j $(($(nproc)-1)) defconfig
KBUILD_OUTPUT=build make O=build -j $(($(nproc)-1))
import re
import subprocess
import os
import pty
import tty
import fcntl
import stat
import threading
from queue import Queue
import logging
@flounderK
flounderK / kconfig.cmake
Last active May 11, 2025 13:43
kconfig_cmake
function(set_kconfig_vars_from_file FILENAME)
# Optional Kconfig integration
if(EXISTS "${FILENAME}")
file(READ "${FILENAME}" KCONFIG_CONTENTS)
string(REGEX MATCHALL "CONFIG_[A-Za-z0-9_]+=(y|n)" KCONFIG_LINES "${KCONFIG_CONTENTS}")
foreach(line ${KCONFIG_LINES})
message("${line}")
string(REPLACE "=" ";" line_parts ${line})
list(GET line_parts 0 VAR)
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
cmake -S llvm -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_PROJECTS=clang
ninja -C build
@flounderK
flounderK / gist:de6bce77ea4bea357eff227542eae65b
Created April 11, 2025 02:53
gather code coverage with clang
clang -fprofile-instr-generate -fcoverage-mapping -o main main.c
LLVM_PROFILE_FILE="prof.profraw" ./main
# merge many profraw files into a profdata
llvm-profdata merge -sparse prof.profraw -o prof.profdata
# show coverage
llvm-cov show ./main -instr-profile=prof.profdata
CFLAGS="-fsanitize=undefined" make
@flounderK
flounderK / gist:aa8181351777c8056bb056f8285287a5
Last active April 11, 2025 02:28
gather code coverage information with gcov in gcc
# build targets with code coverage, CFLAGS bit only works if `+=` is used in the make file
CFLAGS="-fprofile-arcs -ftest-coverage" make CC=gcc
# <run test case>
# create files for all coverage reached by test case (don't use if using lcov)
find . -type f -iname '*.gcda' |xargs gcov
# generate coverage file for gcda files under this directory
lcov -c -d . -o coverage.info
@flounderK
flounderK / python_ctypes_primitives.py
Created March 2, 2024 15:56
python ctypes primitives
import ctypes
def arb_read(addr, size=4):
return bytes((ctypes.c_byte*size).from_address(addr))
def arb_write(addr, byts):
(ctypes.c_byte*len(byts)).from_address(addr)[:] = byts
def rough_addr_of(a):
@flounderK
flounderK / build_snort3.sh
Created January 19, 2024 14:22
building snort3
# build libdaq from source
git clone https://github.com/snort3/libdaq
cd libdaq
./bootstrap
mkdir build
cd build
../configure
make
cd ../../