1,056 questions
3
votes
1
answer
179
views
Memory Layout of C Programs: How is size of stack-heap space determinded?
I was reading an article on the Memory Layout of C Programs; https://www.geeksforgeeks.org/c/memory-layout-of-c-program/.
It mentioned, under "4. Stack Segment":
When the stack and heap ...
17
votes
3
answers
1k
views
Stack memory in a freestanding environment
I'm reading a GNU as introductory book for programs running on top of an OS. I'm at the stack memory part and I was curious how the stack looks like in a freestanding environment.
I'm guessing that ...
1
vote
1
answer
222
views
What are the proper conventions for x64 assembly functions on Windows?
I've been messing around with assembly and compilers & have gotten a lot of conflicting information in how I should be using registers, the stack / spill over registers, and to what extent ...
0
votes
1
answer
86
views
Function parameter memory address assignment [closed]
I want to understand how memory is allocated to function params in c. I compiled the same program twice with gcc -g except I interchanged the first and second params of a function on_menu for the ...
1
vote
1
answer
88
views
Is it valid to initialize a struct with const members allocated on the stack with alloca?
Considering that the type A is defined like this:
typedef struct a { const int a; } A;
I know that this code is valid:
A * foo = malloc(sizeof *foo); // Allocates uninitialized memory with no ...
2
votes
0
answers
128
views
Why rsp is subracted with 4096 bytes (page size)? [duplicate]
I know each segment in the executable file need to be aligned, before loaded into ram there were aligned to minimum page size of 4096 bytes and if there not enough fit within 4096 bytes they span ...
0
votes
0
answers
66
views
Are local variables always volatile? [duplicate]
Are local variables always volatile in C#?
In other words, is the volatility of num the same in these two classes:
public sealed class ThreadSafeObjectA
{
private volatile int num;
public int ...
1
vote
4
answers
160
views
Why can the stack collide with the heap if they are located in a virtual space that is very large in size?
If each process has its own address space and it is much larger than the physical memory of the computer, why can’t we just place the stack at the end of this address space and the heap at the ...
1
vote
0
answers
101
views
Assembly x64: Issue with Function Calls and Stack Alignment in Assembler-Disassembler Tool on Windows
I'm working on an assembler-disassembler tool in x64 assembly on Windows, and I'm encountering a strange issue related to function calls and stack alignment. The program is supposed to support basic ...
1
vote
1
answer
75
views
How can I store a value on the stack at a constant address in the memory in Webassembly?
I have a value on the stack, and I want to store it at a constant address in memory. Would the operation take the address from the stack first, I could put the address on the stack and store the value ...
-3
votes
1
answer
154
views
How is Numpy able to get an array size at run-time?
In C++ the size of an array must be determined at the compile-time.
I want to write a simple code in C++, say, to do a naive matrix multiplication with itself (for a matrix that is square in size) and ...
0
votes
1
answer
256
views
Stack size in relation to virtual memory
In our Operating Systems class we mentioned virtual memory as a mechanism that abstracts physical memory to a process, and that it looks something like this (per process):
The stack grows down the ...
0
votes
2
answers
134
views
Does Stack being limited in size mean i can only get limited pointers to objects in heap?
if stack size is 1MB, does that mean i can only get less than 1000000/8 pointers to allocate ints in heap? (considering 1MB free stack) yeah i know you might not want to make that many individual ints ...
0
votes
0
answers
44
views
With what part of the program are the stack and heap associated?
I understanding the stack, the LIFO working principle, memory allocation on the heap and stuff. My question is, where does this exists ?
Is there a dedicated region on the ram for the stack ? Or is it ...
0
votes
0
answers
93
views
"Symbol not defined : @STACK " error in ASM code for 8086. Compiled using DOSBOX ,MASM
This is a code to add all numbers between 50 and 150 and display the result in decimal form.I have created the stack segment .STACK 32 to store the remainders to convert the hex result to decimal ...
0
votes
0
answers
49
views
Why doesn't pushing a character to the stack without an explicit nul-char look like an underfined behaviour? [duplicate]
The following snippet comes from the lesson 7 on asmtutor.com :
;------------------------------------------
; void sprintLF(String message)
; String printing with line feed function
sprintLF:
call ...
1
vote
1
answer
504
views
Aarch64 is there a Red Zone on Linux, If so 16 or 128 bytes?
There doesn't seem to be any mention of a "Red Zone" for Aarch64 in the ABI, but Microsoft makes reference to a 16-byte red zone for Aarch64, Apple claims a 128-byte red zone in Writing ...
-3
votes
1
answer
113
views
Placing value on stack using alloca function or static keyword
I have an abstract "x vs y" question. In C programming language if I have some small amount of data which I want to store somewhere in RAM, I suppose typical options are the next ones:
to ...
0
votes
0
answers
47
views
Use of Stack/Heap outside of programming
If I understand correctly, the RAM is virtually divided into stack and heap. Stack takes primitive types/functions etc and Heap deals with the reference types and objects. Stack follows the LIFO ...
0
votes
0
answers
171
views
How to allocate a separate stack for a function manually in C++?
I am trying to allocate a new stack on the heap in C++ for a function using VirtualAlloc. While debugging, I noticed that the rsp value for my function can either increase or decrease relative to the ...
1
vote
0
answers
496
views
Uncaught RangeError: Maximum call stack size exceeded (functionjs.js)
I'm trying to build a recruitment management website (nodejs), but when I'm almost done I get this error:
Uncaught RangeError: Maximum call stack size exceeded. functionjs.js
Here is my functionjs.js ...
1
vote
0
answers
39
views
How to get address range of a process stack in MacOS?
I'm debugging a program that has many alloca and triggers EXC_BAD_ACCESS (with -msanitize=address) or crashes __chkstk_darwin (without compiler sanitizer). I want to know the valid stack address range ...
3
votes
2
answers
120
views
How can I declare an array of pointers with blocks of NULL elems
I'm using an array of functions pointers, and I'd like to use it directly with their associated event IDs.
Problem is, event IDs start from 0x10 to 0x1C, and from 0x90 to 0xA5.
I don't want to write ...
-1
votes
1
answer
311
views
Why are some smaller embedded devices unable to run an operating system (and what exactly do they run off of instead)? [closed]
For context, this was taken from an excerpt in a book:
Finally, sometimes you can't even use heap memory! If you are programming in Rust for a small embedded device, you are going to have to use only ...
0
votes
0
answers
103
views
Problem with displaying stack values in a loop
rephrased the question
Getting segmentation fault right after last printf after iterating and displaying stack values (2 iterations for simplicity purposes).
Just trying to display hex value on the ...