stack

Implementing setjmp and longjmp in C without built in functions or assembly (getting incorrect return values)

泄露秘密 提交于 2019-12-22 06:58:04
问题 I'm trying to test 2 of my functions that sort of mimic setjmp and longjmp for a homework - which is pretty difficult since we're not allowed to use built in functions or assembly asm() to implement the longjmp and setjmp functions. (Yes, that's really the assignment.) Problem : I keep getting wrong return values. So, in short, when main() calls foo() and foo() calls bar(), and bar() calls longjump(), then bar() should not return to foo() but instead setjmp() should return to main with return

How to determine the maximum stack size limit?

穿精又带淫゛_ 提交于 2019-12-22 04:59:13
问题 I want to determine the maximum size of the stack programmatically from within Java (the size set by -Xss). How do I do this? Alternatively, as my Java module also uses a native code module, I would be able to do this via JNI; but how? 回答1: Use ManagementFactory.getRuntimeMXBean().getInputArguments() to access all arguments passed to VM. 回答2: Maybe not best practice but certainly straight-forward: I'd write a recursive method counting up a value, recurring until java.lang.StackOverflowError

Modify return address on stack

好久不见. 提交于 2019-12-22 04:48:20
问题 I looked at the basics of buffer overflow vulnerabilities and tried to understand how the stack is working. For that I wanted to write a simple program which changes the address of the return address to some value. Can anybody help me with figuring out the size of the base pointer to get the offset from the first argument? void foo(void) { char ret; char *ptr; ptr = &ret; //add some offset value here *ptr = 0x00; } int main(int argc, char **argv) { foo(); return 1; } The generated assembler

Java, Printing the stack values

落花浮王杯 提交于 2019-12-22 04:38:20
问题 In Java, I want to print the contents of a Stack. The toString() method prints them encased in square brackets delimited by commas: [foo, bar, baz] . The question is, how do I get rid of them and print the variables only? My code so far: Stack myStack = new Stack (); for(int j=0;j<arrayForVar.length;j++) { if(arrayForVar[j][1]!=null) { System.out.printf("%s \n",arrayForVar[j][1]+"\n"); myStack.push(arrayForVar[j][1]); } System.out.printf("%s \n",myStack.toString()); This answer worked for me:

Java, Printing the stack values

自作多情 提交于 2019-12-22 04:38:03
问题 In Java, I want to print the contents of a Stack. The toString() method prints them encased in square brackets delimited by commas: [foo, bar, baz] . The question is, how do I get rid of them and print the variables only? My code so far: Stack myStack = new Stack (); for(int j=0;j<arrayForVar.length;j++) { if(arrayForVar[j][1]!=null) { System.out.printf("%s \n",arrayForVar[j][1]+"\n"); myStack.push(arrayForVar[j][1]); } System.out.printf("%s \n",myStack.toString()); This answer worked for me:

Threading in C# , value types and reference types clarification?

六月ゝ 毕业季﹏ 提交于 2019-12-22 04:05:22
问题 After reading Jon Skeet article , and this article from msdn , I still have a question Let's say I have this code : MyPerson mp = new MyPerson(); //Field int g=0; //Field public void DoWork () { int i; MyPerson mp2 = new MyPerson(); ... } Now let's say I have 2 threads. which runs DoWork . ( let's ignore for now , race conditions) Will they both see the same g or each thread will have its own item ? ? ( value ) Will they both see the same mp or each thread will have its own item ?? ( instance

MySQL table as a FIFO/Queue

两盒软妹~` 提交于 2019-12-21 22:07:45
问题 How can we treat a Mysql table as a limited FIFO buffer (Queue). Objectives are : The table at a time can have only N number of rows. When a row is inserted, the oldest row shpuld be deleted to maintain the row count as N. Pls suggest approaches. UPDATE: Sorry guys, as many pointed I changed my question from STACK to FIFO queue 回答1: Past Mysql 5 you could use a trigger to achieve this. http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html then your triggered sql would be along the lines

Explanation of how stacks work in C

a 夏天 提交于 2019-12-21 20:37:11
问题 I am just wanting a simple explanation of the linking process when pushing data onto a stack. I know how to build on using the code from my book, but I am not really sure I understand how the process works when you move the stack head link from one to the next. For stacks like: typedef struct node { void dataptr; struct node* link; }STRUCT_NODE; typedef struct { int count; STACK_NODE* top; }STACK; How do you change the link to point to the new data pushed on the stack. Also I do not know 回答1:

Retrieving return address of an exception on ARM Cortex M0

老子叫甜甜 提交于 2019-12-21 18:58:34
问题 I am trying to retrieve the return address of an IRQ handler in my code. My aim is to save the value of the PC just before the watchdog timer expires and before the reset for debug purposes, using WDT_IRQHandler(). I am also testing this approach with other IRQs to check if I grasped the idea. But it seems I haven't. I have read the documentation available. I understood that when an exception happens, 8 registers are pushed to the stack: R0, R1, R2, R3, R12, LR, PC and XPSR. I have also read

For buffer overflows, what is the stack address when using pthreads?

断了今生、忘了曾经 提交于 2019-12-21 17:39:11
问题 I'm taking a class in computer security and there is an extra credit assignment to insert executable code into a buffer overflow. I have the c source code for the target program I'm trying to manipulate, and I've gotten to the point where I can successfully overwrite the eip for the current function stack frame. However, I always get a Segmentation fault, because the address I supply is always wrong. The problem is that the current function is inside a pthread, and therefore, the address of