• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <sys/uio.h>
30 
31 // System calls we need.
32 extern "C" int __preadv64(int, const struct iovec*, int, long, long);
33 extern "C" int __preadv64v2(int, const struct iovec*, int, long, long, int);
34 extern "C" int __pwritev64(int, const struct iovec*, int, long, long);
35 extern "C" int __pwritev64v2(int, const struct iovec*, int, long, long, int);
36 
37 // There is no 32-bit off_t preadv/pwritev (even on LP32).
38 // To avoid 32-bit ABI issues about which register pairs you're allowed
39 // to pass 64-bit values in, the kernel just takes two `long` arguments --
40 // which are int32_t for LP32, remember -- and stitches them together.
41 // It even does this for LP64, taking a second unused always-zero `long`.
42 // (The first long was int64_t, which is the same as off64_t.)
43 // The pair is split lo-hi (not hi-lo, as llseek is).
44 
preadv(int fd,const struct iovec * ios,int count,off_t offset)45 ssize_t preadv(int fd, const struct iovec* ios, int count, off_t offset) {
46   return preadv64(fd, ios, count, offset);
47 }
48 
preadv64(int fd,const struct iovec * ios,int count,off64_t offset)49 ssize_t preadv64(int fd, const struct iovec* ios, int count, off64_t offset) {
50 #if defined(__LP64__)
51   return __preadv64(fd, ios, count, offset, 0);
52 #else
53   return __preadv64(fd, ios, count, offset, offset >> 32);
54 #endif
55 }
56 
pwritev(int fd,const struct iovec * ios,int count,off_t offset)57 ssize_t pwritev(int fd, const struct iovec* ios, int count, off_t offset) {
58   return pwritev64(fd, ios, count, offset);
59 }
60 
pwritev64(int fd,const struct iovec * ios,int count,off64_t offset)61 ssize_t pwritev64(int fd, const struct iovec* ios, int count, off64_t offset) {
62 #if defined(__LP64__)
63   return __pwritev64(fd, ios, count, offset, 0);
64 #else
65   return __pwritev64(fd, ios, count, offset, offset >> 32);
66 #endif
67 }
68 
preadv2(int fd,const struct iovec * ios,int count,off_t offset,int flags)69 ssize_t preadv2(int fd, const struct iovec* ios, int count, off_t offset, int flags) {
70   return preadv64v2(fd, ios, count, offset, flags);
71 }
72 
preadv64v2(int fd,const struct iovec * ios,int count,off64_t offset,int flags)73 ssize_t preadv64v2(int fd, const struct iovec* ios, int count, off64_t offset, int flags) {
74 #if defined(__LP64__)
75   return __preadv64v2(fd, ios, count, offset, 0, flags);
76 #else
77   return __preadv64v2(fd, ios, count, offset, offset >> 32, flags);
78 #endif
79 }
80 
pwritev2(int fd,const struct iovec * ios,int count,off_t offset,int flags)81 ssize_t pwritev2(int fd, const struct iovec* ios, int count, off_t offset, int flags) {
82   return pwritev64v2(fd, ios, count, offset, flags);
83 }
84 
pwritev64v2(int fd,const struct iovec * ios,int count,off64_t offset,int flags)85 ssize_t pwritev64v2(int fd, const struct iovec* ios, int count, off64_t offset, int flags) {
86 #if defined(__LP64__)
87   return __pwritev64v2(fd, ios, count, offset, 0, flags);
88 #else
89   return __pwritev64v2(fd, ios, count, offset, offset >> 32, flags);
90 #endif
91 }
92