stack

Why does the stack have to be page aligned?

巧了我就是萌 提交于 2019-12-07 07:30:50
问题 In Linux, I've tried (just for fun) to modify the kernel source in process.c create a stack address that has more entropy, i.e. in particular the line: sp -= get_random_int() % 8192; When I change this too much, the kernel halts or I get some seemingly undefined behavior. I'm guessing that this causes PAGE_ALIGN() to fail in some way? I'm not that interested in why PAGE_ALIGN() in particular fails, or exactly what piece of code in the kernel that fails (although that too would be nice to know

The stack is an implementation detail, or not?

淺唱寂寞╮ 提交于 2019-12-07 06:47:51
问题 According to http://msdn.microsoft.com/en-us/library/ms229017.aspx, value types "are allocated on the stack or inline with other structures*". Yet in the stack is an implementation detail, Eric Lippert states that that's an implementation detail. To my understanding, an implementation detail is "a behavior produced by code which may be relied on by consuming code, though that behavior is not specified by the spec the code is written to.". I understand that documentation is not a specification

ARM: Is “STMDB SP!, {R0-R8}” (aka PUSH {R0-R8}) an atomic operation?

人走茶凉 提交于 2019-12-07 06:13:28
问题 I wonder if STMDB SP!, {R0-R8} is an atomic operation in ARM(v7), because it looks quite complex to me. So is it for example possible, that the CPU is interrupted somewhere "in the middle" and has already stored R5-R8 on the stack and the SP is now SP_old - 16 and after handling the interrupt the processor continues with R0-R4? Thanks. 回答1: It is atomic, as far as interrupt handling is concerned. If I remember correctly, interrupting the instruction causes it to be aborted and re-executed

null character(s) ignored enabled by default

醉酒当歌 提交于 2019-12-07 06:02:55
问题 I am trying to implement stack with array! Every time i execute the program runs fine but i am getting warning as null character(s) ignored enabled by default What does this warning mean?.. what am i doing wrong? My code is: #include<stdio.h> #include<stdlib.h> # define MAX 10 int top=-1; int arr[MAX]; void push(int item) { if(top==MAX-1) { printf("OOps stack overflow:\n"); exit(1); } top=top+1; arr[top]=item; }//warning int popStack() { if(top==0) { printf("Stack already empty:\n"); exit(1);

Using a stack to traverse and solve a maze - Java

人盡茶涼 提交于 2019-12-07 04:35:49
问题 So I am trying to create a maze solver program that would solve a maze of X's and O's. What I would like to do is create a class of Points, so that I can create a 2-Dimensional array of Points which would allow printing to an output page as well as implementing the stack to be relatively simple. The simplest algorithm of the general idea I'd like to implement in the actual program itself I believe should be: 1) Move forward 2) Are you at a wall? 2a) If yes, turn left 3) Are you at the finish?

What is the “standard” size of the stack and the heap in a C program?

早过忘川 提交于 2019-12-07 03:54:18
问题 I have read that the "standard" and initial stack size on Linux is ~8MB and Windows is ~1MB. But how does the heap allocation work? Does the OS set a "virtual" size to the process heap like it does for the stack with committed and reserved memory? 回答1: Classically, the layout of a program has the 'text' (or 'code') segment at the low end of memory, followed by the fixed data ('data' and 'bss' segments), followed by a gap, with the stack growing downwards from high memory. The gap in the

Why Is GCC Using Mov Instead Of Push In Function Calls?

拈花ヽ惹草 提交于 2019-12-07 02:44:28
问题 So I've got this example C program. int worship(long john) { return 0 * john; } int main() { return worship(666); } The assembly looks (essentially) like this: worship(long): pushq %rbp movq %rsp, %rbp movq %rdi, -8(%rbp) movl $0, %eax popq %rbp ret main: pushq %rbp movq %rsp, %rbp movl $666, %edi call worship(long) popq %rbp ret I ran into this while reading about stack smashing. In the assembly worship(long): section where it says movq %rdi, -8(%rbp) I would expect it to be using pushq

How to increase scala stack size?

倖福魔咒の 提交于 2019-12-07 02:19:49
问题 I am getting a java.lang.StackOverflowError , when I execute a Scala program. I believe that the stack size can be set with -DXss=n , but it does not work on my system: Scala compiler version 2.7.7final and Linux 2.6.38-8-generic #42-Ubuntu The attached program witnesses the problem on my system. // scalac StackOverflow.scala // scala StackOverflow 6000 // scala -DXms=200M -DXmx=200M -DXss=200M StackOverflow 6000 object StackOverflow { def recur(k: Double): Double = { // check effects of

How to traverse stack in C++?

柔情痞子 提交于 2019-12-07 01:55:10
问题 Is it possible to traverse std::stack in C++? Traversing using following method is not applicable. Because std::stack has no member end . std::stack<int> foo; // .. for (__typeof(foo.begin()) it = foo.begin(); it != foo.end(); it++) { // ... } 回答1: Is it possible to traverse std::stack in C++? No. A stack is a data structure you should use when you are interested in placing elements on top and getting elements from the top. If you want an iterable stack, either use a different data structure

PHP Stack Implementation

天涯浪子 提交于 2019-12-07 01:50:55
问题 I want to construct a stack implemented in PHP. Initially I have this code: class Stack { protected $stack; protected $limit; public function __construct($limit = 10) { // initialize the stack $this->stack = array(); // stack can only contain this many items $this->limit = $limit; } public function push($item) { // trap for stack overflow if (count($this->stack) < $this->limit) { // prepend item to the start of the array array_unshift($this->stack, $item); } else { throw new RunTimeException(