]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/ukfile: API: Change iovec length to size_t
authorAndrei Tatar <andrei@unikraft.io>
Thu, 6 Feb 2025 12:49:13 +0000 (13:49 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Tue, 11 Feb 2025 15:42:28 +0000 (15:42 +0000)
Previously the ukfile API would take the size of a passed iovec as a
signed int, a design oversight copied over from the binary syscall API.
Negative iovec lengths make no sense and should not be exposed by our
internal API.
This change makes iovec lengths unsigned size_t for ukfiles.
The posix-socket socket ops API is similarly changed to use size_t.
External socket implementations will need updating.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1580

13 files changed:
lib/posix-eventfd/eventfd.c
lib/posix-fdio/fdio.c
lib/posix-pipe/pipe.c
lib/posix-socket/include/uk/socket_driver.h
lib/posix-socket/socket.c
lib/posix-timerfd/timerfd.c
lib/posix-tty/pseudo.c
lib/posix-tty/serial.c
lib/posix-unixsocket/unixsock.c
lib/ukfile/file-nops.c
lib/ukfile/include/uk/file.h
lib/ukfile/include/uk/file/iovutil.h
lib/ukfile/include/uk/file/nops.h

index 078590bf498d98bfe3f515551d882e603e061939..ef97acfa2d3ddae0229aef22d453e4f543ee43b6 100644 (file)
@@ -35,7 +35,7 @@ struct evfd_alloc {
 
 
 static ssize_t evfd_read(const struct uk_file *f,
-                        const struct iovec *iov, int iovcnt,
+                        const struct iovec *iov, size_t iovcnt,
                         size_t off, long flags __unused)
 {
        int semaphore;
@@ -75,7 +75,7 @@ static ssize_t evfd_read(const struct uk_file *f,
 
 
 static ssize_t evfd_write(const struct uk_file *f,
-                         const struct iovec *iov, int iovcnt,
+                         const struct iovec *iov, size_t iovcnt,
                          size_t off, long flags __unused)
 {
        uint64_t add;
index 91222156425ecc27f5035c3a027bab8370bb6624..dc8b2a6736410f28305856780ac3308647d0f4ad 100644 (file)
@@ -77,7 +77,7 @@ ssize_t uk_sys_preadv(struct uk_ofile *of, const struct iovec *iov, int iovcnt,
        for (;;) {
                if (iolock)
                        uk_file_rlock(f);
-               r = uk_file_read(f, iov, iovcnt, offset, flags);
+               r = uk_file_read(f, iov, (size_t)iovcnt, offset, flags);
                if (iolock)
                        uk_file_runlock(f);
                if (!_SHOULD_BLOCK(r, mode))
@@ -124,7 +124,7 @@ ssize_t uk_sys_readv(struct uk_ofile *of, const struct iovec *iov, int iovcnt)
 
                if (iolock)
                        uk_file_rlock(f);
-               r = uk_file_read(f, iov, iovcnt, off, flags);
+               r = uk_file_read(f, iov, (size_t)iovcnt, off, flags);
                if (iolock)
                        uk_file_runlock(f);
                if (!_SHOULD_BLOCK(r, mode))
@@ -192,7 +192,7 @@ ssize_t uk_sys_preadv2(struct uk_ofile *of, const struct iovec *iov, int iovcnt,
 
                if (iolock)
                        uk_file_rlock(f);
-               r = uk_file_read(f, iov, iovcnt, off, xflags);
+               r = uk_file_read(f, iov, (size_t)iovcnt, off, xflags);
                if (iolock)
                        uk_file_runlock(f);
                if (!_SHOULD_BLOCK(r, mode))
@@ -237,7 +237,7 @@ ssize_t uk_sys_pwritev(struct uk_ofile *of, const struct iovec *iov, int iovcnt,
        for (;;) {
                if (iolock)
                        uk_file_wlock(f);
-               r = uk_file_write(f, iov, iovcnt, offset, flags);
+               r = uk_file_write(f, iov, (size_t)iovcnt, offset, flags);
                if (iolock)
                        uk_file_wunlock(f);
                if (!_SHOULD_BLOCK(r, mode))
@@ -292,7 +292,7 @@ ssize_t uk_sys_writev(struct uk_ofile *of, const struct iovec *iov, int iovcnt)
                }
 
                if (likely(off >= 0))
-                       r = uk_file_write(f, iov, iovcnt, off, flags);
+                       r = uk_file_write(f, iov, (size_t)iovcnt, off, flags);
                else
                        r = off;
 
@@ -372,7 +372,7 @@ ssize_t uk_sys_pwritev2(struct uk_ofile *of, const struct iovec *iov,
                }
 
                if (likely(off >= 0))
-                       r = uk_file_write(f, iov, iovcnt, off, xflags);
+                       r = uk_file_write(f, iov, (size_t)iovcnt, off, xflags);
                else
                        r = off;
 
index 3b06bc9704a5440502b8e661354cdfd7c2841645..dc8006600ea2fd88d1ac09e931cf4c30c201218c 100644 (file)
@@ -127,11 +127,11 @@ static void pipebuf_iovwrite(char *buf, pipeidx head,
                _pipebuf_write(buf, head, (const char *)iov[i].iov_base, n);
 }
 
-static ssize_t _iovsz(const struct iovec *iov, int iovcnt)
+static ssize_t _iovsz(const struct iovec *iov, size_t iovcnt)
 {
        size_t ret = 0;
 
-       for (int i = 0; i < iovcnt; i++)
+       for (size_t i = 0; i < iovcnt; i++)
                if (iov[i].iov_len) {
                        if (likely(iov[i].iov_base))
                                ret += iov[i].iov_len;
@@ -142,7 +142,7 @@ static ssize_t _iovsz(const struct iovec *iov, int iovcnt)
 }
 
 static ssize_t pipe_read(const struct uk_file *f,
-                        const struct iovec *iov, int iovcnt,
+                        const struct iovec *iov, size_t iovcnt,
                         size_t off, long flags __unused)
 {
        ssize_t toread;
@@ -230,7 +230,7 @@ static ssize_t pipe_read(const struct uk_file *f,
 }
 
 static ssize_t pipe_write(const struct uk_file *f,
-                         const struct iovec *iov, int iovcnt,
+                         const struct iovec *iov, size_t iovcnt,
                          size_t off, long flags)
 {
        struct pipe_node *d;
index 878e68bcbb86649883648a65ba7b91ae791e7958..b712b6d36f3aa63bee56c8764a6e1de2463f2057 100644 (file)
@@ -398,7 +398,7 @@ typedef void (*posix_socket_socketpair_post_func_t)(
  * @return The number of bytes written on success, -errno otherwise
  */
 typedef ssize_t (*posix_socket_write_func_t)(posix_sock *sock,
-               const struct iovec *iov, int iovcnt);
+               const struct iovec *iov, size_t iovcnt);
 
 /**
  * Read from a socket file descriptor.
@@ -411,7 +411,7 @@ typedef ssize_t (*posix_socket_write_func_t)(posix_sock *sock,
  * @return The number of bytes read on success, -errno otherwise
  */
 typedef ssize_t (*posix_socket_read_func_t)(posix_sock *sock,
-               const struct iovec *iov, int iovcnt);
+               const struct iovec *iov, size_t iovcnt);
 
 /**
  * Close the socket.
@@ -640,7 +640,7 @@ posix_socket_socketpair_post(struct posix_socket_driver *d,
 
 static inline ssize_t
 posix_socket_write(posix_sock *sock, const struct iovec *iov,
-                  int iovcnt)
+                  size_t iovcnt)
 {
        struct posix_socket_driver *d = posix_sock_get_driver(sock);
 
@@ -650,7 +650,7 @@ posix_socket_write(posix_sock *sock, const struct iovec *iov,
 
 static inline ssize_t
 posix_socket_read(posix_sock *sock, const struct iovec *iov,
-                 int iovcnt)
+                 size_t iovcnt)
 {
        struct posix_socket_driver *d = posix_sock_get_driver(sock);
 
index ccd43e0f03fe624e9c1f8f1ddbaea0166322eba6..641f88834a17efb1e806c569a0956aed9103754f 100644 (file)
@@ -93,7 +93,7 @@ static struct uk_ofile *socketfd_get(int fd)
 
 static ssize_t
 socket_read(const struct uk_file *sock,
-           const struct iovec *iov, int iovcnt,
+           const struct iovec *iov, size_t iovcnt,
            size_t off, long flags __unused)
 {
        ssize_t ret;
@@ -125,7 +125,7 @@ socket_read(const struct uk_file *sock,
 
 static ssize_t
 socket_write(const struct uk_file *sock,
-            const struct iovec *iov, int iovcnt,
+            const struct iovec *iov, size_t iovcnt,
             size_t off, long flags __unused)
 {
        ssize_t ret;
index 464a29dcb70dca9edd4623edd4679aaef8c3aa1d..e360c7fad85da8d392d83790976157f8dceed9a2 100644 (file)
@@ -129,7 +129,7 @@ static void _timerfd_set(struct timerfd_node *d, const struct itimerspec *set)
 /* Ops */
 
 static ssize_t timerfd_read(const struct uk_file *f,
-                           const struct iovec *iov, int iovcnt,
+                           const struct iovec *iov, size_t iovcnt,
                            size_t off, long flags __unused)
 {
        struct timerfd_node *d;
index d351e3f8c9ae91b351ce5a5adc096ca7ab1ebd10..29b19baf9d327568e8ea7dc33e4e031dcc042c06 100644 (file)
@@ -22,7 +22,8 @@ static const char VOID_VOLID[] = "void_vol";
 static const char ZERO_VOLID[] = "zero_vol";
 
 static ssize_t null_read(const struct uk_file *f __maybe_unused,
-                        const struct iovec *iov __unused, int iovcnt __unused,
+                        const struct iovec *iov __unused,
+                        size_t iovcnt __unused,
                         size_t off __unused, long flags __unused)
 {
        UK_ASSERT(f->vol == NULL_VOLID);
@@ -30,7 +31,8 @@ static ssize_t null_read(const struct uk_file *f __maybe_unused,
 }
 
 static ssize_t void_read(const struct uk_file *f __maybe_unused,
-                        const struct iovec *iov __unused, int iovcnt __unused,
+                        const struct iovec *iov __unused,
+                        size_t iovcnt __unused,
                         size_t off __unused, long flags __unused)
 {
        UK_ASSERT(f->vol == VOID_VOLID);
@@ -38,14 +40,14 @@ static ssize_t void_read(const struct uk_file *f __maybe_unused,
 }
 
 static ssize_t zero_read(const struct uk_file *f __maybe_unused,
-                        const struct iovec *iov, int iovcnt,
+                        const struct iovec *iov, size_t iovcnt,
                         size_t off __unused, long flags __unused)
 {
        ssize_t total = 0;
 
        UK_ASSERT(f->vol == ZERO_VOLID);
 
-       for (int i = 0; i < iovcnt; i++) {
+       for (size_t i = 0; i < iovcnt; i++) {
                if (unlikely(!iov[i].iov_base && iov[i].iov_len))
                        return -EFAULT;
                memset(iov[i].iov_base, 0, iov[i].iov_len);
@@ -55,7 +57,7 @@ static ssize_t zero_read(const struct uk_file *f __maybe_unused,
 }
 
 static ssize_t null_write(const struct uk_file *f __maybe_unused,
-                         const struct iovec *iov, int iovcnt,
+                         const struct iovec *iov, size_t iovcnt,
                          size_t off __unused, long flags __unused)
 {
        ssize_t total = 0;
@@ -63,7 +65,7 @@ static ssize_t null_write(const struct uk_file *f __maybe_unused,
        UK_ASSERT(f->vol == NULL_VOLID || f->vol == ZERO_VOLID ||
                  f->vol == VOID_VOLID);
 
-       for (int i = 0; i < iovcnt; i++)
+       for (size_t i = 0; i < iovcnt; i++)
                total += iov[i].iov_len;
        return total;
 }
index 00820ce4db8df39405828ecb15c8776687eb5b52..adc230738071968a20a10bef0533ab8f1245148a 100644 (file)
@@ -88,7 +88,7 @@ static inline __ssz _console_out(const char *buf, __sz len)
 }
 
 static ssize_t serial_read(const struct uk_file *f,
-                          const struct iovec *iov, int iovcnt,
+                          const struct iovec *iov, size_t iovcnt,
                           size_t off, long flags __unused)
 {
        ssize_t total = 0;
@@ -100,7 +100,7 @@ static ssize_t serial_read(const struct uk_file *f,
        if (!uk_file_poll_immediate(f, UKFD_POLLIN))
                return 0;
 
-       for (int i = 0; i < iovcnt; i++) {
+       for (size_t i = 0; i < iovcnt; i++) {
                char *buf = iov[i].iov_base;
                size_t len = iov[i].iov_len;
                char *last;
@@ -137,7 +137,7 @@ static ssize_t serial_read(const struct uk_file *f,
 }
 
 static ssize_t serial_write(const struct uk_file *f __maybe_unused,
-                           const struct iovec *iov, int iovcnt,
+                           const struct iovec *iov, size_t iovcnt,
                            size_t off, long flags __unused)
 {
        ssize_t total = 0;
@@ -146,7 +146,7 @@ static ssize_t serial_write(const struct uk_file *f __maybe_unused,
        if (unlikely(off))
                return -ESPIPE;
 
-       for (int i = 0; i < iovcnt; i++) {
+       for (size_t i = 0; i < iovcnt; i++) {
                char *buf = iov[i].iov_base;
                size_t len = iov[i].iov_len;
                int bytes_written;
index dd33bf13d077ceb2a3cec84e1d046b3317878aaf..91d3a81137b9d0e286e81acb5087c398e32561cd 100644 (file)
@@ -887,7 +887,7 @@ ssize_t unix_socket_sendto(posix_sock *file, const void *buf,
 
 static
 ssize_t unix_socket_read(posix_sock *file,
-                        const struct iovec *iov, int iovcnt)
+                        const struct iovec *iov, size_t iovcnt)
 {
        struct msghdr msg = {
                .msg_name = NULL,
@@ -903,7 +903,7 @@ ssize_t unix_socket_read(posix_sock *file,
 
 static
 ssize_t unix_socket_write(posix_sock *file,
-                         const struct iovec *iov, int iovcnt)
+                         const struct iovec *iov, size_t iovcnt)
 {
        struct msghdr msg = {
                .msg_name = NULL,
index 1109e7a3911447413e465e53ee5dbaf5fdc40a2b..2fbbd161ad709fdf76089ec9c4428297c6afbcbd 100644 (file)
 
 
 ssize_t uk_file_nop_read(const struct uk_file *f __unused,
-                        const struct iovec *iov __unused, int iovcnt __unused,
+                        const struct iovec *iov __unused,
+                        size_t iovcnt __unused,
                         size_t off __unused, long flags __unused)
 {
        return -ENOSYS;
 }
 
 ssize_t uk_file_nop_write(const struct uk_file *f __unused,
-                         const struct iovec *iov __unused, int iovcnt __unused,
+                         const struct iovec *iov __unused,
+                         size_t iovcnt __unused,
                          size_t off __unused, long flags __unused)
 {
        return -ENOSYS;
index 1c7255dc88a358169388576c33be453995b74b6c..c4e6cab647f9106199ab8b213da83697077b9f24 100644 (file)
@@ -36,7 +36,7 @@ struct uk_file;
 
 /* I/O */
 typedef ssize_t (*uk_file_io_func)(const struct uk_file *f,
-                                  const struct iovec *iov, int iovcnt,
+                                  const struct iovec *iov, size_t iovcnt,
                                   size_t off, long flags);
 
 /* Info (stat-like & chXXX-like) */
@@ -221,7 +221,7 @@ struct uk_file {
 /* Operations inlines */
 static inline
 ssize_t uk_file_read(const struct uk_file *f,
-                    const struct iovec *iov, int iovcnt,
+                    const struct iovec *iov, size_t iovcnt,
                     size_t off, long flags)
 {
        return f->ops->read(f, iov, iovcnt, off, flags);
@@ -229,7 +229,7 @@ ssize_t uk_file_read(const struct uk_file *f,
 
 static inline
 ssize_t uk_file_write(const struct uk_file *f,
-                     const struct iovec *iov, int iovcnt,
+                     const struct iovec *iov, size_t iovcnt,
                      size_t off, long flags)
 {
        return f->ops->write(f, iov, iovcnt, off, flags);
index b7b0b1b68cd255b91c4fb401449387a0b795220a..3a8b805b58e7a0045072054e870ea1fae2e689f3 100644 (file)
  * @return Number of bytes zeroed
  */
 static inline
-size_t uk_iov_zero(const struct iovec *iov, int iovcnt, size_t len,
-                  int *iovip, size_t *curp)
+size_t uk_iov_zero(const struct iovec *iov, size_t iovcnt, size_t len,
+                  size_t *iovip, size_t *curp)
 {
        size_t ret = 0;
-       int i = *iovip;
+       size_t i = *iovip;
        size_t cur = *curp;
 
        UK_ASSERT(i < iovcnt);
@@ -74,11 +74,11 @@ size_t uk_iov_zero(const struct iovec *iov, int iovcnt, size_t len,
  * @return Number of bytes copied
  */
 static inline
-size_t uk_iov_scatter(const struct iovec *iov, int iovcnt, const char *buf,
-                     size_t len, int *iovip, size_t *curp)
+size_t uk_iov_scatter(const struct iovec *iov, size_t iovcnt, const char *buf,
+                     size_t len, size_t *iovip, size_t *curp)
 {
        size_t ret = 0;
-       int i = *iovip;
+       size_t i = *iovip;
        size_t cur = *curp;
 
        UK_ASSERT(i < iovcnt);
@@ -126,11 +126,11 @@ size_t uk_iov_scatter(const struct iovec *iov, int iovcnt, const char *buf,
  * @return Number of bytes copied
  */
 static inline
-size_t uk_iov_gather(char *buf, const struct iovec *iov, int iovcnt,
-                    size_t len, int *iovip, size_t *curp)
+size_t uk_iov_gather(char *buf, const struct iovec *iov, size_t iovcnt,
+                    size_t len, size_t *iovip, size_t *curp)
 {
        size_t ret = 0;
-       int i = *iovip;
+       size_t i = *iovip;
        size_t cur = *curp;
 
        UK_ASSERT(i < iovcnt);
index 82644f5167d67040144cad4e928d8babf6ba565c..7c0fe1d939027dcd42e537c926db70880327b83f 100644 (file)
 extern const struct uk_file_ops uk_file_nops;
 
 ssize_t uk_file_nop_read(const struct uk_file *f,
-                        const struct iovec *iov, int iovcnt,
+                        const struct iovec *iov, size_t iovcnt,
                         size_t off, long flags);
 
 ssize_t uk_file_nop_write(const struct uk_file *f,
-                         const struct iovec *iov, int iovcnt,
+                         const struct iovec *iov, size_t iovcnt,
                          size_t off, long flags);
 
 int uk_file_nop_getstat(const struct uk_file *f,