Skip to content

Instantly share code, notes, and snippets.

@bgaff
bgaff / pkru.c
Created November 9, 2021 01:41
11th Gen Core CPU PKRU
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/mman.h>
static uint32_t rdpkru(void)
{
uint32_t ecx = 0;
uint32_t edx, pkru;
@bgaff
bgaff / repro.c
Created November 8, 2021 17:26
rdpkru - Intel 11th Gen Core CPU bug
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/mman.h>
#define BITS_PER_PKEY 2
static uint32_t rdpkru(void)
{
uint32_t ecx = 0;
#define _GNU_SOURCE
#include <sys/mman.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#ifndef MREMAP_DONTUNMAP
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <iostream>
#include <functional>
#include <memory>
#include <cstdio>
void* _saved_return;
void* _saved_bp;
#define NO_INLINE __attribute__((noinline))
#define SET_OLD_RBP() \
#include <iostream>
#include <functional>
#include <memory>
#define GET_RETURN_VALUE64(VAR) \
asm ("nop\n nop\n movq %%rax,%0 \n nop\n" \
: "=r" (VAR) \
: \
: "rax" \
);
@bgaff
bgaff / userfaultfd_race.c
Created February 14, 2020 22:34
Example of SIGBUS caused by race handling userfaults
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@bgaff
bgaff / fizzbuzz.cpp
Created April 26, 2012 05:50
FizzBuzz C++: Template Recursion
/*
* fizzbuzz.cpp
*
* Created on: Apr 25, 2012
* Author: Brian Geffon
*
* fizzbuzz solved without looping or conditionals using only template recursion.
*/
#include <iostream>