callstack

Intel 64 bits, strange RSP behavior

半世苍凉 提交于 2019-12-02 23:39:42
问题 I came accross a problem with debugging a 64 bit binary in Windows using IDA. Normally, after a push RSP value should be deducted by 8. But occasionally, from IDA I saw that RSP was only deducted by 2, and then 8 for the next Push. The codes involved are push rax push rbx push rsi push rdi I'm quite new to x64 environment, thus could anyone explain this behavior ? 回答1: You're probably getting mixed up by hexadecimal. Counting by 8 goes 0 8 10 18 20 28 30 Are you looking at that and thinking

how does push and pop work in assembly

僤鯓⒐⒋嵵緔 提交于 2019-12-02 19:46:49
I'm getting confused on what does pop actually do in assembly. Does pop move the value PUSH ed onto the stack last (meaning it doesn't apply if we MOV a value after the the last element PUSH ed) or does it just pop whatever value that's last on the stack (thus, applying to both MOV and PUSH ), or does it pop what ever value pointed to by the stack pointer? Consider the following code: push $4 mov $5, -4(%esp) add $4, %esp (esp pointing to an unknown value) pop %ebp So in this code will the value poped into ebp be 4, 5, or the unknown value pointed to by esp ? 500 - Internal Server Error The

Why are function parameters pushed earlier on call stack than the return address?

时光总嘲笑我的痴心妄想 提交于 2019-12-02 19:41:50
From http://en.wikipedia.org/wiki/Stack_pointer#Structure I am wondering why the return address for a function is placed above the parameters for that function? It makes more sense to have Return Address pushed onto the stack before the Parameters for Drawline because the parameters are not required any more when the Return Address is popped for returning back to the calling function. What are the reasons for preferring the implementation shown in diagram above? The return address is usually pushed via the call machine command, [which in the native language's instruction set ] while the

How can I rethrow an exception in Javascript, but preserve the stack?

 ̄綄美尐妖づ 提交于 2019-12-02 18:17:44
In Javascript, suppose I want to perform some cleanup when an exception happens, but let the exception continue to propagate up the stack, eg: try { enterAwesomeMode(); doRiskyStuff(); // might throw an exception } catch (e) { leaveAwesomeMode(); throw e; } doMoreStuff(); leaveAwesomeMode(); The problem with this code is that catching and rethrowing the exception causes the stack trace information up to that point to be lost, so that if the exception is subsequently caught again, higher up on the stack, the stack trace only goes down to the re-throw. This sucks because it means it doesn't

Intel 64 bits, strange RSP behavior

北城余情 提交于 2019-12-02 13:35:38
I came accross a problem with debugging a 64 bit binary in Windows using IDA. Normally, after a push RSP value should be deducted by 8. But occasionally, from IDA I saw that RSP was only deducted by 2, and then 8 for the next Push. The codes involved are push rax push rbx push rsi push rdi I'm quite new to x64 environment, thus could anyone explain this behavior ? You're probably getting mixed up by hexadecimal. Counting by 8 goes 0 8 10 18 20 28 30 Are you looking at that and thinking 10 - 8 == 2 ? Because it's 0x10 - 0x8 == 0x8 . 来源: https://stackoverflow.com/questions/35958737/intel-64-bits

Can you set the size of the call stack in c++? (vs2008)

蹲街弑〆低调 提交于 2019-12-02 09:03:00
问题 I'm working from an example piece of code that allocates a relatively large local array. (32768 to be precise) When I try the same I'm getting behaviour that appears to be a stack overflow. Now I was wondering if my example has maybe set the stack to be larger then my application. Is this possible? if so how? 回答1: With the Microsoft compiler you can use /F to set the stack size, however it seems like you should just allocate the object on the heap. You should have a reason you're allocating

Can you set the size of the call stack in c++? (vs2008)

隐身守侯 提交于 2019-12-02 04:34:30
I'm working from an example piece of code that allocates a relatively large local array. (32768 to be precise) When I try the same I'm getting behaviour that appears to be a stack overflow. Now I was wondering if my example has maybe set the stack to be larger then my application. Is this possible? if so how? With the Microsoft compiler you can use /F to set the stack size, however it seems like you should just allocate the object on the heap. You should have a reason you're allocating this on the stack rather than the heap. Edit: This page gives a good cross-platform breakdown, though it may

Why is it better to use the ebp than the esp register to locate parameters on the stack?

我只是一个虾纸丫 提交于 2019-12-02 04:22:38
I am new to MASM. I have confusion regarding these pointer registers. I would really appreciate if you guys help me. Thanks Encoding an addressing mode using [ebp + disp8] is one byte shorter than [esp+disp8] , because using ESP as a base register requires a SIB byte. See rbp not allowed as SIB base? for details. (That question title is asking about the fact that [ebp] has to be encoded as [ebp+0] .) The first time [esp + disp8] is used after a push or pop, or after a call , will require a stack-sync uop on Intel CPUs. ( What is the stack engine in the Sandybridge microarchitecture? ). Of

Implement recursion in ASM without procedures

给你一囗甜甜゛ 提交于 2019-12-01 23:12:00
问题 I'm trying to implement functions and recursion in an ASM-like simplified language that has no procedures. Only simple jumpz, jump, push, pop, add, mul type commands. Here are the commands: (all variables and literals are integers) set (sets the value of an already existing variable or declares and initializes a new variable) e.g. (set x 3) push (pushes a value onto the stack. can be a variable or an integer) e.g. (push 3) or (push x) pop (pops the stack into a variable) e.g. (pop x) add

Implement recursion in ASM without procedures

假如想象 提交于 2019-12-01 21:02:30
I'm trying to implement functions and recursion in an ASM-like simplified language that has no procedures. Only simple jumpz, jump, push, pop, add, mul type commands. Here are the commands: (all variables and literals are integers) set (sets the value of an already existing variable or declares and initializes a new variable) e.g. (set x 3) push (pushes a value onto the stack. can be a variable or an integer) e.g. (push 3) or (push x) pop (pops the stack into a variable) e.g. (pop x) add (adds the second argument to the first argument) e.g. (add x 1) or (add x y) mul (same as add but for