stack

x86 calling convention: should arguments passed by stack be read-only?

五迷三道 提交于 2019-12-03 11:36:10
问题 It seems state-of-art compilers treat arguments passed by stack as read-only. Note that in the x86 calling convention, the caller pushes arguments onto the stack and the callee uses the arguments in the stack. For example, the following C code: extern int goo(int *x); int foo(int x, int y) { goo(&x); return x; } is compiled by clang -O3 -c g.c -S -m32 in OS X 10.10 into: .section __TEXT,__text,regular,pure_instructions .macosx_version_min 10, 10 .globl _foo .align 4, 0x90 _foo: ## @foo ## BB

C++/C/Java: Anagrams - from original string to target;

只愿长相守 提交于 2019-12-03 11:21:12
问题 I'm trying to solve this problem : http://uva.onlinejudge.org/external/7/732.html. For the given example, they give us the original word, for example TRIT and the target "anagramed" string, TIRT . Objective: We have to output all the valid sequences of 'i' and 'o' (push and pop's, respectively) which produce the target string from the source string. So, I was thinking of calculate all permutations of "i" and "o" , but cutting this cases: 1) if current permutation begins with an 'o', stop

How to get source code line from stack trace in obj-c / ios

情到浓时终转凉″ 提交于 2019-12-03 10:58:22
问题 I use NSSetUncaughtExceptionHandler to print the stack trace to local file in iPhone, which will be sent to our server next time the app launches. Then I can examine the exception data and fix the bug. In some crashes I have the module name and the function that threw the exception, these are easy. But mostly I have something like this: "4 libc++abi.dylib 0x35bba3c5 _ZL19safe_handler_callerPFvvE + 76", "5 libc++abi.dylib 0x35bba451 _ZdlPv + 0", "6 libc++abi.dylib 0x35bbb825 __cxa_current

How can I write an exception stack trace in erlang after catching it?

久未见 提交于 2019-12-03 10:27:05
Suppose I have something like this : try code_that_fails() catch _:_ -> ..... How do I print the stacktrace in the catch block? That block catches all exceptions, but I don't know how to print the stack... Can you help me? Christian From Erlang 21.0 onwards, there's a new official way to get the stack trace. An optional pattern match in the try expression on the third parameter in the exception, which will contain the stack trace: try code_that_fails() catch _:_:Stacktrace -> erlang:display(Stacktrace) end Older versions (OTP 20 and below) For versions of Erlang/OTP 20 and below, you need to

Bug : Theme.Translucent & FLAG_ACTIVITY_REORDER_TO_FRONT

蹲街弑〆低调 提交于 2019-12-03 10:13:02
I have an activity with the translucent Theme : android:theme="@android:style/Theme.Translucent.NoTitleBar" Also the problem is reproduceable with just this Theme: <style name="MyTheme" parent="@android:style/Theme"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:colorBackground">@null</item> </style> This activity is loaded at startup and kept in memory (when I start this activity, I ad the FLAG_ACTIVITY_REORDER_TO_FRONT flag as extra). Problem : when I start this activity (from the menu), the

Are the elements of an array guaranteed to be stored from lower to higher addresses?

六眼飞鱼酱① 提交于 2019-12-03 09:49:48
Suppose I have the following array: int list[3]={2,8,9}; printf("%p,%p,%p",(void*)&list[0],(void*)&list[1],(void*)&list[2]); Is it always guaranteed that &list[0]<&list[1]<&list[2] ? I had assumed it to be a hard and fast rule while using C, but now have to very sure about it as an OP just asked me about it when I answered his question about endianness Little endian or Big endian What gave me second thoughts is the stacks can grow up or down issue.I am not very sure about that so your rigorous answers are appreciated.Thanks. Yes, it's guaranteed that &list[0]<&list[1] and &list[1]<&list[2] .

How do garbage collectors know about references on the stack frame?

岁酱吖の 提交于 2019-12-03 09:33:01
问题 What techniques do modern garbage collectors (as in CLR, JVM) use to tell which heap objects are referenced from the stack? Specifically how can a VM work back from knowing where the stack starts to interpreting all local references to heap objects? 回答1: In Java (and likely in the CLR although I know its internals less well), the bytecode is typed with object vs primitive information. As a result, there are data structures in the bytecode that describe which variables in each stack frame are

x86_64 align stack and recover without saving registers

大憨熊 提交于 2019-12-03 08:21:37
I'm writing interrupt handling routines for x86_64. The ABI specifies that before calling a C function I must align the stack to 16 bytes. The x86_64 ISA specifies that on entry to an ISR, my stack is 8 byte aligned. I need to align my stack pointer to 16 bytes therefore. The issue is that on return from my C function, I must recover the (potentially) unaligned stack pointer so that I can return from my interrupt correctly. I wonder if there is a way to do this without using a general purpose register? Here's my solution to the question as put: pushq %rsp pushq (%rsp) andq $-0x10, %rsp call

GCC - How to realign stack?

无人久伴 提交于 2019-12-03 08:15:49
I try to build an application which uses pthreads and __m128 SSE type. According to GCC manual, default stack alignment is 16 bytes. In order to use __m128, the requirement is the 16-byte alignment. My target CPU supports SSE. I use a GCC compiler which doesn't support runtime stack realignment (e.g. -mstackrealign). I cannot use any other GCC compiler version. My test application looks like: #include <xmmintrin.h> #include <pthread.h> void *f(void *x){ __m128 y; ... } int main(void){ pthread_t p; pthread_create(&p, NULL, f, NULL); } The application generates an exception and exits. After a

Finishing all activities started before the activity

女生的网名这么多〃 提交于 2019-12-03 07:48:22
I want to finish all the activities which are running in the application means want to remove all the parent activities from stack. I want to implement logout functionality locally in my application so what I was thinking, I will finish all the activities started before and will start login activity again.. I should let you know this is not a recommended behavior in android since you should let itself to manage life circles of activities. However if you really need to do this, you can use FLAG_ACTIVITY_CLEAR_TOP I give you some sample code here, where MainActivity is the first activity in the