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
1
vote
1 answer

Program break doesnt change after calling malloc in a loop?

Running this piece of code is supposed to cause program break to increase by about malloc_counts * _SC_PAGESIZE instead I get fixed program break each time, so why is this. malloc is supposed to call brk or sbrk which itself round up size passed to…
KMG
  • 1,433
  • 1
  • 8
  • 19
1
vote
1 answer

Can I get the current sbrk() limit in gdb?

I would like to know what the current sbrk() limit is to debug a SEGV I'm having a hard time with. My code looks good and works in most cases (only one case out of quite many breaks with SEGV.) I'm thinking it may be in link with the fact that in…
Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
1
vote
0 answers

How to find where the stack ends in C

As a personal project, I want to write my own malloc implementation in C using sbrk (not mmap). I know that I can use sbrk(0) to determine the end of the data segment, which would mark the end of my heap. However, I would like to accurately have my…
user129137
  • 71
  • 1
  • 4
1
vote
0 answers

What does (char*)-1 mean?

I am wondering what does: (char*)-1 mean and what does it evaluate to? It is a return value from sbrk() in case of an error.
Vikas Yadav
  • 322
  • 2
  • 9
1
vote
2 answers

multiple malloc calls internally calling mmap only once

When I try the below code I am not clearly able to analyze malloc api internal calls.What I am not clear is about the system call mmap is called only once for 2 or more malloc calls.If I am assigning more then 4069 bytes also it is calling only one…
Harish
  • 341
  • 1
  • 13
1
vote
2 answers

Why do I hit invalid memory after sbrk?

I'm trying to use the sbrk system call to ask for one memory page and divide that page into small blocks, but my code always hits some invalid memory: void sbrkBlocks() { int *b = sbrk(0); if(sbrk(sysconf(_SC_PAGESIZE)) == (void *)-1) { …
qr rq
  • 13
  • 3
1
vote
2 answers

How to find the current location of the program break

I tried adding this inside the brk system call function : void *addr = sbrk(0); printk("current-add-is-%p-\n", addr); But it returned error during kernel compilation that implicit declaration of sbrk function. And I could not find where sbrk is…
Arjun Bora
  • 439
  • 2
  • 8
  • 20
1
vote
2 answers

Undefined reference to _sbrk in ChibiOS

I'm using ChibiOS 3.x to write an embedded application. When compiling/linking it, I encounter an error message like this: /usr/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/libg.a(lib_a-sbrkr.o): In function…
Uli Köhler
  • 13,012
  • 16
  • 70
  • 120
1
vote
5 answers

Sbrk and negative parameter

I am running into a problem when i am freeing memory using sbrk. I pass sbrk a negative value but it doesnt decrement the start of the heap. Here is the code int main(int argc, char** argv) { void * a = sbrk(0); printf("%p\n",a); …
cthemc
  • 27
  • 1
  • 7
1
vote
0 answers

Arduino Due in Atmel Studio 6.1. without Visualmikro

I prefer the tutorial from http://www.engblaze.com/tutorial-using-atmel-studio-6-with-arduino-projects/ over Visualmikro because I love being able to jump inside the arduino functions and modify them without having to install any kind of plugin. I…
Boern
  • 7,233
  • 5
  • 55
  • 86
1
vote
1 answer

Memory (sbrk) 16-byte aligned shifting on pointer access

I wrote a reasonably basic memory allocator using sbrk. I ask for a chunk of memory, say 65k and carve it up as needed for variables requesting dynamic memory. I free the memory by adding it back to the 65k block. The 65k block is derived from a…
1
vote
1 answer

Opinions and suggestions regarding my approach to first fit malloc function

I'm writing a malloc function for a college assignment. Here's a basic layout of my idea: 1)Define a node struct with pointers to previous node, next node, as well as a char for size and vacancy. Each region in the heap will contain a hidden node…
rmh52
  • 193
  • 1
  • 1
  • 4
1
vote
0 answers

linker error on arm neon code

I am working on ARM neon code using c intrinsics. When I compile the file I keep getting the following errors: c:/program files (x86)/codesourcery/sourcery g++ lite/bin/../lib/gcc/arm-none-ea bi/4.3.3/../../../../arm-none-eabi/bin/ld.exe:…
Prachi Chouksey
  • 153
  • 1
  • 1
  • 7
0
votes
2 answers

Allocating proper memory size

I am having an issue with allocating the right size of memory in my program. I do the following: void * ptr = sbrk(sizeof(void *)+sizeof(unsigned int)); When I do this, I think it is adding too much memory to the heap because it is allocating it…
mrswmmr
  • 2,081
  • 5
  • 21
  • 23
0
votes
0 answers

sbrk abnormal behavior when writing my own malloc

My device is Apple MacBook M1 I am writing a "malloc" function using brk and sbrk, however when I am advancing my unit test I found some strange things about sbrk when I need to use it to extend my heap. The issue: Here I will give a minimized…
billz
  • 11
  • 1