callstack

save_stack_trace_tsk and struct stack_trace is no longer available in Linux 5.2+

▼魔方 西西 提交于 2021-01-27 05:42:18
问题 In kernel version before 5.2, I use save_stack_trace_tsk to retrieve call stack. But this method is no longer available in Linux kernel 5.2+, what should I use? 回答1: This question seemed so tempting so I did some digging here is my findings. TLDR; stack_trace_save () functions replaced by arch_stack_walk() interfaces * this is part of consolidation plan and remove duplicate code. linux commit 214d8ca6ee854 provide common architecture to walking stack trace. the new interface called arch_stack

The x86 disassembly for C code generates: orq $0x0, %(rsp)

我们两清 提交于 2021-01-24 13:30:49
问题 I have written the following C code: It simply allocates an array of 1000000 integers and another integer, and sets the first integer of the array to 0 I compiled this using gcc -g test.c -o test -fno-stack-protector It gives a very weird disassembly: Apparently it keeps allocating 4096 bytes on the stack in a loop, and "or"s every 4096th byte with 0 and then once it reaches 3997696 bytes, it then further allocates 2184 bytes. It then proceeds to set the 4000000th byte (which was never

What are the x86 instructions that affect ESP as a side effect?

懵懂的女人 提交于 2020-08-20 02:01:50
问题 I know that call and ret will modify the value of esp and that push and pop have a number of variants, but are there other instructions that will affect the stack pointer ? 回答1: The following instructions modify the stack pointer 1 : call enter int n/into/int 3 iret/iretd leave pop push ret sysenter sysexit pusha/pushad popa/popad pushf/pushfd/pushfq popf/popfd/popfq vmlaunch/vmresume eexit I leave to you the burden of telling primary and side effects apart. Keep in mind that any instruction

Why does GCC allocate more space than necessary on the stack, beyond what's needed for alignment?

浪尽此生 提交于 2020-07-25 06:16:08
问题 I'm reading a textbook which shows assembly code based on C code: C code: void echo() { char buf[8]; otherFunction(buf); } assembly code: echo: subq $24, %rsp //Allocate 24 bytes on stack, but why allocate 24 instead of 8 bytes? movq %rsp, %rdi //Compute buf as %rsp call otherFunction I don't understand why stack pointer %rsp is decremented by 24 bytes. I only assign 8 bytes' buffer as char buf[8]; , and there no callee saved registers to push on stack, shouldn't the instruction be subq $8,

Why does GCC allocate more space than necessary on the stack, beyond what's needed for alignment?

我们两清 提交于 2020-07-25 06:15:39
问题 I'm reading a textbook which shows assembly code based on C code: C code: void echo() { char buf[8]; otherFunction(buf); } assembly code: echo: subq $24, %rsp //Allocate 24 bytes on stack, but why allocate 24 instead of 8 bytes? movq %rsp, %rdi //Compute buf as %rsp call otherFunction I don't understand why stack pointer %rsp is decremented by 24 bytes. I only assign 8 bytes' buffer as char buf[8]; , and there no callee saved registers to push on stack, shouldn't the instruction be subq $8,

C++ Visual Studio debugging with call stack

北战南征 提交于 2020-07-10 06:38:04
问题 I have recently began learning C++ coming from a C# background. My problem is with the way exceptions get handled. If I have a nullptr somewhere, resulting in reading from a forbidden location, then I get a nice looking callstack in VS like this: However if I throw my own exception, or an assertion fails, then I do not get any clue as of what went wrong. VS just shows an error window: A: This is kind of uncomfortable for me as in C# I would get a stacktrace in both case. Is there a way to

C++ Visual Studio debugging with call stack

大兔子大兔子 提交于 2020-07-10 06:37:05
问题 I have recently began learning C++ coming from a C# background. My problem is with the way exceptions get handled. If I have a nullptr somewhere, resulting in reading from a forbidden location, then I get a nice looking callstack in VS like this: However if I throw my own exception, or an assertion fails, then I do not get any clue as of what went wrong. VS just shows an error window: A: This is kind of uncomfortable for me as in C# I would get a stacktrace in both case. Is there a way to

How do canary words allow gcc to detect buffer overflows?

那年仲夏 提交于 2020-07-03 09:45:52
问题 I could test using strncpy() with larger source string then the destination: int main() { char *ptr = malloc(12); strcpy(ptr,"hello world!"); return 0; } Compiling with the flag -fstack-protector and using the -S option I got: .file "malloc.c" .text .globl main .type main, @function main: .LFB2: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $32, %rsp movl %edi, -20(%rbp) movq %rsi, -32(%rbp) movq %fs:40, %rax movq %rax, -8(