Questions tagged [sbrk]

**sbrk** is a basic memory management system call used in Unix and Unix-like operating systems to control the amount of memory allocated to the data segment[clarification needed] of the process.

sbrk is a basic memory management system call used in Unix and Unix-like operating systems to control the amount of memory allocated to the data segment[clarification needed] of the process. These calls are typically made from a higher-level memory management library such as malloc. In the original Unix system, brk and sbrk were the only ways in which applications could acquire additional data space; later versions allowed this to also be done using the mmap call

97 questions
0
votes
0 answers

What does sys_brk call return?

Can you please explain me what is program break point and what sys_brk call returns in Linux on x86-64 architecture. I used to think that break point of the program is the last valid address in the program's address space. If I want to extend it, I…
0
votes
0 answers

Writing to allocated memory with sbrk results in segfault

I'm trying to allocate memory with sys_brk and here is the program: BYTES_TO_ALLOCATE equ 0x08 section .text global _start _start: mov rax, 12 ;sys_brk number mov rdi, BYTES_TO_ALLOCATE syscall mov cl, 0x00 ;setting the value…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
0
votes
1 answer

How the system know the end of data segment

2 Questions (the same topic) : Some examples : Let's say i have something like that in assembly (GCC Compilation) : movl 12 -4(%rbp) When i will give the adress -4(%rbp) to another instruction, how the system will know where stop ? Because -4(%rbp)…
0
votes
0 answers

why free() doesn't decrease programs data space

My understanding is that malloc internally uses sbrk() and sbrk(0) gives pointer to current location of the program break. then according to following code :- #include #include int main() { printf("Before allocation :-…
0
votes
1 answer

TDM-GCC - undefined reference to sbrk() in Kernighan & Ritchie's Storage Allocator implementation program

I am trying to understand the storage allocator program shown in Kernighan and Ritchie's book "The C Programming Language, 2nd edition". I think I understood most, but when I code the program in Windows 8.1 x86_64 with TDM GCC version 5.1.0. It…
KeyC0de
  • 4,728
  • 8
  • 44
  • 68
0
votes
1 answer

splitting an sbrk into 2

To recode the malloc function, I do a sbrk(stack) where : void *malloc(size_t size) { stack = 0; while (stack < size) stack += 4096; } I malloc always more than I need then I want to take some of this allocated area of size size and return…
0
votes
1 answer

Program hangs only on first run?

I'm trying to debug a low-level C program in gdb. The program in question is meant to act as a wrapper, launching another process and monitoring/interfering with its memory use. When I load the program in gdb, everything seems normal (if not ideal)…
Draconis
  • 3,209
  • 1
  • 19
  • 31
0
votes
0 answers

Decreasing the heap with sbrk can collide with the data segment?

I know that allocating too much free memory to the heap can collide with the stack, but what about the data segment? Because sbrk can be used with a negative value. Thanks in advance.
0
votes
2 answers

Newlib stubs in static library

I am using Eclipse to develop bare-metal applications. I link against newlib, so I provided my own implementation of _sbrk(). This function was normally included in my project, and everything was working great. Now I try to move this function to a…
0
votes
2 answers

C code for implementing my own malloc function

I have a problem with my C code. I have to make a malloc function. First of all there is my code: #include #include #include "my-malloc.h" #define MOST_RESTRICTING_TYPE double // Pour s’aligner sur des frontieres multiples //…
0
votes
1 answer

Why my implementation of sbrk system call does not work?

I try to write a very simple os to better understand the basic principles. And I need to implement user-space malloc. So at first I want to implement and test it on my linux-machine. At first I have implemented the sbrk() function by the following…
user1886376
0
votes
1 answer

Segmentation fault for a weird unknown reason

I get a segmentation fault (core dumped) in the following peace of code (I'm implementing malloc(), free() and realloc()): void free(void* ptr) { void* curr = head; void* before = NULL; int isLegal = 0; /*Line X*/printf("curr is…
Jack
  • 111
  • 1
  • 1
  • 6
0
votes
2 answers

sbrk and malloc in c

I have following code #include int main () { void *result[20]; void *endptr; void *x; for (i = 0; i < 20; i++) { result[i] = malloc(10); printf("111 : %d\n",result[i]); …
user1079065
  • 2,085
  • 9
  • 30
  • 53
0
votes
2 answers

C: sbrk() addresses ascending or descending?

When sbrk() returns a pointer to an address that is the beginning of the heap, are the addresses ascending or descending? For example, if I had a 10 byte heap from addresses 1 to 10, would sbrk() return a pointer to address 10 or 1? On a similar…
user2821275
0
votes
1 answer

using brk to get brk_start

Manual for int brk(void *end_data_segment); says: "brk() sets the end of the data segment to the value specified by end_data_segment" On Success it returns 0 else -1. But how to I get the init value of my break (like sbrk(0))? best regards,
user1735225
  • 113
  • 10