[uclibc-ng-devel] _FILE_OFFSET_BITS=64 and preadv/pwritev prototypes

Message ID CAKo4hF+R0m+gGjk+P36tXN3ztiFr+vRsXXwe3bDPkM2zPY62+g@mail.gmail.com
State New
Headers show
Series
  • [uclibc-ng-devel] _FILE_OFFSET_BITS=64 and preadv/pwritev prototypes
Related show

Commit Message

Sergey Korolev June 10, 2018, 8:28 p.m.
As preadv and pwritev accept off_t type the prototypes should be declared
as follows

extern ssize_t preadv (int __fd, const struct iovec *__iovec, int __count,
                       off_t __offset) __wur;


extern ssize_t pwritev (int __fd, const struct iovec *__iovec, int __count,
                        off_t __offset) __wur;

to take into account _FILE_OFFSET_BITS=64 define.

I am not sure but probably it is better to redeclare these prototypes
by analogy with sendfile using __REDIRECT_NTH.

Comments

Waldemar Brodkorb June 11, 2018, 3:14 a.m. | #1
Hi Sergey,
what does the patch fixes?
Compiler warnings? Runtime issues? ...

best regards
 Waldemar 

> Am 10.06.2018 um 22:28 schrieb Sergey Korolev <s.korolev@ndmsystems.com>:
> 
> As preadv and pwritev accept off_t type the prototypes should be declared as follows
> 
> extern ssize_t preadv (int __fd, const struct iovec *__iovec, int __count,
>                        off_t __offset) __wur;
>                                                                               
> extern ssize_t pwritev (int __fd, const struct iovec *__iovec, int __count,
>                         off_t __offset) __wur;
> 
> to take into account _FILE_OFFSET_BITS=64 define.
> 
> I am not sure but probably it is better to redeclare these prototypes
> by analogy with sendfile using __REDIRECT_NTH.
> <Fix-prototypes-for-preadv-pwritev.patch>
> _______________________________________________
> devel mailing list
> devel@uclibc-ng.org
> https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
Sergey Korolev June 11, 2018, 8:57 a.m. | #2
This patch fixes a size of 4th argument in a prototype
in case of _FILE_OFFSET_BITS=64 to match an implementation
on 32 bit architectures

#ifdef __NR_pwritev
ssize_t
pwritev (int fd, const struct iovec *vector, int count, off_t offset)
{
  unsigned long pos_l, pos_h;

  pos_h = (unsigned long)((long long)offset >> 32);
  pos_l = (unsigned long)((long long)offset);

  return INLINE_SYSCALL (pwritev, 5, fd, vector, count, pos_l, pos_h);
}
#endif

A simple test program compiled with gcc 7.3 and -Wconversion

#include <stdio.h>
#include <stdint.h>
#include <sys/uio.h>

int main()
{
    const off_t ofs = INT64_MAX;

    pwritev(0, NULL, 0, ofs);

    return 0;
}

gives a warning

test.c:9:22: warning: conversion to '__off_t {aka long int}' from 'off_t
{aka const long long int}' may alter its value [-Wconversion]
  pwritev(0, NULL, 0, ofs);
                      ^~~

Without the patch the prototype tells a compiler to pass only 32 bits
to preadv/pwritev definitions that gives a corrupted offset value.

On Mon, Jun 11, 2018 at 6:14 AM, Waldemar Brodkorb <wbx@uclibc-ng.org>
wrote:

