mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* Why sbrk clear the increased memory region
@ 2019-04-22  3:13 张忠山
  2019-04-23  9:49 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: 张忠山 @ 2019-04-22  3:13 UTC (permalink / raw)
  To: barebox

Recently, I'm using barebox in a deep embedded project, and need some funtctions
in libc/libm, So I linked barebox with newlib

But whenever newlib call sbrk with negtive `increment`, barebox crash.

The reason is sbrk clean memory region using `increment`.

Why sbrk must clear the increased memory region? 

--------------------------------8<----------------------------- 
From dbaa658b60fe413e1d1818afad13a53e7ad000ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BC=A0=E5=BF=A0=E5=B1=B1?= <zzs213@126.com>
Date: Mon, 22 Apr 2019 11:01:33 +0800
Subject: [PATCH] only clear memory when increasing head size
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: 张忠山 <zzs213@126.com>
---
 common/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/memory.c b/common/memory.c
index 8f0b59891..0a8700d28 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -122,7 +122,7 @@ void *sbrk(ptrdiff_t increment)
 	void *old = sbrk_no_zero(increment);
 
 	/* Only clear increment, if valid address was returned */
-	if (old != NULL)
+	if ((old != NULL) && (increment > 0))
 		memset(old, 0, increment);
 
 	return old;
-- 
2.21.0

-- 
Best Regards,
zzs


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Why sbrk clear the increased memory region
  2019-04-22  3:13 Why sbrk clear the increased memory region 张忠山
@ 2019-04-23  9:49 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2019-04-23  9:49 UTC (permalink / raw)
  To: 张忠山; +Cc: barebox

On Mon, Apr 22, 2019 at 11:13:30AM +0800, 张忠山 wrote:
> Recently, I'm using barebox in a deep embedded project, and need some funtctions
> in libc/libm, So I linked barebox with newlib
> 
> But whenever newlib call sbrk with negtive `increment`, barebox crash.
> 
> The reason is sbrk clean memory region using `increment`.
> 
> Why sbrk must clear the increased memory region?

sbrk is used only for dlmalloc in barebox. AFAIK the dlmalloc
implementation needs the memory cleared. Also dlmalloxc probably never
calls sbrk with a negative increment, so this was never an issue.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-04-23  9:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-22  3:13 Why sbrk clear the increased memory region 张忠山
2019-04-23  9:49 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox