Handle IRQs inside the kernel
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m42s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m42s
This commit is contained in:
95
libmalloc/_malloc_port.c
Normal file
95
libmalloc/_malloc_port.c
Normal file
@@ -0,0 +1,95 @@
|
||||
#include <map.h>
|
||||
#include <page_size.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <system.h>
|
||||
|
||||
#define LACKS_UNISTD_H 1
|
||||
#define LACKS_SYS_MMAN_H 1
|
||||
#define LACKS_SYS_PARAM_H 1
|
||||
#define LACKS_FCNTL_H 1
|
||||
#define LACKS_SYS_TYPES_H 1
|
||||
#define LACKS_SCHED_H 1
|
||||
#define LACKS_ERRNO_H 1
|
||||
#define LACKS_STDLIB_H 1
|
||||
#define LACKS_TIME_H 1
|
||||
#define LACKS_STRINGS_H 1
|
||||
|
||||
#define ABORT \
|
||||
{ \
|
||||
(void)0; \
|
||||
}
|
||||
#define MALLOC_ALIGNMENT 16
|
||||
#define HAVE_MORECORE 0
|
||||
#define NO_MALLOC_STATS 1
|
||||
#define USE_LOCKS 2
|
||||
#define MALLOC_FAILURE_ACTION \
|
||||
do { \
|
||||
test ('M'); \
|
||||
} while (0)
|
||||
#define EINVAL -1
|
||||
#define ENOMEM -1
|
||||
#define DEFAULT_MMAP_THRESHOLD 0
|
||||
#define MLOCK_T int
|
||||
|
||||
#define open _open_dummy
|
||||
#define O_RDWR 0
|
||||
#define PROT_READ 0
|
||||
#define PROT_WRITE 0
|
||||
#define MAP_PRIVATE 0
|
||||
#define fprintf(...)
|
||||
|
||||
static MLOCK_T malloc_global_mutex;
|
||||
|
||||
static int _init_lock (MLOCK_T* lock) {
|
||||
*lock = mutex_create ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _fini_lock (MLOCK_T* lock) { return mutex_delete (*lock); }
|
||||
|
||||
static int _acquire_lock (MLOCK_T* lock) { return mutex_lock (*lock); }
|
||||
|
||||
static int _release_lock (MLOCK_T* lock) { return mutex_unlock (*lock); }
|
||||
|
||||
static int _try_lock (MLOCK_T* lock) { return mutex_try (*lock); }
|
||||
|
||||
#define INITIAL_LOCK(lk) _init_lock ((lk))
|
||||
|
||||
#define DESTROY_LOCK(lk) _fini_lock ((lk))
|
||||
|
||||
#define ACQUIRE_LOCK(lk) _acquire_lock ((lk))
|
||||
|
||||
#define RELEASE_LOCK(lk) _release_lock ((lk))
|
||||
|
||||
#define TRY_LOCK(lk)
|
||||
|
||||
int _open_dummy (const char* path, uint16_t modes) {
|
||||
(void)path, (void)modes;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* mmap (void* addr, size_t size, int prot, int flags, int fd, size_t off) {
|
||||
(void)prot, (void)fd, (void)off, (void)flags;
|
||||
|
||||
if (size == 0)
|
||||
return (void*)-1;
|
||||
|
||||
size = (size + PAGE_SIZE - 1) / PAGE_SIZE;
|
||||
|
||||
void* r = map ((uintptr_t)addr, size, MAP_FLAGS | MAP_RW);
|
||||
if (r == NULL)
|
||||
return (void*)-1;
|
||||
|
||||
memset (r, 0, size * PAGE_SIZE);
|
||||
return r;
|
||||
}
|
||||
|
||||
int munmap (void* addr, size_t length) {
|
||||
if (length == 0)
|
||||
return 0;
|
||||
|
||||
length = (length + PAGE_SIZE - 1) / PAGE_SIZE;
|
||||
|
||||
return unmap ((uintptr_t)addr, length);
|
||||
}
|
||||
Reference in New Issue
Block a user