Skip to content

Instantly share code, notes, and snippets.

View paranlee's full-sized avatar
🐧
Run RISC-V run!

Paran Lee paranlee

🐧
Run RISC-V run!
View GitHub Profile
@paranlee
paranlee / lkdtm-as-ko.md
Last active February 12, 2023 13:30
LKDTM as lkdtm.ko Module build. https://elixir.bootlin.com/linux/v5.15/source/drivers/misc/lkdtm edit Makefile

Edit Makefile.

# SPDX-License-Identifier: GPL-2.0
KERNEL_PATH ?= /lib/modules/$(shell uname -r)/build

obj-m		+= lkdtm.o

lkdtm-objs		+= core.o
lkdtm-objs		+= bugs.o
@paranlee
paranlee / debug-kernel-build.sh
Created February 10, 2023 14:25
Ubuntu 22.04
# kernel debug build
apt install -y build-essential crossbuild-essential-arm64 libssl-dev libncurses-dev flex bison libelf-dev dwarves pahole
apt install -y linux-source-5.15.0
wget https://src.fedoraproject.org/rpms/kernel/blob/3fbb080931cb5dddc42d2b92d1bfdb810b76d01e/f/kernel-aarch64-debug-rhel.config
# cp kernel-aarch64-debug-rhel.config linux-source-5.15.0/.config
cd linux-source-5.15.0
#
# Automatically generated file; DO NOT EDIT.
# Linux/arm64 5.15.78 Kernel Configuration
#
CONFIG_CC_VERSION_TEXT="aarch64-linux-gnu-gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0"
CONFIG_CC_IS_GCC=y
CONFIG_GCC_VERSION=110300
CONFIG_CLANG_VERSION=0
CONFIG_AS_IS_GNU=y
CONFIG_AS_VERSION=23800
@paranlee
paranlee / DumpHex.c
Created December 13, 2022 11:23 — forked from ccbrown/DumpHex.c
Compact C Hex Dump Function w/ASCII
#include <stdio.h>
void DumpHex(const void* data, size_t size) {
char ascii[17];
size_t i, j;
ascii[16] = '\0';
for (i = 0; i < size; ++i) {
printf("%02X ", ((unsigned char*)data)[i]);
if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~') {
ascii[i % 16] = ((unsigned char*)data)[i];
@paranlee
paranlee / mallocng.md
Created December 12, 2022 12:40 — forked from MaskRay/mallocng.md
musl mallocng

Introduced in musl v1.2.1. Design goal: "Strong hardening against memory usage errors by the caller, including detection of overflows, double-free, and use-after-free, and does not admit corruption of allocator state via these errors."

context

// Singleton: ctx
struct malloc_context {
  uint64_t secret;
#ifndef PAGESIZE
  size_t pagesize;
@paranlee
paranlee / Makefile
Created November 27, 2022 05:07 — forked from chrizchow/Makefile
Linux Minimal ioctl Network Device Example
KDIR := /home/chriz/repositories/WSL2-Linux-Kernel/
obj-m += chriz_ioctl_kernel.o
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
gcc -o chriz_ioctl_user chriz_ioctl_user.c
clean:
rm -rf *.o *.ko *.mod.* *.cmd .module* modules* Module* .*.cmd .tmp*
@paranlee
paranlee / quick_sort_mt.cpp
Created September 5, 2022 14:29 — forked from theodoregoetz/quick_sort_mt.cpp
parallel quicksort in C++11
/**
* g++ -std=c++14 quick_sort_mt.cpp -pthread && ./a.out 10000 1 1
*
*
* This works:
* ./a.out 10000 1 1
*
* This fails (unpredictably!):
* ./a.out 100000 1 1
**/
@paranlee
paranlee / gist:ad5e97d7c70a79fad702632030e46a07
Created August 25, 2022 17:05 — forked from sing1ee/gist:3087723
fibonacci by dynamic programming
# !/usr/bin/python
# -*- encoding: utf-8 -*-
import sys
dp = []
for i in range(100):
dp.append(0)
dp[0] = 0
dp[1] = 1
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/slab.h>
struct birthday {
int day;
int month;
int year;