Skip to content

Instantly share code, notes, and snippets.

0000000000007120 <_ZN3aaa10build_user17h6ef656f427941943E>:
7120: 55 push rbp
7121: 48 89 e5 mov rbp,rsp
7124: 48 89 f8 mov rax,rdi
7127: c7 47 10 64 00 00 00 mov DWORD PTR [rdi+0x10],0x64
712e: 48 c7 07 65 00 00 00 mov QWORD PTR [rdi],0x65
7135: 48 c7 47 08 66 00 00 mov QWORD PTR [rdi+0x8],0x66
713c: 00
713d: 5d pop rbp
713e: c3 ret
@wayling
wayling / fork
Last active March 21, 2018 15:00
vfork_fork
#include <stdio.h>
#include <sched.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#define DATA_SIZE 0x80000000
qemu-system-aarch64 -M virt -cpu cortex-a57 -nographic -smp 1 -kernel output/images/Image -append "console=ttyAMA0 memblock=debug" -netdev user,id=eth0 -device virtio-net-device,netdev=eth0
Booting Linux on physical CPU 0x0
Linux version 4.11.3 (wayling@wayling-MacBookPro) (gcc version 6.3.0 (Buildroot 2017.08-git-00449-g773e8b5) ) #2 SMP Wed Jun 14 23:11:40 CST 2017
Boot CPU: AArch64 Processor [411fd070]
efi: Getting EFI parameters from FDT:
efi: UEFI not found.
memblock_reserve: [0x0000000040080000-0x0000000040744fff] arm64_memblock_init+0x158/0x1e0
memblock_reserve: [0x0000000047fff000-0x0000000047ffffff] memblock_alloc_range_nid+0x5c/0x74
memblock_reserve: [0x0000000047ffe000-0x0000000047ffefff] memblock_alloc_range_nid+0x5c/0x74
memblock_reserve: [0x0000000047ffd000-0x0000000047ffdfff] memblock_alloc_range_nid+0x5c/0x74
//g++-7 -std=c++1z -o test 1.cpp -latomic
#include <iostream>
#include <utility>
#include <atomic>
struct A { int a[100]; };
struct B { int x, y; };
struct C { int b[2]; };
struct D { char c,d; };
gcc -g -O0 -o thread-ex ex1.c -Wall -Werror -lpthread
0x000000000040071a <+84>: mov 0x200934(%rip),%eax # 0x601054 <global_val>
0x0000000000400720 <+90>: cmp $0x1,%eax
0x0000000000400723 <+93>: jne 0x40071a <main+84>
gcc -g -O1 -o thread-ex ex1.c -Wall -Werror -lpthread
0x000000000040075c <+76>: mov 0x2008f2(%rip),%eax # 0x601054 <global_val>
0x0000000000400762 <+82>: cmp $0x1,%eax
0x0000000000400765 <+85>: jne 0x400762 <main+82>
@wayling
wayling / pte.c
Last active April 21, 2017 16:08
/*
* This is useful to dump out the page tables associated with
* 'addr' in mm 'mm'.
*/
void show_pte(struct mm_struct *mm, unsigned long addr)
{
pgd_t *pgd;
if (!mm)
mm = &init_mm;
@wayling
wayling / mmu.c
Last active April 21, 2017 16:14
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <asm/uaccess.h>
static int pid_mem = 1;
static int mm_exp_load(void){
struct task_struct *task;
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
/* longjmp for i386.
Copyright (C) 1995-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
@wayling
wayling / gist:b786c9b19f8cabe67962e75b85c1c1b6
Last active October 22, 2016 07:50
ch3.1-start/before.c
#include <stdio.h>
#include <stdlib.h>
static void __attribute__((constructor)) before_main1(void)
{
printf("Before main1\n");
}
static void __attribute__((constructor)) before_main2(void)
{