Skip to content

Commit

Permalink
Adjust mmap to new interface
Browse files Browse the repository at this point in the history
JIRA: RTOS-665
  • Loading branch information
badochov authored and agkaminski committed Nov 9, 2023
1 parent 090a2fd commit 993f5e7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
5 changes: 2 additions & 3 deletions include/sys/mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
#include <phoenix/mman.h>


#define MAP_ANON MAP_ANONYMOUS
#define MAP_FAILED (void *)-1
#define MAP_ANON MAP_ANONYMOUS


#ifdef __cplusplus
Expand All @@ -39,7 +38,7 @@ extern void meminfo(meminfo_t *info);
extern int syspageprog(syspageprog_t *prog, int index);


extern void *mmap(void *vaddr, size_t size, int prot, int flags, oid_t *oid, offs_t offs);
extern void *mmap(void *vaddr, size_t size, int prot, int flags, int fildes, off_t offs);


extern int munmap(void *vaddr, size_t size);
Expand Down
2 changes: 1 addition & 1 deletion pthread/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
}

void *stack = mmap(attrs->stackaddr, attrs->stacksize,
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, NULL, 0);
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

if ((stack == MAP_FAILED) || (stack == NULL)) {

Check failure on line 225 in pthread/pthread.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

'MAP_FAILED' undeclared (first use in this function); did you mean 'MAP_FIXED'?

Check failure on line 225 in pthread/pthread.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-qemu)

'MAP_FAILED' undeclared (first use in this function); did you mean 'MAP_FIXED'?

Check failure on line 225 in pthread/pthread.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a9-zynq7000-zedboard)

'MAP_FAILED' undeclared (first use in this function); did you mean 'MAP_FIXED'?
return EAGAIN;
Expand Down
6 changes: 4 additions & 2 deletions stdio/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ static void *buffAlloc(size_t size)
void *ret;

#ifndef NOMMU
if ((ret = mmap(NULL, (size + (_PAGE_SIZE - 1)) & ~(_PAGE_SIZE - 1), PROT_READ | PROT_WRITE, MAP_ANONYMOUS, NULL, 0)) == MAP_FAILED) {
ret = mmap(NULL, (size + (_PAGE_SIZE - 1)) & ~(_PAGE_SIZE - 1), PROT_READ | PROT_WRITE, MAP_ANONYMOUS, -1, 0);
if (ret == MAP_FAILED) {
return NULL;
}
#else
Expand Down Expand Up @@ -1150,7 +1151,8 @@ FILE *popen(const char *command, const char *mode)
goto failed;
}

if ((pf->file.buffer = mmap(NULL, BUFSIZ, PROT_READ | PROT_WRITE, MAP_ANONYMOUS, NULL, 0)) == MAP_FAILED) {
pf->file.buffer = mmap(NULL, BUFSIZ, PROT_READ | PROT_WRITE, MAP_ANONYMOUS, -1, 0);
if (pf->file.buffer == MAP_FAILED) {
goto failed;
}

Expand Down
8 changes: 5 additions & 3 deletions stdlib/malloc_dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,14 @@ static heap_t *_malloc_heapAlloc(size_t size)
size_t heapSize = CEIL(sizeof(heap_t) + size, _PAGE_SIZE);
heap_t *heap;

if (heapSize < size)
if (heapSize < size) {
return NULL;
}

heap = mmap(NULL, heapSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, NULL, 0);
if (heap == MAP_FAILED)
heap = mmap(NULL, heapSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (heap == MAP_FAILED) {
return NULL;
}

chunk = (chunk_t*) heap->space;

Expand Down
4 changes: 3 additions & 1 deletion stdlib/malloc_trivial3.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ static heap_t *_malloc_heapCreate(size_t size)
heap_t *heap;
chunk_t *chunk;

if ((heap = mmap((void *)0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, NULL, 0)) == NULL)
heap = mmap((void *)0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (heap == NULL) {
return NULL;
}

heap->size = size;
chunk = (chunk_t *)(heap + 1);
Expand Down

0 comments on commit 993f5e7

Please sign in to comment.