Skip to content

Instantly share code, notes, and snippets.

View singchia's full-sized avatar
🎯
Focusing

singchia

🎯
Focusing
View GitHub Profile
@extremecoders-re
extremecoders-re / qemu-networking.md
Last active May 4, 2024 05:55
Setting up Qemu with a tap interface

Setting up Qemu with a tap interface

There are two parts to networking within QEMU:

  • The virtual network device that is provided to the guest (e.g. a PCI network card).
  • The network backend that interacts with the emulated NIC (e.g. puts packets onto the host's network).

Example: User mode network

@laoar
laoar / mmap_zcopy
Last active February 10, 2024 00:08
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"
@turtlemonvh
turtlemonvh / Makefile
Last active January 23, 2024 03:33
Golang Project Makefile Template
# Borrowed from:
# https://github.com/silven/go-example/blob/master/Makefile
# https://vic.demuzere.be/articles/golang-makefile-crosscompile/
BINARY = superdo
VET_REPORT = vet.report
TEST_REPORT = tests.xml
GOARCH = amd64
VERSION?=?
@dtoma
dtoma / epoll.cpp
Last active March 9, 2023 16:58
C++ epoll
// https://banu.com/blog/2/how-to-use-epoll-a-complete-example-in-c/
// http://www.kegel.com/poller/
/** Todo
* - [ ] Split i/o and logic
* - [ ] Unit test logic
* - [ ] Logging
* - [ ] Continuous integration
* - [ ] Linux
* - [ ] Windows
@CMCDragonkai
CMCDragonkai / memory_layout.md
Last active April 28, 2024 18:50
Linux: Understanding the Memory Layout of Linux Executables

Understanding the Memory Layout of Linux Executables

Required tools for playing around with memory:

  • hexdump
  • objdump
  • readelf
  • xxd
  • gcore
// Package main demonstrates a problem with sockets.
// run it with:
//
// go build
// ./test 127.0.0.1:1234
//
// Nevermind, found the problem (using select wrong)
//
package main
@jboner
jboner / latency.txt
Last active May 5, 2024 03:12
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@tonyc
tonyc / gist:1384523
Last active February 6, 2023 04:05
Using strace and lsof

Using strace and lsof to debug blocked processes

You can use strace on a specific pid to figure out what a specific process is doing, e.g.:

strace -fp <pid>

You might see something like:

select(9, [3 5 8], [], [], {0, 999999}) = 0 (Timeout)

@glacjay
glacjay / tun-ping-linux.py
Created September 18, 2010 04:49
Reading/writing Linux's TUN/TAP device using Python.
import fcntl
import os
import struct
import subprocess
# Some constants used to ioctl the device file. I got them by a simple C
# program.
TUNSETIFF = 0x400454ca
TUNSETOWNER = TUNSETIFF + 2