From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: linux/sbrk is wrong Date: Sun, 22 May 2011 16:55:55 +0200 Message-ID: <20110522145555.GE6142@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ibq+fG+Ci5ONsaof" X-Trace: dough.gmane.org 1306076182 12753 80.91.229.12 (22 May 2011 14:56:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 22 May 2011 14:56:22 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-89-gllmg-musl=m.gmane.org@lists.openwall.com Sun May 22 16:56:19 2011 Return-path: Envelope-to: gllmg-musl@lo.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by lo.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1QOA4o-0002ze-N4 for gllmg-musl@lo.gmane.org; Sun, 22 May 2011 16:56:18 +0200 Original-Received: (qmail 28446 invoked by uid 550); 22 May 2011 14:56:17 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 28438 invoked from network); 22 May 2011 14:56:17 -0000 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Xref: news.gmane.org gmane.linux.lib.musl.general:6 Archived-At: --ibq+fG+Ci5ONsaof Content-Type: text/plain; charset=us-ascii Content-Disposition: inline linux brk syscall returns the end pointer so if it fails then the old one if it succeeds then the new one the current implementation of sbrk returns the end of the allocated area instead of the begining i attached a patch that fixes brk and sbrk --ibq+fG+Ci5ONsaof Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="sbrk.diff" diff --git a/src/linux/brk.c b/src/linux/brk.c index 9f63c5a..c261518 100644 --- a/src/linux/brk.c +++ b/src/linux/brk.c @@ -2,5 +2,5 @@ int brk(void *end) { - return -(syscall(SYS_brk, end) == -1); + return -((void *)syscall(SYS_brk, end) != end); } diff --git a/src/linux/sbrk.c b/src/linux/sbrk.c index b2943a9..478a35e 100644 --- a/src/linux/sbrk.c +++ b/src/linux/sbrk.c @@ -3,5 +3,11 @@ void *sbrk(ptrdiff_t inc) { - return (void *)syscall(SYS_brk, syscall(SYS_brk, 0)+inc); + void *p = (void *)syscall(SYS_brk, 0); + + if (inc == 0) + return p; + if ((void *)syscall(SYS_brk, p+inc) == p+inc) + return p; + return (void *)-1; } --ibq+fG+Ci5ONsaof--