Desire Stack State:
Stack[8,5,3,6,5]
Write the step of stack data structure operations(push and pop) to achieve the above desire state of stack data structure if you have to insert following numbers in stack?
require sequence of numbers that must push in stack:
Stack[0,1,9,8,8,0,1,5,3,6,5]
This seems to be a student home assignments. You should try it you self.
If you have the following sequence of numbers that must push in stack data structure, i.e,
require sequence of numbers that must push in stack: Stack[0,1,9,8,8,0,1,5,3,6,5]
The Following steps will lead us to achieve the desire state of stack.
Push(0)
Push(1)
Push(9)
Push(8)
Pop()
Pop()
Pop()
Pop()
Push(8)
Push(0)
Push(1)
Pop()
Pop()
Push(5)
Push(3)
Push(6)
Push(5)
Desire Stack State: Stack[8,5,3,6,5]
Related
So I created a stack using a linked list, the tutorial says that to check whether the heap is full we will check if we can create a node or not . If we can create one then the stack is not full and otherwise, it is full, now how does the computer know what's the actual size we want to create .
std::bad_alloc is thrown if your attempt to allocate memory fails.
Catch that exception, and you've determined that the heap is unable to fulfill your request.
I am a bit confused on this homework and the data structure of a stack. Essentially the question is:
"Give the output printed by java Stack for the input"
Below is the input
it was - the best - of times - - - it was - the - -
the output would be in the answer key
was best times of the was the it (1 left on stack)
I don't understand how you would receive this output I attempted writing my own stack structure but if I iterate through it I just get first in, first out.
Any help will do I would greatly appreciate it.
It isn't stated explicitly, but looking at the input I assume words are pushed onto the stack, while - signs are pop operations. If that is the case then the operations are
push it, stack contains it;
push was, stack contains it was;
pop prints was, stack contains it;
push the, stack contains it the;
push best, stack contains it the best;
pop prints best, stack contains it the;
push of, stack contains it the of;
push times, stack contains it the of times;
pop prints times, stack contains it the of;
pop prints of, stack contains it the;
pop prints the, stack contains it;
push it, stack contains it it;
push was, stack contains it it was;
pop prints was, stack contains it it;
push the, stack contains it it the;
pop prints the, stack contains it it;
pop prints it, stack contains it.
The words in bold are the output of the pop operations.
I want to obtain the return address of the current user stack frame
from some Linux kernel structure on a Linux x86_64 VM using a VMI-based approach.
I can access the content of more or less all registers, but solely at the moment
of a context switch (CR3 event), so registers like RBP or RSP are
pointing to the kernel stack and not user stack.
My first approach was to obtain the stack/base pointer and derive
from it the offset to the return address. However, accessing the
task_struct member thread (type thread_struct) and inside of it the
members sp or usersp doesn't yield the desired result. The member
usersp does point to some area in the user stack, but it definitively does not
hold the current position of the user stack pointer. I used some simple
C program, which prints out the stack pointer within each function, to verify
the validity of the usersp member.
Another approach was to follow the ret_stack pointer (type ftrace_ret_stack) of task_struct that contains the member ret. This member refers to the same value
as the usersp member from above.
I could however derive the top of stack by accessing the field start_stack
from the structure mm_struct that is nested in the task_struct (a pointer to it). This information seems to come most closely to the actual stack pointer. But, I have no idea how to derive from it the desired return address.
I have noticed there is some raw pointer called stack within the task_struct,
but couldn't figure out any detailed information about it.
I'm aware of the 'trapframe' structure on Windows systems, but couldn't find
the equivalent on Linux.
Thanks in advance.
I have written a function in C, which, when called, immediately results in a stack overflow.
Prototype:
void dumpOutput( Settings *, char **, FILE * );
Calling line:
dumpOutput( stSettings, sInput, fpOut );
At the time of calling it, stSettings is already a pointer to Settings structure, sInput is a dynamically allocated 2D array and fpOut is a FILE *. It reaches all the way to the calling line without any errors, no memory leaks etc.
The actual function is rather lengthy and i think its not worth sharing it here as the overflow occurs just as the code enters the function (called the prologue part, i think)
I have tried calling the same function directly from main() with dummy variables for checking if there are any problems with passed arguments but it still throws the stack overflow condition.
The error arises from the chkstk.asm when the function is called. This asm file (according to the comments present in it) tries to probe the stack to check / allocate the memory for the called function. It just keeps jumping to Find next lower page and probe part till the stack overflow occurs.
The local variables in dumpOutput are not memory beasts either, just 6 integers and 2 pointers.
The memory used by code at the point of entering this function is 60,936K, which increases to 61,940K at the point when the stack overflow occurs. Most of this memory goes into the sInput. Is this the cause of error? I don't think so, because only its pointer is being passed. Secondly, i fail to understand why dumpOutput is trying to allocate 1004K of memory on stack?
I am totally at a loss here. Any help will be highly appreciated.
Thanks in advance.
By design, it is _chkstk()'s job to generate a stack overflow exception. You can diagnose it by looking at the generated machine code. After you step into the function, right-click the edit window and click Go To Disassembly. You ought to see something similar to this:
003013B0 push ebp
003013B1 mov ebp,esp
003013B3 mov eax,1000D4h ; <== here
003013B8 call #ILT+70(__chkstk) (30104Bh)
The value passed through the EAX register is the important one, that's the amount of stack space your function needs. Chkstk then verifies it is actually available by probing the pages of stack. If you see it repeatedly looping then the value for EAX in your code is high. Like mine, it is guaranteed to consume all bytes of the stack. And more. Which is what it protects against, you normally get an access violation exception. But there's no guarantee, your code may accidentally write to a mapped page that belongs to, say, the heap. Which would produce an incredibly difficult to diagnose bug. Chkstk() helps you find these bugs before you blow your brains out in frustration.
I simply did it with this little test function:
void test()
{
char kaboom[1024*1024];
}
We can't see yours, but the exception says that you either have a large array as a local variable or you are passing a large value to _alloca(). Fix by allocating that array from the heap instead.
Most likely a stack corruption or recursion error but it's hard to answer without seeing any code
Here is the project page
http://www.codeproject.com/KB/threads/StackWalker.aspx
[STACKFRAME64][1] s;
//s contains the current stack frame filled by calling [StackWalk64][2] WinAPI
if (s.AddrPC.Offset == s.AddrReturn.Offset)
{
printf("StackWalk64-Endless-Callstack!");
}
My question is when will this condition be satisfied? What addresses do s.AddrPC.Offset, s.AddrReturn.Offset contain?
Is the return address in the last frame on stack = 0?
Hopefully never, but it is a basic sanity check in case the stack frame got stomped. Which isn't unlikely when you try to walk the stack in an exception handler triggered by a nasty hardware exception like AccessViolation. Without that check the code would enter an endless loop, constantly finding the same stack frame back.
AddrPC is the address of the call instruction, AddrReturn is the return address, the address of the previous call instruction (+5). Not sure what "stack 0" might mean.