| Message ID | 20250714024141.99939-1-arijitkdgit.official@gmail.com |
|---|---|
| State | New |
| Headers |
Return-Path: <newlib-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B63E33858C54 for <patchwork@sourceware.org>; Mon, 14 Jul 2025 02:43:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B63E33858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1752461028; bh=G9uUVxcwg896ErrtCgwVG302eK7JRTkVJ+j4xMVC+vg=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=eznOcIo8egi8boU6RICtnCqZ+FQiwjyY9iZhupNyQfNn71EdPfe2V9MXnQtMpN+U4 7KBi9dPHENM0SO9Pq9WXSukEaIXcq1ZitrHkKbGzxtQpz1F8vG4OYsooTbkvj5Tqva q1D5JKZqPySjBXbtUtxFUJbbAe2nnImngCYpm9Qw= X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 6084A3858C42 for <newlib@sourceware.org>; Mon, 14 Jul 2025 02:43:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6084A3858C42 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6084A3858C42 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1752461003; cv=none; b=QbDBi7nKtZ1ukdpl7S5zShTgLK/b0w2SWniO2VVqlQVGsNsMWC1U0N1lDSlW77dyvwbCIfa+IvJJ5wYEX7FyZec/hrEEn/nUVwQH2W/Ql8UOL1jtbRdx85OQSPWr9Y/fKsf/l/k7k6EPcsv08t+M4zg7ccMlkR7PZSsqQnkJR9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1752461003; c=relaxed/simple; bh=DsMk0Qe5apyTiE/BOw9S/gNSgCQnoPCK+LAzo8SPawo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=YdYv1PSseoaO/+shSkck540yZWDs/EivV02nm3X8U8zv9V/dkFulwKms/caYcNXug26QcHt11cOmHnLCWGsKyv8PKxXAzvC2CLoA4uCSAU6uexUv5E7X6v1jOYswXdcLqKfyJvRAPY3P85qEFpLQKPgwj89G7F8iws5dXwNqAvc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6084A3858C42 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-748d982e92cso2392421b3a.1 for <newlib@sourceware.org>; Sun, 13 Jul 2025 19:43:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752461002; x=1753065802; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=G9uUVxcwg896ErrtCgwVG302eK7JRTkVJ+j4xMVC+vg=; b=AjzPtKDFcIEvt8+Y7E7Xl2yh3SMH0+ob42wFUDhgwCYmEy5xRfMgtL7JGni8fiEy2F CdZll71RBe5a1Ukjxi4V4pD2ctmbrW6swfqCGvoe/BPJF8Q9Zc+dUY7mC2TSWnbvd0dG PoghiZYCbUE8IS2xvwr3LjJmULVkF1Hv4/yWZ/YVSDAjei2yH/JPGR3xvIgIUVfmdAqF CbjgCdByi1zTFWVOrwZRZ2wI6qeYmJfsoXnwJLyqfVmCjfyyM3NPrLK7JTBLKhTde800 HUraisdq87J7Bm3XcMeFiKtZ1aDe6RiJJohyRL2QMfYsSHEOjmXGMczKlopVBxfXrOG/ JaRA== X-Gm-Message-State: AOJu0YwH5jOJfHK+dmIGSCFMlQXkMXBAZ0qIGc+wlyMhs63ECAjr+/8d KBYQ8ATcHFOzLySRT5JnsZCa3PPp+z0DH2OpvKsTarVmw8pMz0omyw4n++A0D9Gg X-Gm-Gg: ASbGncthhMIeQRhqwdTz5K8lzviOEd8+6GOYAQmMA9u+R+xlGSpwmhdI2chpx1nRB6+ Z4MSwhjBMPkpWS3LPpjhR1YgIruVJSMxptCT1u+EHMvSeqb4vdx4iVJtbsZrxWt3mkyi8A7TyNh k/bunUAhEAjWl/x6Y72FbZtoSlzn/aXVJnf7tJw6/vO1dPj4cE4AgvCKUaC0nZj7GGcMy8P05Pn klEMYRnt7wPke84qKYUyiR6ZscNK67fBXpcaWNUmPpb3tWL6QwrM7Bo11emLHITqeCN2tysLdxN gzOrUA/ACU73dGHrlxXvXkXZEwnyO2q/Yy6pf6HqqapaGX7q6kjRN/Luzsbhhx1phFtkV/P5IP6 C+oUMab1IvLiGFLZHi9oAZ8KVqISuPA85Z73vipfZvpbcSLdL79vWMDluys4= X-Google-Smtp-Source: AGHT+IHL8TDBbsRmn3Fh6MMfS0mkkKSgciKUhPwXKoQ3CN5q0v8H9PI+OJnE+sw30E+q9E1uzKlyoQ== X-Received: by 2002:a05:6a21:918a:b0:206:a9bd:a3a3 with SMTP id adf61e73a8af0-2311fd02f84mr23037347637.24.1752461001906; Sun, 13 Jul 2025 19:43:21 -0700 (PDT) Received: from VIVOBOOK-K3605ZU.mshome.net ([117.231.224.161]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74eb9f1d328sm9764201b3a.94.2025.07.13.19.43.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Jul 2025 19:43:21 -0700 (PDT) To: newlib@sourceware.org Cc: Arijit Kumar Das <arijitkdgit.official@gmail.com> Subject: [PATCH] nvptx: Add _ssize_t as _READ_WRITE_RETURN_TYPE in newlib/libc/include/sys/config.h Date: Mon, 14 Jul 2025 08:11:41 +0530 Message-Id: <20250714024141.99939-1-arijitkdgit.official@gmail.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list <newlib.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/newlib>, <mailto:newlib-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/newlib/> List-Post: <mailto:newlib@sourceware.org> List-Help: <mailto:newlib-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/newlib>, <mailto:newlib-request@sourceware.org?subject=subscribe> From: Arijit Kumar Das via Newlib <newlib@sourceware.org> Reply-To: Arijit Kumar Das <arijitkdgit.official@gmail.com> Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
nvptx: Add _ssize_t as _READ_WRITE_RETURN_TYPE in newlib/libc/include/sys/config.h
|
|
Commit Message
Arijit Kumar Das
July 14, 2025, 2:41 a.m. UTC
Signed-off-by: Arijit Kumar Das <arijitkdgit.official@gmail.com>
---
newlib/libc/include/sys/config.h | 4 ++++
1 file changed, 4 insertions(+)
Comments
Hi Arijit! Thanks for looking into this! On 2025-07-14T08:11:41+0530, Arijit Kumar Das via Newlib <newlib@sourceware.org> wrote: > --- a/newlib/libc/include/sys/config.h > +++ b/newlib/libc/include/sys/config.h > @@ -12,6 +12,10 @@ > #define __DYNAMIC_REENT__ > #endif > > +#ifdef __nvptx__ > +#define _READ_WRITE_RETURN_TYPE _ssize_t > +#endif > + > /* exceptions first */ > #if defined(__H8500__) || defined(__W65__) > #define __SMALL_BITFIELDS I did wonder why placing this new '#define' here is a good choice -- but then, I've just looked at the current 'config.h' file, and found that placement of most of its content appears to be rather disorganized, so this placement here indeed should be as good as (almost) any other. (We shall of course be happy to hear from the newlib maintainers, if they've got any better advice.) But: won't that change in isolation break the build, or at least warn, given that we've still got 'newlib/libc/machine/nvptx/misc.c': int read(int fd, void *buf, size_t count) { ..., that is, 'int' instead of the desire 'ssize_t' return type? In 'newlib/libc/machine/nvptx/write.c' we have: _READ_WRITE_RETURN_TYPE write (int fd, const void *buf, size_t count) { Apparently, there isn't any diagnostic about the 'int' vs. 'ssize_t' for 'read', but I suggest that you change the return types of both 'read' and 'write' to the actual type, 'ssize_t'. (Actually, I don't see any '-W[...]' flags get used for an combined-tree GCC/newlib build, huh...) Another thing I've now noticed: nvptx' 'read' and 'write' implementations correctly use 'size_t count' (see cited above) -- but in 'config.h', as far as I can tell, we use the default 'int': /* Define `count' parameter of read/write routines. In POSIX, the `count' parameter is "size_t" but legacy newlib code has been using "int" for some time. If not specified, "int" is defaulted. */ #ifndef _READ_WRITE_BUFSIZE_TYPE #define _READ_WRITE_BUFSIZE_TYPE int #endif I suggest that for nvptx, next to your new '_READ_WRITE_RETURN_TYPE', you also add '#define _READ_WRITE_BUFSIZE_TYPE __size_t' (double underscore, per 'newlib/libc/include/sys/_types.h'), what do you think? (I'm slightly confused, as no configuration apart from Cygwin, 'winsup/cygwin/include/cygwin/config.h', appears to be doing this, but it still seems the right thing to do?) Make that either an additional commit, or as part of this one, as you like. I'll meanwhile test all this, too. Grüße Thomas
Hi Thomas! Sorry for the late response. I had seen your email earlier yesterday, but thought of replying after I got back to my laptop (which I didn't, until today). And for some reason, Slack fails to connect from the mobile app (could be an ISP issue because I can connect from my laptop) so I couldn't respond from my phone. > I did wonder why placing this new '#define' here is a good choice -- but > then, I've just looked at the current 'config.h' file, and found that > placement of most of its content appears to be rather disorganized, so > this placement here indeed should be as good as (almost) any other. > (We shall of course be happy to hear from the newlib maintainers, if > they've got any better advice.) Yes, and I placed it there because the #define for __AMDGCN__ was just above that, and both are kind of related so mainly that's why. Moreover, __nvptx__ wasn't #define -d anywhere else so that location seemed plausible to me. I'd of course like to hear from the newlib maintainers, as you said. > But: won't that change in isolation break the build, or at least warn, > given that we've still got 'newlib/libc/machine/nvptx/misc.c': > > int > read(int fd, void *buf, size_t count) { > > ..., that is, 'int' instead of the desire 'ssize_t' return type? > > In 'newlib/libc/machine/nvptx/write.c' we have: > > _READ_WRITE_RETURN_TYPE write (int fd, const void *buf, size_t count) > { That's a very real possibility, and in fact after some speculation it's likely to occur since the commit does not change the return type of read() to _READ_WRITE_RETURN_TYPE (aka _ssize_t) whereas that's the one for write() in write.c. This causes both to have a different function signature, which will most definitely cause a CUDA error, if not a compile time error or warning, as per my earlier experience. > Apparently, there isn't any diagnostic about the 'int' vs. 'ssize_t' for > 'read', but I suggest that you change the return types of both 'read' and > 'write' to the actual type, 'ssize_t'. (Actually, I don't see any > '-W[...]' flags get used for an combined-tree GCC/newlib build, huh...) Okay, so I change it directly to ssize_t instead of _ssize_t? (Actually, I followed the convention of the other #define -s for _READ_WRITE_RETURN_TYPE from config.h). > Another thing I've now noticed: nvptx' 'read' and 'write' implementations > correctly use 'size_t count' (see cited above) -- but in 'config.h', as > far as I can tell, we use the default 'int': > > /* Define `count' parameter of read/write routines. In POSIX, the `count' > parameter is "size_t" but legacy newlib code has been using "int" for some > time. If not specified, "int" is defaulted. */ > #ifndef _READ_WRITE_BUFSIZE_TYPE > #define _READ_WRITE_BUFSIZE_TYPE int > #endif > > I suggest that for nvptx, next to your new '_READ_WRITE_RETURN_TYPE', you > also add '#define _READ_WRITE_BUFSIZE_TYPE __size_t' (double underscore, > per 'newlib/libc/include/sys/_types.h'), what do you think? > (I'm slightly confused, as no configuration apart from Cygwin, > 'winsup/cygwin/include/cygwin/config.h', appears to be doing this, but it > still seems the right thing to do?) Yeah, __size_t is indeed correct and I verified that from _types.h as you said. And I'll be incorporating this new #define too, and update count as in read() and write(). > Make that either an additional commit, or as part of this one, as you > like. Alright. Another thing which I was thinking is that, now that my work in newlib/libc/machine/nvptx/misc.c is functional (albeit, not optimized or following some expected standards per se) could I add this one too, in my commit? That doesn't break the build, adds some functionality, and I can still continue working on it and sending my commits without breaking stuff. If the above idea isn't possible at the moment, I can also just update the function signatures in newlib/libc/machine/nvptx/misc.c and newlib/libc/machine/nvptx/write.c and leave everything as it is. Let me know what's your take on the above. Best regards, Arijit
Hi Arijit! On 2025-07-15T14:09:03+0530, Arijit Kumar Das via Newlib <newlib@sourceware.org> wrote: >> But: won't that change in isolation break the build, or at least warn, >> given that we've still got 'newlib/libc/machine/nvptx/misc.c': >> >> int >> read(int fd, void *buf, size_t count) { >> >> ..., that is, 'int' instead of the desire 'ssize_t' return type? >> >> In 'newlib/libc/machine/nvptx/write.c' we have: >> >> _READ_WRITE_RETURN_TYPE write (int fd, const void *buf, size_t count) >> { > > That's a very real possibility, and in fact after some speculation > it's likely to occur since the > commit does not change the return type of read() to _READ_WRITE_RETURN_TYPE (aka > _ssize_t) whereas that's the one for write() in write.c. This causes > both to have a different > function signature, which will most definitely cause a CUDA error, if > not a compile time > error or warning, as per my earlier experience. > >> Apparently, there isn't any diagnostic about the 'int' vs. 'ssize_t' for >> 'read', but I suggest that you change the return types of both 'read' and >> 'write' to the actual type, 'ssize_t'. (Actually, I don't see any >> '-W[...]' flags get used for an combined-tree GCC/newlib build, huh...) > > Okay, so I change it directly to ssize_t instead of _ssize_t? > (Actually, I followed the convention > of the other #define -s for _READ_WRITE_RETURN_TYPE from config.h). I've not researched all the context/history here, but usually it goes similar to this: Generic code (for example: 'newlib/libc/include/sys/config.h', 'newlib/libc/stdio/stdio.c'), which has to work for all possible newlib targets/configurations, is often using some indirections/abstractions (for example: '_ssize_t' corresponding to the actual 'ssize_t', or '_READ_WRITE_RETURN_TYPE' corresponding to the actual 'read', 'write' return type), so that certain targets/configurations are able to "fix up things" if necessary. In contrast, the target-specific implementations (for example: 'newlib/libc/machine/nvptx/write.c') can directly use the actual types (for example: 'ssize_t' instead of '_ssize_t' or '_READ_WRITE_RETURN_TYPE'); they (mostly) don't need the indirections/abstractions, as they define (implement) code for the actual target/configuration. > Another thing which I was thinking is that, now that my work in > newlib/libc/machine/nvptx/misc.c > is functional (albeit, not optimized or following some expected > standards per se) could I add this > one too, in my commit? That doesn't break the build, adds some > functionality, and I can still > continue working on it and sending my commits without breaking stuff. :-) I understand you're eager to get your new code out there, but let's first sort out the '_READ_WRITE_RETURN_TYPE', '_READ_WRITE_BUFSIZE_TYPE' thing, and then continue to work on the new code some more, test it properly (via the GCC test suite, for example), and clean it up, etc. We'll get there. :-) Grüße Thomas
Hi Thomas! On Wed, Jul 16, 2025 at 1:17 PM Thomas Schwinge <tschwinge@baylibre.com> wrote: > > Okay, so I change it directly to ssize_t instead of _ssize_t? > > (Actually, I followed the convention > > of the other #define -s for _READ_WRITE_RETURN_TYPE from config.h). > > I've not researched all the context/history here, but usually it goes > similar to this: > > Generic code (for example: 'newlib/libc/include/sys/config.h', > 'newlib/libc/stdio/stdio.c'), which has to work for all possible newlib > targets/configurations, is often using some indirections/abstractions > (for example: '_ssize_t' corresponding to the actual 'ssize_t', or > '_READ_WRITE_RETURN_TYPE' corresponding to the actual 'read', 'write' > return type), so that certain targets/configurations are able to "fix up > things" if necessary. > > In contrast, the target-specific implementations (for example: > 'newlib/libc/machine/nvptx/write.c') can directly use the actual types > (for example: 'ssize_t' instead of '_ssize_t' or > '_READ_WRITE_RETURN_TYPE'); they (mostly) don't need the > indirections/abstractions, as they define (implement) code for the actual > target/configuration. > Got it! I'll be sending the patch soon. Here's what I'll add to config.h: #ifdef __nvptx__ #define _READ_WRITE_RETURN_TYPE ssize_t #define _READ_WRITE_BUFSIZE_TYPE size_t Does that look good? > > > Another thing which I was thinking is that, now that my work in > > newlib/libc/machine/nvptx/misc.c > > is functional (albeit, not optimized or following some expected > > standards per se) could I add this > > one too, in my commit? That doesn't break the build, adds some > > functionality, and I can still > > continue working on it and sending my commits without breaking stuff. > > :-) I understand you're eager to get your new code out there, but let's > first sort out the '_READ_WRITE_RETURN_TYPE', '_READ_WRITE_BUFSIZE_TYPE' > thing, and then continue to work on the new code some more, test it > properly (via the GCC test suite, for example), and clean it up, etc. > We'll get there. :-) > Alright! But can I also update the function signatures in write.c and misc.c to _READ_WRITE_RETURN_TYPE and _READ_WRITE_BUFSIZE_TYPE wherever applicable and leave the rest of the things as it is (i.e. not include my filesystem code yet)? Otherwise the function signatures for read() and write() become different since write() uses_READ_WRITE_RETURN_TYPE and read() uses int which can cause a run time CUDA error. Let me know what do you think and I'll be glad to send my first commit to be merged :-) Best regards, Arijit
Hi Arijit! On 2025-07-16T22:45:39+0530, Arijit Kumar Das <arijitkdgit.official@gmail.com> wrote: > On Wed, Jul 16, 2025 at 1:17 PM Thomas Schwinge <tschwinge@baylibre.com> wrote: >> Generic code (for example: 'newlib/libc/include/sys/config.h', >> 'newlib/libc/stdio/stdio.c'), which has to work for all possible newlib >> targets/configurations, is often using some indirections/abstractions >> (for example: '_ssize_t' corresponding to the actual 'ssize_t', or >> '_READ_WRITE_RETURN_TYPE' corresponding to the actual 'read', 'write' >> return type), so that certain targets/configurations are able to "fix up >> things" if necessary. >> >> In contrast, the target-specific implementations (for example: >> 'newlib/libc/machine/nvptx/write.c') can directly use the actual types >> (for example: 'ssize_t' instead of '_ssize_t' or >> '_READ_WRITE_RETURN_TYPE'); they (mostly) don't need the >> indirections/abstractions, as they define (implement) code for the actual >> target/configuration. >> > > Got it! I'll be sending the patch soon. Here's what I'll add to config.h: > > #ifdef __nvptx__ > #define _READ_WRITE_RETURN_TYPE ssize_t > #define _READ_WRITE_BUFSIZE_TYPE size_t No, in the (generic) 'newlib/libc/include/sys/config.h', you should use '_ssize_t' and '__size_t'. It won't make a difference in practice, but for consistency. >> [...] let's >> first sort out the '_READ_WRITE_RETURN_TYPE', '_READ_WRITE_BUFSIZE_TYPE' >> thing, [...] > > Alright! But can I also update the function signatures in write.c and misc.c to > _READ_WRITE_RETURN_TYPE and _READ_WRITE_BUFSIZE_TYPE > wherever applicable and leave the rest of the things as it is (i.e. not include > my filesystem code yet)? Do not include your new code yet, just update: > Otherwise the function signatures for read() > and write() > become different since write() uses_READ_WRITE_RETURN_TYPE and > read() uses int which can cause a run time CUDA error. ... these to 'ssize_t' return type. Grüße Thomas
Hi Thomas! Here's the final commit. I hope it's okay :-) Best regards, Arijit 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() - 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). 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(-) 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..329804f88 100644 --- a/newlib/libc/machine/nvptx/misc.c +++ b/newlib/libc/machine/nvptx/misc.c @@ -62,8 +62,8 @@ open (const char *pathname, int flags, ...) { return -1; } -int -read(int fd, void *buf, size_t count) { +_READ_WRITE_RETURN_TYPE +read(int fd, void *buf, _READ_WRITE_BUFSIZE_TYPE count) { return 0; } diff --git a/newlib/libc/machine/nvptx/write.c b/newlib/libc/machine/nvptx/write.c index 0544dd05e..49fb65944 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) +_READ_WRITE_RETURN_TYPE +write (int fd, const void *buf, _READ_WRITE_BUFSIZE_TYPE count) { size_t i; char *b = (char *)buf;
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
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;
Hi! On 2025-07-17T17:00:59+0530, Arijit Kumar Das <arijitkdgit.official@gmail.com> wrote: > Here's the updated version and (hopefully) this one's done as you instructed :-) Pushed to main branch commit 5d8c71af5e0fa5cdc99d9f741624920e34756418 "nvptx: Change 'read' and 'write' to 'ssize_t' return type". Arijit, congratulations to your first commit in newlib! :-D Grüße Thomas > 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
diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h index 4c9acc55c..0ee9e672d 100644 --- a/newlib/libc/include/sys/config.h +++ b/newlib/libc/include/sys/config.h @@ -12,6 +12,10 @@ #define __DYNAMIC_REENT__ #endif +#ifdef __nvptx__ +#define _READ_WRITE_RETURN_TYPE _ssize_t +#endif + /* exceptions first */ #if defined(__H8500__) || defined(__W65__) #define __SMALL_BITFIELDS