mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 6/8] add dummy_malloc functions
Date: Fri,  8 Apr 2011 16:56:17 +0200	[thread overview]
Message-ID: <1302274579-11158-7-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1302274579-11158-1-git-send-email-s.hauer@pengutronix.de>

For some environments the dummy malloc functions offer a very small
alternative implementation. malloc will get its memory from sbrk()
and never frees memory again.
This of course is not suitable for interactive environments and thus
depends on CONFIG_SHELL_NONE

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/Kconfig        |   16 ++++++++++++++++
 common/Makefile       |    3 ++-
 common/dummy_malloc.c |   26 ++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletions(-)
 create mode 100644 common/dummy_malloc.c

diff --git a/common/Kconfig b/common/Kconfig
index c3449a9..7d2367b 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -148,6 +148,22 @@ config EXPERIMENTAL
 	bool
 	prompt "Prompt for experimental code"
 
+choice
+	prompt "malloc implementation"
+
+config MALLOC_DLMALLOC
+	bool "dlmalloc"
+
+config MALLOC_DUMMY
+	bool "dummy malloc"
+	depends on SHELL_NONE
+	help
+	  select this option to use a dummy malloc implementation. With this
+	  memory is never freed. This is suitable for well tested noninteractive
+	  environments only.
+
+endchoice
+
 config MODULES
 	depends on HAS_MODULES
 	depends on EXPERIMENTAL
diff --git a/common/Makefile b/common/Makefile
index aa2c222..9fed2ae 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -9,7 +9,8 @@ obj-$(CONFIG_POLLER)		+= poller.o
 obj-$(CONFIG_BLOCK)		+= block.o
 
 obj-y += memory.o
-obj-y += dlmalloc.o
+obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
+obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
 obj-y += clock.o
 obj-y += version.o
 obj-$(CONFIG_COMMAND_SUPPORT) += command.o
diff --git a/common/dummy_malloc.c b/common/dummy_malloc.c
new file mode 100644
index 0000000..213e51d
--- /dev/null
+++ b/common/dummy_malloc.c
@@ -0,0 +1,26 @@
+#include <common.h>
+#include <malloc.h>
+
+void *memalign(size_t alignment, size_t bytes)
+{
+	unsigned long mem = (unsigned long)sbrk(bytes + alignment);
+
+	mem = (mem + alignment) & ~(alignment - 1);
+
+	return (void *)mem;
+}
+
+void *malloc(size_t size)
+{
+	return memalign(8, size);
+}
+
+void free(void *ptr)
+{
+}
+
+void *realloc(void *ptr, size_t size)
+{
+	BUG();
+}
+
-- 
1.7.2.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2011-04-08 14:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-08 14:56 Size reduction patches Sascha Hauer
2011-04-08 14:56 ` [PATCH 1/8] env: Make environment variable support optional Sascha Hauer
2011-04-08 14:56 ` [PATCH 2/8] make command " Sascha Hauer
2011-04-08 14:56 ` [PATCH 3/8] add noshell support Sascha Hauer
2011-04-08 14:56 ` [PATCH 4/8] arm: compile icache command only when command support is present Sascha Hauer
2011-04-08 14:56 ` [PATCH 5/8] malloc: put common memory functions to seperate file Sascha Hauer
2011-04-08 14:56 ` Sascha Hauer [this message]
2011-04-08 14:56 ` [PATCH 7/8] ARM: make exception handling optional Sascha Hauer
2011-04-08 14:56 ` [PATCH 8/8] nand: make reading oob optional Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1302274579-11158-7-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox