stack

Computing method call stack size for checking StackOverflowException

安稳与你 提交于 2019-12-04 02:24:08
Today morning I answered a question which is related to StackoverflowException . The person has asked when Stackoverflow exception occurs See this link Simplest ways to cause stack overflow in C#, C++ and Java So my question is that is there any method by which we can compute the method call stacks size dynamically in our program and then applying a check before calling a method which checks whether method call stack has space to accommodate it or not to prevent StackOverflowException. As I am a java person I am looking for java but also looking for explanation related to the concept without

How to access a process's kernel stack in linux kernel?

℡╲_俬逩灬. 提交于 2019-12-04 02:20:16
问题 I am trying to monitor which functions are being called up by a process during its course of execution. My aim is to know how much time a process spends in every function. The functions are pushed over a stack and popped when function call returns. I would like to know where in the kernel code this push and pop actually happens. I found a void *stack field in task_struct . I am not sure if this is the field I am looking for. If it is, then what is the way to know how it is updated? I have to

What's inside the stack?

守給你的承諾、 提交于 2019-12-04 01:48:21
If I run a program, just like #include <stdio.h> int main(int argc, char *argv[], char *env[]) { printf("My references are at %p, %p, %p\n", &argc, &argv, &env); } We can see that those regions are actually in the stack. But what else is there? If we ran a loop through all the values in Linux 3.5.3 (for example, until segfault) we can see some weird numbers, and kind of two regions, separated by a bunch of zeros, maybe to try to prevent overwriting the environment variables accidentally. Anyway, in the first region there must be a lot of numbers, such as all the frames for each function call.

C++ jump to other method execution

浪尽此生 提交于 2019-12-04 01:35:25
In my C++ JNI-Agent project i am implementing a function which would be given a variable number of parameters and would pass the execution to the other function: // address of theOriginalFunction public static void* originalfunc; void* interceptor(JNIEnv *env, jclass clazz, ...){ // add 4 to the function address to skip "push ebp / mov ebp esp" asm volatile("jmp *%0;"::"r" (originalfunc+4)); // will not get here anyway return NULL; } The function above needs to just jump to the: JNIEXPORT void JNICALL Java_main_Main_theOriginalFunction(JNIEnv *env, jclass clazz, jboolean p1, jbyte p2, jshort

gcc -mpreferred-stack-boundary option

瘦欲@ 提交于 2019-12-04 01:04:24
I want to know what's the use of -mpreferred-stack-boundary option during compilation in GNU compiler. I've checked the documentation but the explanation is lost on me. Could someone please explain it. I want to know what's the use of -mpreferred-stack-boundary option during compilation in GNU debugger. The option has absolutely nothing to do with the debugger. It affects generated code in your binary. By default, GCC will arrange things so that every function, immediately upon entry, has its stack pointer aligned on 16-byte boundary (this may be important if you have local variables, and

Why does GCC subtract the wrong value to the stack pointer when allocating a big array with no subsequent function calls?

故事扮演 提交于 2019-12-04 00:41:16
Really bizarre gcc quirk. Check this out: main() { int a[100]; a[0]=1; } produces this assembly: 0: 55 push %rbp 1: 48 89 e5 mov %rsp,%rbp 4: 48 81 ec 18 01 00 00 sub $0x118,%rsp b: c7 85 70 fe ff ff 01 movl $0x1,-0x190(%rbp) 12: 00 00 00 15: c9 leaveq 16: c3 retq The top of the stack is clearly 400, since its a 100 * 4 array. So when it writes to the first entry, it does rbp - 400 (line 'b'). Good. But why does it subtract 280 from the stack (line '4') pointer? Doesn't that point to the middle of the array? If we add a function call afterward, gcc does the right thing: b() {} main() { int a

Does a garbage collector collect stack memory, heap memory, or both?

大城市里の小女人 提交于 2019-12-04 00:04:27
I read lot of articles about garbage collection and almost all article tells about heap memory. so my question is "garbage collection collects stack memory or heap memory or both". It collects heap memory. Usually, stack memory is collected automatically when the execution path reaches the end of the scope. e.g.: void fun() { int n; // reservation on the stack as part of the activation record ... } // returning the stack pointer to where it was before entering the scope In fact, in a language like C++, stack allocated variables are called auto variables. Heap memory. Garbage collection is a

.NET - Function variables stored on heap or stack in address space?

允我心安 提交于 2019-12-03 23:07:15
问题 I encountered the following question in an exam: When a program calls a function, in which type of data structure is the memory allocated for the variable in that function? HEAP QUEUE LIFO STACK According to the test, HEAP is the correct answer, although I selected STACK. Can someone fantastic person out there please explain why? Thanks in advance. 回答1: Well, local variables and parameters are stored on the stack not on a heap. For local value-types, this means that the value itself is stored

Local variables on stack

ε祈祈猫儿з 提交于 2019-12-03 21:57:22
To understand the stack frame concept, I wrote a little program for my own. First I will show you the code, a little sketch about it and then I will present my question: So, the program: int check_pw(char *password){ int valid = 0; char buffer[10]; strcpy(buffer, password); if(strcmp(buffer, "a") == 0){ valid = 1; } return valid; } int main(int argc, char *argv[]){ if(check_pw(argv[1])){ printf("OK\n"); } else{ printf("Wrong password\n"); } } I give the password as a command-line argument. And if it is equal to 'a', then it is ok. So, I think it is clear. Now the sketch how the stack frame of

What is thread stack size option(-Xss) given to jvm? Why does it have a limit of atleast 68k in a windows pc?

我怕爱的太早我们不能终老 提交于 2019-12-03 20:53:18
I have seen JVM option -Xss - What does it do exactly? this link, but my question is how is this option useful. Because, if we set a very minimum limit to the -Xss value, maybe the threads are not going to work properly as it may throw stackOverflow error most of the times. Why is there a 64k limit at least for this value? How i got this 64k limit is when i was trying to configure the runtime vm options on the IntelliJ iDE, I tried to give some thing like 10k and it popped up this error stating it needs at least 64k for thread stack size. Another question is that, how to find the default