From c20e93539e9fd55edc8a0b05e851e2f8c0408479 Mon Sep 17 00:00:00 2001 From: Ash Vardanian <1983160+ashvardanian@users.noreply.github.com> Date: Sat, 4 Jan 2025 17:08:35 +0000 Subject: [PATCH] Docs: Formatting --- .vscode/settings.json | 14 +++++++++++- README.md | 10 ++++----- libsee.c | 52 +++++++++++++++++++++++-------------------- 3 files changed, 46 insertions(+), 30 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index b167472..fbca6bd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,17 @@ "string.h": "c", "cstdio": "c", "wchar.h": "c" - } + }, + "cSpell.words": [ + "BLAS", + "dlsym", + "dlvsym", + "hsearch", + "LAPACK", + "libsee", + "memcpy", + "memset", + "PCRE", + "tsearch" + ] } \ No newline at end of file diff --git a/README.md b/README.md index e356afb..7b41e74 100644 --- a/README.md +++ b/README.md @@ -3,18 +3,18 @@ > _See where you use LibC the most._
> _Trace calls failing tests. Then - roast!_ -One-liner, to download and compile the script and run your vavorite query: +One-liner, to download and compile the script and run your favorite query: ```bash gcc -g -O2 -fno-builtin -fPIC -nostdlib -nostartfiles -shared -o libsee.so libsee.c ``` -LibSee overrides LibC symbols using `LD_PRELOAD`, profiling the most commonly used functions, and, optionally, fuzzing their behaviour for testing. +LibSee overrides LibC symbols using `LD_PRELOAD`, profiling the most commonly used functions, and, optionally, fuzzing their behavior for testing. The library yields a few binaries when compiled: ```bash libsee.so # Profiles LibC calls -libsee_and_knee.so # Correct LibC behaviour, but fuzzed! +libsee_and_knee.so # Correct LibC behavior, but fuzzed! ``` ## Tricks Used @@ -39,11 +39,11 @@ Feel free to suggest PRs covering the rest: - [x] [algorithms](https://en.cppreference.com/w/c/algorithm) - [x] [date and time](https://en.cppreference.com/w/c/chrono) - [x] [input/output](https://en.cppreference.com/w/c/io) +- [x] [wide-character strings](https://en.cppreference.com/w/c/string/wide) - [ ] [concurrency and atomics](https://en.cppreference.com/w/c/thread) - [ ] retrieving error numbers - [ ] [numerics](https://en.cppreference.com/w/c/numeric) -- [ ] [wide-character strings](https://en.cppreference.com/w/c/string/wide) -- [ ] [multibyte strings](https://en.cppreference.com/w/c/string/multibyte) +- [ ] [multi-byte strings](https://en.cppreference.com/w/c/string/multibyte) - [ ] [wide-character IO](https://en.cppreference.com/w/c/io) - [ ] [localization](https://en.cppreference.com/w/c/locale) - [ ] anything newer than C 11 diff --git a/libsee.c b/libsee.c index 2e0edb4..cae23b9 100644 --- a/libsee.c +++ b/libsee.c @@ -480,25 +480,27 @@ void syscall_print(char const *buf, size_t count) { // The system call number is passed in x8, and the arguments are in x0, x1, and x2. long syscall_write = (long)64; // System call number for write in AArch64 Linux long file_descriptor = (long)1; - asm volatile("mov x0, %1\n" // First argument: file descriptor - "mov x1, %2\n" // Second argument: buffer address - "mov x2, %3\n" // Third argument: buffer size - "mov x8, %4\n" // System call number: SYS_write (64) - "svc #0\n" // Make the system call - "mov %0, x0" // Store the return value - : "=r"(ret) - : "r"(file_descriptor), "r"(buf), "r"((long)count), "r"(syscall_write) - : "x0", "x1", "x2", "x8", "memory"); + asm volatile( // + "mov x0, %1\n" // First argument: file descriptor + "mov x1, %2\n" // Second argument: buffer address + "mov x2, %3\n" // Third argument: buffer size + "mov x8, %4\n" // System call number: SYS_write (64) + "svc #0\n" // Make the system call + "mov %0, x0" // Store the return value + : "=r"(ret) + : "r"(file_descriptor), "r"(buf), "r"((long)count), "r"(syscall_write) + : "x0", "x1", "x2", "x8", "memory"); #elif defined(__x86_64__) || defined(__i386__) // Inline assembly syntax for making a system call in x86-64 Linux. // Uses the syscall instruction, passing the system call number in rax, // and the call arguments in rdi, rsi, and rdx, respectively. long syscall_write = (long)1; // System call number for write in x86-64 Linux unsigned int file_descriptor = (unsigned int)1; - asm volatile("syscall" - : "=a"(ret) - : "a"(syscall_write), "D"(file_descriptor), "S"(buf), "d"(count) - : "rcx", "r11", "memory"); + asm volatile( // + "syscall" + : "=a"(ret) + : "a"(syscall_write), "D"(file_descriptor), "S"(buf), "d"(count) + : "rcx", "r11", "memory"); (void)ret; #endif (void)buf; @@ -539,18 +541,20 @@ void reopen_stdout(void) { void close_stdout(void) { long ret; #ifdef __aarch64__ - asm volatile("mov x0, 1\n" // File descriptor for stdout - "mov x8, 57\n" // Syscall number for 'close' in AArch64 - "svc #0\n" - "mov %0, x0" - : "=r"(ret) - : // No inputs besides the syscall number and FD - : "x0", "x8", "memory"); + asm volatile( // + "mov x0, 1\n" // File descriptor for stdout + "mov x8, 57\n" // Syscall number for 'close' in AArch64 + "svc #0\n" + "mov %0, x0" + : "=r"(ret) + : // No inputs besides the syscall number and FD + : "x0", "x8", "memory"); #elif defined(__x86_64__) - asm volatile("syscall" - : "=a"(ret) - : "a"(3), "D"(1) // Inputs: syscall number for 'close', FD for stdout - : "rcx", "r11", "memory"); + asm volatile( // + "syscall" + : "=a"(ret) + : "a"(3), "D"(1) // Inputs: syscall number for 'close', FD for stdout + : "rcx", "r11", "memory"); #endif (void)ret; }