Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix-malloc #543

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions sw/device/lib/runtime/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ int _link (const char *__path1, const char *__path2);
_off_t _lseek (int __fildes, _off_t __offset, int __whence);
ssize_t _read (int __fd, void *__buf, size_t __nbyte);
void * _sbrk (ptrdiff_t __incr);
int _brk(void *addr);
int _unlink (const char *__path);
ssize_t _write (int __fd, const void *__buf, size_t __nbyte);
int _execve (const char *__path, char * const __argv[], char * const __envp[]);
Expand Down Expand Up @@ -270,22 +271,26 @@ static char *brk = __heap_start;

int _brk(void *addr)
{
brk = addr;
return 0;
if (addr >= (void *)__heap_start && addr <= (void *)__heap_end) {
brk = addr;
return 0;
} else {
return -1;
}
}

void *_sbrk(ptrdiff_t incr)
{
char *old_brk = brk;

if (__heap_start == __heap_end) {
return NULL;
return NULL;
}

if ((brk += incr) < __heap_end) {
if (brk + incr < __heap_end && brk + incr >= __heap_start) {
brk += incr;
} else {
brk = __heap_end;
return (void *)-1;
}
return old_brk;
}
Loading