aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-28 01:36:33 -0400
committerIan Moffett <ian@osmora.org>2024-03-28 01:36:33 -0400
commite43852ffc738b27cbb84d0aea85b677bd5d98f82 (patch)
tree8e45f8dee68ee3f6c24a9a788dcb7ad2159749f3
parentc426258d595e2b9490f037b8d8a768b6257d09f1 (diff)
kernel: vm_dynalloc: Add dynalloc_memalign()
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--share/man/man9/dynalloc.96
-rw-r--r--sys/include/vm/dynalloc.h1
-rw-r--r--sys/vm/vm_dynalloc.c12
3 files changed, 18 insertions, 1 deletions
diff --git a/share/man/man9/dynalloc.9 b/share/man/man9/dynalloc.9
index 64e0557..55b48eb 100644
--- a/share/man/man9/dynalloc.9
+++ b/share/man/man9/dynalloc.9
@@ -24,7 +24,7 @@
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
-.Dd Jan 12 2024
+.Dd Mar 28 2024
.Dt DYNALLOC 9
.Os Hyra
.Sh NAME
@@ -42,6 +42,10 @@ The
function is analogous to malloc() in other systems.
The
+.Ft dynalloc_memalign()
+function allows you to allocate aligned memory
+
+The
.Ft dynrealloc()
function is analogous to realloc() in other systems.
diff --git a/sys/include/vm/dynalloc.h b/sys/include/vm/dynalloc.h
index 1a30d3d..44d2f5a 100644
--- a/sys/include/vm/dynalloc.h
+++ b/sys/include/vm/dynalloc.h
@@ -37,6 +37,7 @@
#include <sys/types.h>
void *dynalloc(size_t sz);
+void *dynalloc_memalign(size_t sz, size_t align);
void *dynrealloc(void *old_ptr, size_t newsize);
void dynfree(void *ptr);
diff --git a/sys/vm/vm_dynalloc.c b/sys/vm/vm_dynalloc.c
index 0b8d668..dea4460 100644
--- a/sys/vm/vm_dynalloc.c
+++ b/sys/vm/vm_dynalloc.c
@@ -47,6 +47,18 @@ dynalloc(size_t sz)
return tmp;
}
+void *
+dynalloc_memalign(size_t sz, size_t align)
+{
+ struct vm_ctx *vm_ctx = vm_get_ctx();
+ void *tmp;
+
+ spinlock_acquire(&vm_ctx->dynalloc_lock);
+ tmp = tlsf_memalign(vm_ctx->tlsf_ctx, align, sz);
+ spinlock_release(&vm_ctx->dynalloc_lock);
+ return tmp;
+}
+
/*
* Reallocates memory pool created by `dynalloc()'
*