Skip to content

Instantly share code, notes, and snippets.

@jserv
jserv / main.c
Created November 17, 2024 18:53
Object-Oriented Programming (OOP) in C: Render pixel effects using SDL2
/*
* This program demonstrates a simple Object-Oriented Programming (OOP)
* approach in C using function pointers and structures. It renders pixel
* effects onto an RGBA32 buffer using SDL2 for window management and display.
*
* Supported effects:
* - Bitwise operations pattern
* - Mandelbrot fractal visualization
*
* Key controls:
@jserv
jserv / main.c
Created November 17, 2024 17:23
Conway's Game of Life using SDL2 in C99
/*
* Conway's Game of Life using SDL2 in C99
*
* The grid size is dynamically scaled, and the cells are displayed in two
* states: dead and alive. The application uses a double-buffered grid to
* update the cell states based on the classic rules of Conway's Game of Life:
* - Any live cell with fewer than two live neighbors dies (underpopulation).
* - Any live cell with two or three live neighbors lives on to the next
* generation.
* - Any live cell with more than three live neighbors dies (overpopulation).
@jserv
jserv / readers.c
Last active March 24, 2022 02:31
user-level threads using clone system call (incomplete)
#if !defined(__x86_64__)
#error "This program only works for x86_64"
#endif
#define _GNU_SOURCE
#include <errno.h>
#include <limits.h>
#include <linux/futex.h>
#include <sched.h>
#include <signal.h>
@jserv
jserv / Makefile
Created August 20, 2021 12:05
lock-free hashmap
.PHONY: all clean
TARGET = test-hashmap
all: $(TARGET)
include common.mk
CFLAGS = -I.
CFLAGS += -O2 -g
CFLAGS += -std=gnu11 -Wall
@jserv
jserv / Makefile
Created August 20, 2021 11:49
Scheduler Plugin for Linux Kernel
obj-m += proc_queue.o
obj-m += proc_sched.o
obj-m += proc_set.o
PWD := $(shell pwd)
KERNELDIR ?= /lib/modules/`uname -r`/build
PWD := $(shell pwd)
all:
@jserv
jserv / norcu.patch
Created August 19, 2021 02:09
No RCU
diff --git a/fs/Kconfig b/fs/Kconfig
index c229f82..515f76d 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -4,6 +4,12 @@
menu "File systems"
+config DCACHE_NO_RCU
+ def_bool y
@jserv
jserv / Makefile
Last active August 1, 2022 07:26
Lock-free multiple-producer (MP) /multiple-consumer (MC) ring buffer (**incomplete**)
CC = gcc
CFLAGS = -O2 -g -Wall -I.
CFLAGS += -fsanitize=thread
LDFLAGS = -fsanitize=thread
all: lfring
# Control the build verbosity
ifeq ("$(VERBOSE)","1")
Q :=
@jserv
jserv / Makefile
Created August 13, 2021 10:26
Synthesize events for select/poll/epoll (**incomplete***)
MODULENAME := vpoll
obj-m += $(MODULENAME).o
$(MODULENAME)-y += module.o
KERNELDIR ?= /lib/modules/`uname -r`/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
gcc -Wall -o user user.c
@jserv
jserv / vwifi.c
Created August 6, 2021 11:58
virtual cfg80211 driver
#include <linux/module.h>
#include <linux/skbuff.h>
#include <net/cfg80211.h>
#include <linux/mutex.h>
#include <linux/workqueue.h>
#define WIPHY_NAME "owl" /* Our WireLess */
#define NDEV_NAME WIPHY_NAME "%d"
@jserv
jserv / simrupt.c
Created August 6, 2021 11:48
A device that simulates interrupts
/* simrupt: A device that simulates interrupts */
#include <linux/cdev.h>
#include <linux/circ_buf.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kfifo.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/workqueue.h>