aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@linux.intel.com>2011-06-13 23:03:31 +0100
committerMatt Fleming <matt.fleming@linux.intel.com>2011-07-21 11:38:59 +0100
commitaba10773b6fda96227f51cab74232d262e9801d8 (patch)
tree122f783f9108b3ae9c7286ef02aa971b5f8ca111
parent216f49f27bdb0353aae50730fc0af71054cf931d (diff)
downloadefilinux-aba10773b6fda96227f51cab74232d262e9801d8.tar.gz
efilinux: malloc support
Provide a malloc implementation with the same prototype as the standard C library. This implementation is a wrapper around allocate_pool() and allocates from the EfiLoaderData runtime pool. Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
-rw-r--r--Makefile2
-rw-r--r--malloc.c62
-rw-r--r--stdlib.h6
3 files changed, 69 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 59fc760..34bae3f 100644
--- a/Makefile
+++ b/Makefile
@@ -56,7 +56,7 @@ CFLAGS=-I. -I/usr/include/efi -I/usr/include/efi/$(ARCH) \
LDFLAGS=-T $(LDSCRIPT) -Bsymbolic -shared -nostdlib -L$(LIBDIR) $(CRT0)
IMAGE=efilinux.efi
-OBJS = entry.o
+OBJS = entry.o malloc.o
all: $(IMAGE)
diff --git a/malloc.c b/malloc.c
new file mode 100644
index 0000000..3e6c24b
--- /dev/null
+++ b/malloc.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2011, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products
+ * derived from this software without specific prior written
+ * permission.
+ *
+ * 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 OWNER 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 <efi.h>
+#include "efilinux.h"
+
+/**
+ * malloc - Allocate memory from the EfiLoaderData pool
+ * @size: size in bytes of the requested allocation
+ *
+ * Return a pointer to an allocation of @size bytes of type
+ * EfiLoaderData.
+ */
+void *malloc(UINTN size)
+{
+ EFI_STATUS err;
+ void *buffer;
+
+ err = allocate_pool(EfiLoaderData, size, &buffer);
+ if (err != EFI_SUCCESS)
+ buffer = NULL;
+
+ return buffer;
+}
+
+/**
+ * free - Release memory to the EfiLoaderData pool
+ */
+void free(void *buffer)
+{
+ free_pool(buffer);
+}
diff --git a/stdlib.h b/stdlib.h
new file mode 100644
index 0000000..1079e88
--- /dev/null
+++ b/stdlib.h
@@ -0,0 +1,6 @@
+#ifndef __STDLIB_H__
+#define __STDLIB_H__
+
+extern void *malloc(UINTN size);
+
+#endif /* __STDLIB_H__ */