Verified Commit 59db5471 authored by Felix Kopp's avatar Felix Kopp
Browse files

malloc: rewrite with atomic support

parent 7e6dbad0
......@@ -14,12 +14,28 @@
/**
* @brief Allocate `size` bytes of memory *w/out initializing it*.
*
* This method may block if an allocation is already taking place.
* Use `atomic_malloc()` if you are in kernel space and in atomic context.
*
* @param size The amount of bytes to allocate.
* @return A pointer to the beginning of the memory area, or `NULL` if
* `size` was 0 or there is not enough free memory left.
*/
__shared __malloc(free, 1) void *malloc(size_t size);
/**
* @brief Allocate `size` bytes of memory *w/out initializing it*.
*
* Unlike `malloc()`, this method is guaranteed not to sleep. It does this by
* using a completely separate, smaller heap. Only use this if you already are
* in atomic context, like when in an irq.
*
* @param size Amount of bytes to allocate
* @return A pointer to the beginning of the memory area, or `NULL` if
* `size` was 0 or there is not enough free memory left.
*/
__malloc(free, 1) void *atomic_malloc(size_t size);
/**
* @brief Allocate an array and initialize the memory to zeroes.
* The allocated size will be at least `nmemb * size`.
......@@ -41,7 +57,7 @@ __shared void free(void *ptr);
/** @} */
/** Initialize the memory allocator, this is only called by the Kernel on early bootstrap. */
/** Initialize the memory allocator, this is only called by the bootloader on early bootstrap. */
void malloc_init(void *heap, size_t size);
/*
......
......@@ -16,17 +16,17 @@ enum syscall {
};
/** Perform an indirect system call. */
int syscall(enum syscall number, ...);
long syscall(enum syscall number, ...);
/** The table of system call handlers, indexed by syscall number. */
extern int (*const sys_table[NSYSCALLS])(sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
sysarg_t arg4, sysarg_t arg5, sysarg_t arg6);
extern long (*const sys_table[NSYSCALLS])(sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
sysarg_t arg4, sysarg_t arg5, sysarg_t arg6);
/* catchall handler that returns -ENOSYS */
int sys_stub(void);
long sys_stub(void);
int sys_read(int fd, void *buf, size_t len);
int sys_write(int fd, const void *buf, size_t len);
long sys_read(int fd, void *buf, size_t len);
long sys_write(int fd, const void *buf, size_t len);
/*
* This file is part of Ardix.
......
This diff is collapsed.
......@@ -12,6 +12,8 @@ set(CONFIG_NFILE 16 CACHE STRING "Maximum number of open files")
set(CONFIG_STACK_SIZE 2048 CACHE STRING "Stack size in bytes")
set(CONFIG_IOMEM_SIZE 8192 CACHE STRING "I/O memory size in bytes")
set(CONFIG_SCHED_MAXTASK 8 CACHE STRING "Maximum number of running tasks")
set(CONFIG_SCHED_FREQ 1000 CACHE STRING "Task switch frequency in Hz")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment