47 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
2
answers
93
views
What difference between brk() and syscall(SYS_brk,)
man 2 brk says:
int brk(void *addr);
brk() sets the end of the data segment to the value specified by addr ...
On success, brk() returns zero. On error, -1 is returned, and errno is set to ENOMEM.
...
0
votes
0
answers
82
views
segmentation fault when calling brk() and printf() [duplicate]
Note: sys_brk returns the program break while brk() returns 0 or -1.(According to manual brk(2), NOTES)
The following code can pass.
#include <unistd.h>
#include <stdio.h>
#include <...
1
vote
0
answers
66
views
Can the pointer returned by sys _brk overlap the stack on Linux?
Based on info in https://man7.org/linux/man-pages/man2/brk.2.html, the brk Linux system call works like this:
void *sys_brk(void *desired_break) { return (void*)syscall(SYS_brk, desired_break); }
It ...
pts's user avatar
- 88.7k
1
vote
1
answer
691
views
In what circumstances can malloc_trim(0) cause a crash?
I have a piece of code where I am using malloc_trim(0) to release any unused memory back to the system.
But very intermittently I am see that it causes a crash. Backtraces below:
Program terminated ...
1
vote
1
answer
201
views
Why using both malloc/calloc/realloc and brk functions will results in undefined behavior?
Does this means using one of (malloc or calloc or realloc) and one of(brk/sbrk) concurrently results in UB or using both malloc and calloc can also cause UB?
This happends through the entire program ...
0
votes
0
answers
444
views
Too many brk() noticed in strace
I have a c++ service, where I am trying to debug the cause of high service startup time. From strace logs I notice a lot of brk() (which contributes to about 300ms, which is very high for our SLA). On ...
0
votes
2
answers
136
views
Heap break will not change after free()?
Code:
int main() {
printf("entering main. %p\n", sbrk(0));
void* ptr = malloc(300 * 1024);
memset(ptr, 0xBE, 300 * 1024);
printf("Allocated memory. %p\n", sbrk(0));...
0
votes
0
answers
111
views
Memory allocation of program without any allocation syscalls
I am currently working on a C program in Debian. This program at first allocates several gigabytes of memory. the problem is that after the startup of the program, still it is allocating memory. I ...
0
votes
0
answers
82
views
Problems with malloc
int main(int argc, char ** argv)
{
char *p[10];
for(int i =0 ; i < 10; ++i)
{
ssize_t msize = pow(2,i) * sizeof(char);
p[i] = (char*)malloc(msize);
printf(&...
0
votes
1
answer
161
views
Why are user processes responsible for requesting memory from the OS?
Heap allocators are responsible for actively requesting memory from the OS to grow the heap, e.g., with brk or mmap. Accessing unallocated memory leads to segfaults.
I could design a different OS-user ...
0
votes
1
answer
172
views
Can I enforce sbrk return address to be within a certain specific range?
I want to make sure the return address of sbrk is within a certain specific range. I read somewhere that sbrk allocates from an area allocated at program initialization. So I'm wondering if there's ...
2
votes
2
answers
2k
views
Will malloc round up to the nearest page size?
I'm not sure if I'm asking a noob question here, but here I go. I also searched a lot for a similar question, but I got nothing.
So, I know how mmap and brk work and that, regardless of the length you ...
1
vote
1
answer
524
views
Own Malloc implementation freeze at brk
for practice I'm currently trying to write my own malloc function in c.
So my question is, after some allocation from the heap my program will freeze. I found the code segment which will couse the ...
0
votes
1
answer
1k
views
Need to align memory on a power of 2 and align the program break on a multiple of 2 * getpagesize() in C
I'm re-coding the malloc function using brk, sbrk & getpagesize()
I must follow two rules:
1)
I must align my memory on a power of 2
It means: If the call to malloc is : malloc(9); i must ...
1
vote
1
answer
117
views
Why isn't argument of brk(void *end_data_segment), rounded up to the next page boundary?
From The Linux Programming Interface:
int brk(void * end_data_segment );
The brk() system call sets the program break to the location specified
by end_data_segment. Since virtual memory is ...
Rick's user avatar
- 7,664