Skip to content

Instantly share code, notes, and snippets.

@jserv
jserv / disable-selinux.patch
Created February 23, 2013 11:46
Disable the protection of SELinux in olibc dynamic linker
diff --git a/linker/linker_environ.cpp b/linker/linker_environ.cpp
index edc659a..4a6e4a0 100644
--- a/linker/linker_environ.cpp
+++ b/linker/linker_environ.cpp
@@ -42,20 +42,6 @@ bool get_AT_SECURE() {
return _AT_SECURE_value;
}
-static void __init_AT_SECURE(KernelArgumentBlock& args) {
- // Check auxv for AT_SECURE first to see if program is setuid, setgid,
@jserv
jserv / string.c
Created October 8, 2013 15:46
The missing string.c
#include <stddef.h>
#include <stdint.h>
#include <limits.h>
#define ALIGN (sizeof(size_t))
#define ONES ((size_t)-1/UCHAR_MAX)
#define HIGHS (ONES * (UCHAR_MAX/2+1))
#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
#define SS (sizeof(size_t))
@jserv
jserv / exec_with_gdb.sh
Created April 26, 2017 19:37
GDB runner
# Execute an executable under gdb, printing a call stack if we get a crash.
gdb -return-child-result -quiet -batch \
-ex "set env MALLOC_CHECK_=3" \
-ex "set print thread-events off" \
-ex run \
-ex "thread apply all backtrace full" \
-ex "quit" \
$*
@jserv
jserv / pyc.py
Last active March 13, 2021 11:27
import atexit
import ctypes
import os
import shlex
import sys
import tempfile
CMD_C_TO_SO = '{compiler} -shared -o {output} {input} {libraries}'
@jserv
jserv / naive-sum.c
Last active September 1, 2019 06:48
#include <stdio.h>
#define NUM 10000
int main() {
float sum = 0.0f;
for (int i = 0; i < NUM; i++) sum += i + 1;
printf("Sum: %f\n", sum);
return 0;
}
#include <stdio.h>
static void test() { puts(__func__); }
int main() {
typedef void (*callback_t)(void);
callback_t cb = &test;
(*cb)();
}
#include <assert.h>
#include <fcntl.h>
#include <limits.h>
#include <semaphore.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
/* Simple port forwarder */
#define _GNU_SOURCE 1
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <netdb.h>
#include <stdbool.h>
#include <stdio.h>
#include <inttypes.h>
#include <sys/time.h>
enum {
EV_READ = (1 << 0),
EV_WRITE = (1 << 1),
EV_TIMEOUT_ONESHOT = (1 << 2),
EV_TIMEOUT_PERIODIC = (1 << 3),
EV_SIGNAL = (1 << 4),
EV_CLOEXEC = (1 << 0),
@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>