性能分析备忘录
Perf Debian 安装 perf 1 sudo apt install linux-perf 收集分支预测事件 1 perf stat -e branch-instructions,branch-misses <your_program> branch-instructions:分支指令的总数 branch-misses:分支预测失败的次数 1 hit_rate = 1 - branch-misses / branch-instructions //命中率 以下是一个包含多个复杂分支跳转的 C 语言程序示例。这个程序包含了多层嵌套的条件判断、循环和函数调用,以演示复杂的分支逻辑 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 #include <stdio.h> #include <stdlib.h> #include <time.h> // 模拟复杂条件的函数 int complex_condition(int x) { if (x % 2 == 0) { if (x % 3 == 0) { return 1; // 可被2和3整除 } else { if (x % 5 == 0) { return 2; // 可被2和5整除 } else { return 3; // 可被2整除,但不能被3或5整除 } } } else { if (x % 7 == 0) { return 4; // 可被7整除 } else { return 5; // 不能被2或7整除 } } } // 递归函数,模拟复杂的分支跳转 int recursive_function(int depth) { if (depth <= 0) { return 0; } else { if (depth % 2 == 0) { return depth * recursive_function(depth - 1); } else { return depth + recursive_function(depth - 1); } } } // 主函数,包含多重循环和分支判断 int main() { srand(time(NULL)); // 用当前时间作为随机数种子 // 模拟分支跳转 for (int i = 0; i < 20; i++) { int rand_num = rand() % 100 + 1; // 生成1到100之间的随机数 int result = complex_condition(rand_num); switch (result) { case 1: printf("Number %d is divisible by 2 and 3.\n", rand_num); break; case 2: printf("Number %d is divisible by 2 and 5.\n", rand_num); break; case 3: printf("Number %d is divisible by 2, but not by 3 or 5.\n", rand_num); break; case 4: printf("Number %d is divisible by 7.\n", rand_num); break; case 5: printf("Number %d is not divisible by 2 or 7.\n", rand_num); break; default: printf("Unexpected result for number %d.\n", rand_num); break; } } // 递归调用,模拟更复杂的分支 int depth = rand() % 10 + 1; printf("\nRecursive function result for depth %d: %d\n", depth, recursive_function(depth)); return 0; } 编译之后,使用 perf 进行分支预测事件统计得到结果: ...
SoK: Sanitizing for Security 论文结构梳理
Abstract I. Inctrodcution II. Exploit Mitigations vs. Sanitizers III. Low-Level Vulnerabilities A. Memory Safety Violations (1) Spatial Safety Violatoins (2) Temporal Safety Violations B. Use of Uninitialized Variables C. Pointer Type Errors D. Variadic Function Misuse E. Other Vulnerabilities IV. Bug Finding Techiques A. Memory Safety Violations Location-based Access Checkers Identity-based Access Checkers (1) Spatial Memory Safety Violations Red-zone Insertion Guard Pages Per-pointer Bounds Tracking Per-object Bounds Tracking (2) Temporal Memory Safety Violations Reuse Delay Lock-and-key Dangling Pointer Tagging B. Use of Uninitailized Variables Uninitailized Memory Read Detection Uninitialized Value Use Dectection C. Pointer Type Errors Pointer Casting Monitor Pointer Use Monitor D. Variadic Function Misuse Dangerous Format String Detection Argument Mismatch Detection E. Other Vulnerabilities V. Program Instumentation A. Language-level Instrumentation B. IR-level Instrumentation C. Binary Instrumentation D. Library Interposition VI. Metadata Management A. Object Metadata Embedded Metadata Direct-mapped Shadow Multi-level Shadow Custom Data Structure B. Pointer Metadata Fat Pointers Tagged Pointers Disjoint Metadata C. Static Metadata VII. Driving A Sanitizer VIII. Analysis A. False Positives B. False Negatives C. Incomplete Instrumentation D. Tread Safety E. Performance Overhead F. Memory Overhead IX. Deployment A. Methodology Popular Github repositories Sanitizer web pages Search trends B. Findings AddressSanitizer is the most widely adopted sanitizer The adoption rate for other LLVM-based sanitizers is lower C. Deployment Directions X. Future Research And Development Directions A. Type Error Detection B. Improving Compatibility C. Composing Sanitizers D. Hardware Support E. Kernel and Bare-Metal Support XI. Conclusion
使用 C++ 理解 23 种设计模式
开一个坑,使用C++实现23种设计模式
Debian Gnome 修改默认目录
我在 askbuntu 里面找到了答案: Change default user folders path 具体做法: 1 vi ~/.config/user-dirs.dirs 以下是我的配置: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # This file is written by xdg-user-dirs-update # If you want to change or add directories, just edit the line you're # interested in. All local changes will be retained on the next run. # Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped # homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an # absolute path. No other format is supported. # XDG_DESKTOP_DIR="/home/hcy/Desktop/" XDG_DOWNLOAD_DIR="/home/hcy/Downloads/" XDG_TEMPLATES_DIR="/home/hcy/Templates/" XDG_PUBLICSHARE_DIR="/home/hcy/Public/" XDG_DOCUMENTS_DIR="/home/hcy/Documents/" XDG_MUSIC_DIR="/home/hcy/Music/" XDG_PICTURES_DIR="/home/hcy/Pictures/" XDG_VIDEOS_DIR="/home/hcy/Videos/"
Debian 安装 Flameshot 和迅雷以及 Neovim 剪切板
Flameshot 直接从仓库安装 flameshot 1 sudo apt install flameshot 要在 Wayland 下面可以复制粘贴图片还需安装: 1 sudo apt install xdg-desktop-portal xdg-desktop-portal-kde wl-clipboard 为了让 flameshot 在 wayland 和 x11 下都可以使用剪切板,可以编写一个小脚本: 1 2 3 4 5 if [[ $XDG_SESSION_TYPE == "wayland" ]] || [[ -n $WAYLAND_DISPLAY ]]; then flameshot gui -c --raw | wl-copy else flameshot gui -c fi 将这一个脚本压缩为一行: 1 [[ $XDG_SESSION_TYPE == "wayland" ]] || [[ -n $WAYLAND_DISPLAY ]] && flameshot gui -c --raw | wl-copy || flameshot gui -c Flameshot 的 GitHub 仓库 Issue 里面有讨论这个问题 1 https://github.com/flameshot-org/flameshot/issues/2848 Neovim 剪切板 和上面的 Flameshot 需要 wl-clipboard 一样,在 X11 环境里面也需要: ...