> Hi Sergey,
> what does the patch fixes?
> Compiler warnings? Runtime issues? ...
>
> best regards
>  Waldemar
>
> > Am 10.06.2018 um 22:28 schrieb Sergey Korolev <s.korolev@ndmsystems.com
> >:
> >
> > As preadv and pwritev accept off_t type the prototypes should be
> declared as follows
> >
> > extern ssize_t preadv (int __fd, const struct iovec *__iovec, int
> __count,
> >                        off_t __offset) __wur;
> >
>
> > extern ssize_t pwritev (int __fd, const struct iovec *__iovec, int
> __count,
> >                         off_t __offset) __wur;
> >
> > to take into account _FILE_OFFSET_BITS=64 define.
> >
> > I am not sure but probably it is better to redeclare these prototypes
> > by analogy with sendfile using __REDIRECT_NTH.
> > <Fix-prototypes-for-preadv-pwritev.patch>
> > _______________________________________________
> > devel mailing list
> > devel@uclibc-ng.org
> > https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel
>
>
<div dir="ltr">This patch fixes a size of 4th argument in a prototype<div>in case of <span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">_FILE_OFFSET_BITS=64 </span>to match an implementation</div><div>on 32 bit architectures<div><div><br></div><div><div>#ifdef __NR_pwritev</div><div>ssize_t</div><div>pwritev (int fd, const struct iovec *vector, int count, off_t offset)</div><div>{</div><div>  unsigned long pos_l, pos_h;</div><div><br></div><div>  pos_h = (unsigned long)((long long)offset &gt;&gt; 32);</div><div>  pos_l = (unsigned long)((long long)offset);</div><div><br></div><div>  return INLINE_SYSCALL (pwritev, 5, fd, vector, count, pos_l, pos_h);</div><div>}</div><div>#endif</div></div><div><br></div></div></div><div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">A simple test program compiled with gcc 7.3 and -Wconversion</div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="text-decoration-style:initial;text-decoration-color:initial"><div><div>#include &lt;stdio.h&gt;</div><div>#include &lt;stdint.h&gt;</div><div>#include &lt;sys/uio.h&gt;</div><div><br></div><div>int main()</div><div>{</div><div>    const off_t ofs = INT64_MAX;</div><div><br></div><div>    pwritev(0, NULL, 0, ofs);</div><div><br></div><div>    return 0;</div><div>}</div></div><div><br></div></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">gives a warning</div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="text-decoration-style:initial;text-decoration-color:initial"><div>test.c:9:22: warning: conversion to &#39;__off_t {aka long int}&#39; from &#39;off_t {aka const long long int}&#39; may alter its value [-Wconversion]</div><div>  pwritev(0, NULL, 0, ofs);</div><div>                      ^~~</div></div></div><div><br></div><div>Without the patch the prototype tells a compiler to pass only 32 bits</div><div>to preadv/pwritev definitions that gives a corrupted offset value.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 11, 2018 at 6:14 AM, Waldemar Brodkorb <span dir="ltr">&lt;<a href="mailto:wbx@uclibc-ng.org" target="_blank">wbx@uclibc-ng.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Sergey,<br>
what does the patch fixes?<br>
Compiler warnings? Runtime issues? ...<br>
<br>
best regards<br>
 Waldemar <br>
<div><div class="h5"><br>
&gt; Am 10.06.2018 um 22:28 schrieb Sergey Korolev &lt;<a href="mailto:s.korolev@ndmsystems.com">s.korolev@ndmsystems.com</a>&gt;:<br>
&gt; <br>
&gt; As preadv and pwritev accept off_t type the prototypes should be declared as follows<br>
&gt; <br>
&gt; extern ssize_t preadv (int __fd, const struct iovec *__iovec, int __count,<br>
&gt;                        off_t __offset) __wur;<br>
&gt;                                                                               <br>
&gt; extern ssize_t pwritev (int __fd, const struct iovec *__iovec, int __count,<br>
&gt;                         off_t __offset) __wur;<br>
&gt; <br>
&gt; to take into account _FILE_OFFSET_BITS=64 define.<br>
&gt; <br>
&gt; I am not sure but probably it is better to redeclare these prototypes<br>
&gt; by analogy with sendfile using __REDIRECT_NTH.<br>
</div></div>&gt; &lt;Fix-prototypes-for-preadv-<wbr>pwritev.patch&gt;<br>
&gt; ______________________________<wbr>_________________<br>
&gt; devel mailing list<br>
&gt; <a href="mailto:devel@uclibc-ng.org">devel@uclibc-ng.org</a><br>
&gt; <a href="https://mailman.uclibc-ng.org/cgi-bin/mailman/listinfo/devel" rel="noreferrer" target="_blank">https://mailman.uclibc-ng.org/<wbr>cgi-bin/mailman/listinfo/devel</a><br>
<br>
</blockquote></div><br></div>

Patch

From 12347ece4b48c81a1db80eec660fc7ec7c542c19 Mon Sep 17 00:00:00 2001
From: Vlad Starodubtsev <v.starodubtsev@ndmsystems.com>
Date: Thu, 26 Oct 2017 17:22:33 +0300
Subject: [PATCH] Fix prototypes for preadv pwritev.

---
 include/sys/uio.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/sys/uio.h b/include/sys/uio.h
index 78341ed40..aa766f9b1 100644
--- a/include/sys/uio.h
+++ b/include/sys/uio.h
@@ -59,7 +59,7 @@  extern ssize_t writev (int __fd, const struct iovec *__iovec, int __count);
    This function is a cancellation point and therefore not marked with
    __THROW.  */
 extern ssize_t preadv (int __fd, const struct iovec *__iovec, int __count,
-		       __off_t __offset) __wur;
+		       off_t __offset) __wur;
 
 /* Write data pointed by the buffers described by IOVEC, which is a
    vector of COUNT 'struct iovec's, to file descriptor FD at the given
@@ -71,7 +71,7 @@  extern ssize_t preadv (int __fd, const struct iovec *__iovec, int __count,
    This function is a cancellation point and therefore not marked with
    __THROW.  */
 extern ssize_t pwritev (int __fd, const struct iovec *__iovec, int __count,
-			__off_t __offset) __wur;
+			off_t __offset) __wur;
 #endif	/* Use misc.  */
 
 __END_DECLS
-- 
2.17.1