We later will use this function on ARM(64) for allocating page tables.

Signed-off-by: Ralf Ramsauer <[email protected]>
---
 inmates/lib/alloc.c                 | 49 +++++++++++++++++++++++++++++
 inmates/lib/arm-common/Makefile.lib |  2 +-
 inmates/lib/inmate_common.h         |  3 ++
 inmates/lib/x86/Makefile            |  2 +-
 inmates/lib/x86/inmate.h            |  3 --
 inmates/lib/x86/mem.c               | 10 ------
 6 files changed, 54 insertions(+), 15 deletions(-)
 create mode 100644 inmates/lib/alloc.c

diff --git a/inmates/lib/alloc.c b/inmates/lib/alloc.c
new file mode 100644
index 00000000..3ada047c
--- /dev/null
+++ b/inmates/lib/alloc.c
@@ -0,0 +1,49 @@
+/*
+ * Jailhouse, a Linux-based partitioning hypervisor
+ *
+ * Copyright (c) Siemens AG, 2018
+ *
+ * Authors:
+ *  Jan Kiszka <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Alternatively, you can use or redistribute this file under the following
+ * BSD license:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * 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.
+ */
+
+#include <inmate.h>
+
+static unsigned long heap_pos = (unsigned long)stack_top;
+
+void *alloc(unsigned long size, unsigned long align)
+{
+       unsigned long base = (heap_pos + align - 1) & ~(align - 1);
+
+       heap_pos = base + size;
+       return (void *)base;
+}
diff --git a/inmates/lib/arm-common/Makefile.lib 
b/inmates/lib/arm-common/Makefile.lib
index 9edb2d9f..fc25f724 100644
--- a/inmates/lib/arm-common/Makefile.lib
+++ b/inmates/lib/arm-common/Makefile.lib
@@ -36,7 +36,7 @@
 # THE POSSIBILITY OF SUCH DAMAGE.
 #
 
-objs-y := ../string.o ../cmdline.o ../setup.o
+objs-y := ../string.o ../cmdline.o ../setup.o ../alloc.o
 objs-y += printk.o gic.o timer.o
 objs-y += uart-jailhouse.o uart-pl011.o uart-8250.o uart-8250-8.o
 objs-y += uart-xuartps.o uart-mvebu.o uart-hscif.o uart-scifa.o uart-imx.o
diff --git a/inmates/lib/inmate_common.h b/inmates/lib/inmate_common.h
index ba39550e..cdce825f 100644
--- a/inmates/lib/inmate_common.h
+++ b/inmates/lib/inmate_common.h
@@ -69,6 +69,8 @@ static inline void __attribute__((noreturn)) stop(void)
 
 void printk(const char *fmt, ...);
 
+void *alloc(unsigned long size, unsigned long align);
+
 void *memset(void *s, int c, unsigned long n);
 void *memcpy(void *d, const void *s, unsigned long n);
 int memcmp(const void *s1, const void *s2, unsigned long n);
@@ -86,6 +88,7 @@ bool cmdline_parse_bool(const char *param);
        const char cmdline[size] __attribute__((section(".cmdline")))
 
 extern const char cmdline[];
+extern const char stack_top[];
 
 void inmate_main(void);
 
diff --git a/inmates/lib/x86/Makefile b/inmates/lib/x86/Makefile
index 31e025c9..0ae88e39 100644
--- a/inmates/lib/x86/Makefile
+++ b/inmates/lib/x86/Makefile
@@ -41,7 +41,7 @@ include $(INMATES_LIB)/Makefile.lib
 always := lib.a lib32.a
 
 TARGETS := header.o hypercall.o ioapic.o printk.o smp.o
-TARGETS += ../pci.o ../string.o ../cmdline.o ../setup.o
+TARGETS += ../alloc.o ../pci.o ../string.o ../cmdline.o ../setup.o
 TARGETS_64_ONLY := int.o mem.o pci.o timing.o
 
 lib-y := $(TARGETS) $(TARGETS_64_ONLY)
diff --git a/inmates/lib/x86/inmate.h b/inmates/lib/x86/inmate.h
index 0636420c..f8ae5e55 100644
--- a/inmates/lib/x86/inmate.h
+++ b/inmates/lib/x86/inmate.h
@@ -249,7 +249,6 @@ void apic_timer_set(unsigned long timeout_ns);
 
 enum map_type { MAP_CACHED, MAP_UNCACHED };
 
-void *alloc(unsigned long size, unsigned long align);
 void map_range(void *start, unsigned long size, enum map_type map_type);
 
 u32 pci_read_config(u16 bdf, unsigned int addr, unsigned int size);
@@ -264,8 +263,6 @@ extern volatile u32 smp_num_cpus;
 extern u8 smp_cpu_ids[SMP_MAX_CPUS];
 void smp_wait_for_all_cpus(void);
 void smp_start_cpu(unsigned int cpu_id, void (*entry)(void));
-
-extern const char stack_top[];
 #endif
 
 #include "../inmate_common.h"
diff --git a/inmates/lib/x86/mem.c b/inmates/lib/x86/mem.c
index 42b193d6..c6903897 100644
--- a/inmates/lib/x86/mem.c
+++ b/inmates/lib/x86/mem.c
@@ -43,16 +43,6 @@
 #define PG_PS          0x80
 #define PG_PCD         0x10
 
-static unsigned long heap_pos = (unsigned long)stack_top;
-
-void *alloc(unsigned long size, unsigned long align)
-{
-       unsigned long base = (heap_pos + align - 1) & ~(align - 1);
-
-       heap_pos = base + size;
-       return (void *)base;
-}
-
 void map_range(void *start, unsigned long size, enum map_type map_type)
 {
        unsigned long pt_addr, *pt_entry, *pt;
-- 
2.17.0

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to