Fix __getreent stack calculations.

Message ID 20190607145501.23295-2-ams@codesourcery.com
State New
Headers show
Series
  • Fix __getreent stack calculations.
Related show

Commit Message

Andrew Stubbs June 7, 2019, 2:55 p.m.
Fix a bug in which the high-part of 64-bit values are being corrupted, leading
to erroneous stack overflow errors. The problem was only that the mixed-size
calculations are being treated as signed when they should be unsigned.
---
 newlib/libc/machine/amdgcn/getreent.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Jeff Johnston June 7, 2019, 5:59 p.m. | #1
Patch applied.

-- Jeff J.

On Fri, Jun 7, 2019 at 10:55 AM Andrew Stubbs <ams@codesourcery.com> wrote:

>

> Fix a bug in which the high-part of 64-bit values are being corrupted,

> leading

> to erroneous stack overflow errors. The problem was only that the

> mixed-size

> calculations are being treated as signed when they should be unsigned.

> ---

>  newlib/libc/machine/amdgcn/getreent.c | 12 ++++++------

>  1 file changed, 6 insertions(+), 6 deletions(-)

>

>

Patch

diff --git a/newlib/libc/machine/amdgcn/getreent.c b/newlib/libc/machine/amdgcn/getreent.c
index 5a28aa406..bc50ca022 100644
--- a/newlib/libc/machine/amdgcn/getreent.c
+++ b/newlib/libc/machine/amdgcn/getreent.c
@@ -35,9 +35,9 @@  __getreent (void)
      s[4:5] contains the dispatch pointer.
      
      WARNING: this code will break if s[0:3] is ever used for anything!  */
-  const register long buffer_descriptor asm("s0");
-  long private_segment = buffer_descriptor & 0x0000ffffffffffff;
-  const register int stack_offset asm("s11");
+  const register unsigned long buffer_descriptor asm("s0");
+  unsigned long private_segment = buffer_descriptor & 0x0000ffffffffffff;
+  const register unsigned int stack_offset asm("s11");
   const register hsa_kernel_dispatch_packet_t *dispatch_ptr asm("s4");
 
   struct data {
@@ -45,9 +45,9 @@  __getreent (void)
     struct _reent reent;
   } *data;
 
-  long stack_base = private_segment + stack_offset;
-  long stack_end = stack_base + dispatch_ptr->private_segment_size * 64;
-  long addr = (stack_end - sizeof(struct data)) & ~7;
+  unsigned long stack_base = private_segment + stack_offset;
+  unsigned long stack_end = stack_base + dispatch_ptr->private_segment_size * 64;
+  unsigned long addr = (stack_end - sizeof(struct data)) & ~7;
   data = (struct data *)addr;
 
   register long sp asm("s16");