Skip to content

Instantly share code, notes, and snippets.

@x0nu11byt3
x0nu11byt3 / elf_format_cheatsheet.md
Created February 27, 2021 05:26
ELF Format Cheatsheet

ELF Format Cheatsheet

Introduction

Executable and Linkable Format (ELF), is the default binary format on Linux-based systems.

ELF

Compilation

@murphypei
murphypei / safe_queue.h
Last active August 16, 2023 17:28
C++ thread safe queue
#ifndef SAFE_QUEUE
#define SAFE_QUEUE
#include <condition_variable>
#include <mutex>
#include <queue>
// A threadsafe-queue.
template <class T>
class SafeQueue
@mcastelino
mcastelino / qemu_optionrom.md
Last active June 10, 2024 22:00
QEMU Option ROMS and booting from option rom

With seabios

  1. QEMU includes bundled option ROMs which are loaded by default unless a device is specifically setup with --romfile="".
  2. These options roms are bundled as binaries. The source code for the same can be found at http://ipxe.org/
  3. These options roms are useful for example when you want to PXE boot over a virtio-net device.

Here is an example of booting via Network PXE using the option ROM

qemu-system-x86_64 \
@wbenny
wbenny / vmcs_field_encoding.md
Last active December 11, 2020 10:04
VMCS field encoding

VMCS field encoding

Values of VMCS fields are encoded as per section VMREAD, VMWRITE, and Encodings of VMCS Field (24.11.2, Intel Manual Volume 3C - May 2018).

This encoding can be transcribed into C:

union vmcs_component_encoding
{
 struct

virtio is a kernel virtual bus. From drivers/virtio/virtio.c:

static struct bus_type virtio_bus = {
	.name  = "virtio",
	.match = virtio_dev_match,
	.dev_groups = virtio_dev_groups,
	.uevent = virtio_uevent,
	.probe = virtio_dev_probe,
	.remove = virtio_dev_remove,
@gustavorv86
gustavorv86 / c_priority_queue_threads.c
Last active September 8, 2023 04:42
POSIX message priority queue example written in C/C++
/**
* Compile:
* gcc -std=gnu11 -Wall -Wextra c_priority_queue_threads.c -o priority_queue_threads -lpthread -lrt
*/
#include <errno.h>
#include <mqueue.h>
#include <fcntl.h> /* For O_* constants. */
#include <sys/stat.h> /* For mode constants. */
@Pulimet
Pulimet / AdbCommands
Last active July 23, 2024 18:05
Adb useful commands list
adb help // List all comands
== Adb Server
adb kill-server
adb start-server
== Adb Reboot
adb reboot
adb reboot recovery
adb reboot-bootloader
@mcastelino
mcastelino / qemu-tracing.md
Last active May 30, 2024 20:06
Tracing QEMU-KVM Interactions

Tracing QEMU-KVM Interactions

But default in linux you can figure out how many times and for what reasons there is a VM Exit from a VM into the kvm kernel module. However given the ubiquity of vhost and the ability of kvm to emulate most device models directly in the kernel, most of those VM exits do not result in a transition from host kernel into the QEMU. The transitions from VM -> kvm -> QEMU are typically the most expensive.

Here we try to figure out how many of the VM Exits result in the invocation of QEMU.

Tracking VM-KVM Interactions

This can be done very simply with perf

@laoar
laoar / mmap_zcopy
Last active June 3, 2024 09:07
an example of kernel space to user space zero-copy via mmap, and also the comparing mmap with read/write
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <asm/uaccess.h>
#define MAX_SIZE (PAGE_SIZE * 2) /* max size mmaped to userspace */
#define DEVICE_NAME "mchar"
@BrotherJing
BrotherJing / mtest.c
Created June 1, 2016 14:22
a kernel module for process memory management
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/string.h>
#include<linux/vmalloc.h>
#include<linux/mm.h>
#include<linux/init.h>
#include<linux/proc_fs.h>
#include<linux/sched.h>
#include<linux/uaccess.h>
#include<linux/fs.h>