public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin] RISC-V: Fix _sbrk, it's failed only when return value is -1.
Date: Wed, 29 Aug 2018 13:50:00 -0000	[thread overview]
Message-ID: <20180829135025.13492.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=9e032fd939a188b38ab36b6e94c93056ed347952

commit 9e032fd939a188b38ab36b6e94c93056ed347952
Author: Denis Ivanov <denis.ivanov@cloudbear.ru>
Date:   Fri Jul 6 19:03:23 2018 +0300

    RISC-V: Fix _sbrk, it's failed only when return value is -1.
    
    Signed-off-by: Kito Cheng <kito.cheng@gmail.com>

Diff:
---
 libgloss/riscv/internal_syscall.h | 11 ++++++++---
 libgloss/riscv/sys_sbrk.c         |  8 ++++----
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/libgloss/riscv/internal_syscall.h b/libgloss/riscv/internal_syscall.h
index 8f7dcb4..e5d5594 100644
--- a/libgloss/riscv/internal_syscall.h
+++ b/libgloss/riscv/internal_syscall.h
@@ -40,13 +40,18 @@ __internal_syscall(long n, long _a0, long _a1, long _a2, long _a3, long _a4, lon
   asm volatile ("scall"
 		: "+r"(a0) : "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(syscall_id));
 
+  return a0;
+}
+
+static inline long
+syscall_errno(long n, long _a0, long _a1, long _a2, long _a3, long _a4, long _a5)
+{
+  long a0 = __internal_syscall (n, _a0, _a1, _a2, _a3, _a4, _a5);
+
   if (a0 < 0)
     return __syscall_error (a0);
   else
     return a0;
 }
 
-#define syscall_errno(n, a, b, c, d, e, f) \
-        __internal_syscall(n, (long)(a), (long)(b), (long)(c), (long)(d), (long)(e), (long)(f))
-
 #endif
diff --git a/libgloss/riscv/sys_sbrk.c b/libgloss/riscv/sys_sbrk.c
index 19802fb..f91c2c5 100644
--- a/libgloss/riscv/sys_sbrk.c
+++ b/libgloss/riscv/sys_sbrk.c
@@ -41,14 +41,14 @@ _sbrk(ptrdiff_t incr)
 
   if (heap_end == 0)
     {
-      long brk = syscall_errno (SYS_brk, 0, 0, 0, 0, 0, 0);
+      long brk = __internal_syscall (SYS_brk, 0, 0, 0, 0, 0, 0);
       if (brk == -1)
-	return (void *)-1;
+        return (void *)__syscall_error (-ENOMEM);
       heap_end = brk;
     }
 
-  if (syscall_errno (SYS_brk, heap_end + incr, 0, 0, 0, 0, 0) != heap_end + incr)
-    return (void *)-1;
+  if (__internal_syscall (SYS_brk, heap_end + incr, 0, 0, 0, 0, 0) != heap_end + incr)
+    return (void *)__syscall_error (-ENOMEM);
 
   heap_end += incr;
   return (void *)(heap_end - incr);


                 reply	other threads:[~2018-08-29 13:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20180829135025.13492.qmail@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=newlib-cvs@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).