[PATCH] nvptx: Add _ssize_t as _READ_WRITE_RETURN_TYPE in newlib/libc/include/sys/config.h

Arijit Kumar Das arijitkdgit.official@gmail.com
Thu Jul 17 11:30:59 GMT 2025


Hi Thomas!

Here's the updated version and (hopefully) this one's done as you instructed :-)

Best regards,
Arijit


>From b7ed7f8883053fd84c77a87e69ed757b55551b5f Mon Sep 17 00:00:00 2001
From: Arijit Kumar Das <arijitkdgit.official@gmail.com>
Date: Thu, 17 Jul 2025 16:21:16 +0530
Subject: [PATCH] nvptx: Change 'read' and 'write' to 'ssize_t' return type

This commit changes the return type of the read() and write() syscalls for
nvptx to ssize_t. This would allow large files to be handled properly by
these syscalls in situations where the read/write buffer length exceeds
INT_MAX, for example. This also makes the syscall signatures fully complaint
with their current POSIX specifications.

We additionally define two macros: '_READ_WRITE_RETURN_TYPE' as _ssize_t and
'_READ_WRITE_BUFSIZE_TYPE' as __size_t in libc/include/sys/config.h under
__nvptx__ for consistency.

Signed-off-by: Arijit Kumar Das <arijitkdgit.official@gmail.com>
---
 newlib/libc/include/sys/config.h  | 5 +++++
 newlib/libc/machine/nvptx/misc.c  | 2 +-
 newlib/libc/machine/nvptx/write.c | 3 ++-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h
index 4c9acc55c..c3cd51e86 100644
--- a/newlib/libc/include/sys/config.h
+++ b/newlib/libc/include/sys/config.h
@@ -12,6 +12,11 @@
 #define __DYNAMIC_REENT__
 #endif

+#ifdef __nvptx__
+#define _READ_WRITE_RETURN_TYPE _ssize_t
+#define _READ_WRITE_BUFSIZE_TYPE __size_t
+#endif
+
 /* exceptions first */
 #if defined(__H8500__) || defined(__W65__)
 #define __SMALL_BITFIELDS
diff --git a/newlib/libc/machine/nvptx/misc.c b/newlib/libc/machine/nvptx/misc.c
index 56e66b9f3..829921ec2 100644
--- a/newlib/libc/machine/nvptx/misc.c
+++ b/newlib/libc/machine/nvptx/misc.c
@@ -62,7 +62,7 @@ open (const char *pathname, int flags, ...) {
   return -1;
 }

-int
+ssize_t
 read(int fd, void *buf, size_t count) {
   return 0;
 }
diff --git a/newlib/libc/machine/nvptx/write.c
b/newlib/libc/machine/nvptx/write.c
index 0544dd05e..38f086893 100644
--- a/newlib/libc/machine/nvptx/write.c
+++ b/newlib/libc/machine/nvptx/write.c
@@ -18,7 +18,8 @@
 #include <unistd.h>
 #include <errno.h>

-_READ_WRITE_RETURN_TYPE write (int fd, const void *buf, size_t count)
+ssize_t
+write (int fd, const void *buf, size_t count)
 {
   size_t i;
   char *b = (char *)buf;
-- 
2.39.5

On Thu, Jul 17, 2025 at 1:49 PM Thomas Schwinge <tschwinge@baylibre.com> wrote:
>
> Hi Arijit!
>
> On 2025-07-17T01:27:41+0530, Arijit Kumar Das <arijitkdgit.official@gmail.com> wrote:
> > Here's the final commit. I hope it's okay :-)
>
> Almost.  ;-)
>
> > From 3089acec0f3b5606bffcbca3b6864023ccd2afa3 Mon Sep 17 00:00:00 2001
> > From: Arijit Kumar Das <arijitkdgit.official@gmail.com>
> > Date: Thu, 17 Jul 2025 01:01:03 +0530
> > Subject: [PATCH] [nvptx]: Use _READ_WRITE_RETURN_TYPE for return type and
> >  _READ_WRITE_BUFSIZE_TYPE for count in read() and write()
>
> The important thing about this commit is the changes of types.  I'd say:
>
>     nvptx: Change 'read' and 'write' to 'ssize_t' return type, and 'size_t count'
>
> Your following text is just textually describing the commit:
>
> > - Changed the return type of read() from int to _READ_WRITE_RETURN_TYPE as per conventions.
> > - Changed the 'count' parameter of read() and write() to _READ_WRITE_BUFSIZE_TYPE.
> > - Defined both of the above macros in libc/include/sys/config.h under __nvptx__.
> > - _READ_WRITE_RETURN_TYPE defined as _ssize_t (ssize_t).
> > - _READ_WRITE_BUFSIZE_TYPE defined as __size_t (size_t).
>
> ..., so I personally wouldn't include that.  Instead, you could add some
> rationale, perhaps:
>
>     ... to match their specification in POSIX, and enable large files.
>
> > Signed-off-by: Arijit Kumar Das <arijitkdgit.official@gmail.com>
> > ---
> >  newlib/libc/include/sys/config.h  | 5 +++++
> >  newlib/libc/machine/nvptx/misc.c  | 4 ++--
> >  newlib/libc/machine/nvptx/write.c | 3 ++-
> >  3 files changed, 9 insertions(+), 3 deletions(-)
>
> > --- a/newlib/libc/include/sys/config.h
> > +++ b/newlib/libc/include/sys/config.h
> > @@ -12,6 +12,11 @@
> >  #define __DYNAMIC_REENT__
> >  #endif
> >
> > +#ifdef __nvptx__
> > +#define _READ_WRITE_RETURN_TYPE _ssize_t
> > +#define _READ_WRITE_BUFSIZE_TYPE __size_t
> > +#endif
> > +
> >  /* exceptions first */
> >  #if defined(__H8500__) || defined(__W65__)
> >  #define __SMALL_BITFIELDS
>
> ACK.
>
> But for the following two nvptx-specific implementation files:
>
> > --- a/newlib/libc/machine/nvptx/misc.c
> > +++ b/newlib/libc/machine/nvptx/misc.c
>
> > -int
> > -read(int fd, void *buf, size_t count) {
> > +_READ_WRITE_RETURN_TYPE
> > +read(int fd, void *buf, _READ_WRITE_BUFSIZE_TYPE count) {
>
> > --- a/newlib/libc/machine/nvptx/write.c
> > +++ b/newlib/libc/machine/nvptx/write.c
>
> > -_READ_WRITE_RETURN_TYPE write (int fd, const void *buf, size_t count)
> > +_READ_WRITE_RETURN_TYPE
> > +write (int fd, const void *buf, _READ_WRITE_BUFSIZE_TYPE count)
> >  {
>
> ..., I'd like you to use the actual types.  So, please here replace
> '_READ_WRITE_RETURN_TYPE' with 'ssize_t', and revert back
> '_READ_WRITE_BUFSIZE_TYPE' to 'size_t'.
>
>
> Grüße
>  Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-nvptx-Change-read-and-write-to-ssize_t-return-type-a.patch
Type: text/x-patch
Size: 2252 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20250717/b5c12b4c/attachment.bin>


More information about the Newlib mailing list