From 1d0ecb2915ca6259d70e46a292812eb44b45cdcb Mon Sep 17 00:00:00 2001 From: Vladimir Atamanenko Date: Mon, 1 Nov 2021 03:43:57 +0400 Subject: [PATCH 1/5] Create uio.h --- newlib/libc/sys/vita/sys/uio.h | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 newlib/libc/sys/vita/sys/uio.h diff --git a/newlib/libc/sys/vita/sys/uio.h b/newlib/libc/sys/vita/sys/uio.h new file mode 100644 index 000000000..91d82b55c --- /dev/null +++ b/newlib/libc/sys/vita/sys/uio.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 1991-2018 Free Software Foundation, Inc. + * This file is part of the GNU C Library. + * The GNU C Library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * The GNU C Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public + * License along with the GNU C Library; if not, see + * . + */ + +#ifndef _SYS_UIO_H_ +#define _SYS_UIO_H_ + +#include +#include +#include + +__BEGIN_DECLS + +#ifndef __GNU_VISIBLE +void* mempcpy(void *<[out]>, const void *<[in]>, size_t <[n]>); +#endif + +struct iovec { + void *iov_base; + size_t iov_len; +}; + +ssize_t readv(int, const struct iovec *, int); +ssize_t writev(int, const struct iovec *, int); + +__END_DECLS + +#endif /* sys/uio.h */ From 3c52a4d6e4acedfaa888c0db8a4a07ec4165b126 Mon Sep 17 00:00:00 2001 From: Vladimir Atamanenko Date: Mon, 1 Nov 2021 03:47:41 +0400 Subject: [PATCH 2/5] Create uio.c --- newlib/libc/sys/vita/uio.c | 134 +++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 newlib/libc/sys/vita/uio.c diff --git a/newlib/libc/sys/vita/uio.c b/newlib/libc/sys/vita/uio.c new file mode 100644 index 000000000..79564aaf9 --- /dev/null +++ b/newlib/libc/sys/vita/uio.c @@ -0,0 +1,134 @@ +/* + * Copyright (C) 1991-2018 Free Software Foundation, Inc. + * This file is part of the GNU C Library. + * The GNU C Library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * The GNU C Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public + * License along with the GNU C Library; if not, see + * . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef SSIZE_MAX +/* ssize_t is not formally required to be the signed type + corresponding to size_t, but it is for all configurations supported + by glibc. */ +# if __WORDSIZE == 64 || __WORDSIZE32_SIZE_ULONG +# define SSIZE_MAX LONG_MAX +# else +# define SSIZE_MAX INT_MAX +# endif +#endif + +static void ifree (char **ptrp) +{ + free (*ptrp); +} + +/* Write data pointed by the buffers described by VECTOR, which + is a vector of COUNT 'struct iovec's, to file descriptor FD. + The data is written in the order specified. + Operates just like 'write' (see ) except that the data + are taken from VECTOR instead of a contiguous buffer. */ +ssize_t writev (int fd, const struct iovec *vector, int count) +{ + /* Find the total number of bytes to be written. */ + size_t bytes = 0; + for (int i = 0; i < count; ++i) + { + /* Check for ssize_t overflow. */ + if (SSIZE_MAX - bytes < vector[i].iov_len) + { + return -1; + } + bytes += vector[i].iov_len; + } + + char *buffer; + char *malloced_buffer __attribute__ ((__cleanup__ (ifree))) = NULL; + + malloced_buffer = buffer = (char *) malloc (bytes); + if (buffer == NULL) + /* XXX I don't know whether it is acceptable to try writing the data in chunks. Probably not so we just fail here. */ + return -1; + + /* Copy the data into BUFFER. */ + size_t to_copy = bytes; + char *bp = buffer; + for (int i = 0; i < count; ++i) + { + size_t copy = MIN (vector[i].iov_len, to_copy); + + bp = mempcpy ((void *) bp, (void *) vector[i].iov_base, copy); + + to_copy -= copy; + if (to_copy == 0) + break; + } + + ssize_t bytes_written = write (fd, buffer, bytes); + + return bytes_written; +} + +/* Read data from file descriptor FD, and put the result in the + buffers described by VECTOR, which is a vector of COUNT 'struct iovec's. + The buffers are filled in the order specified. + Operates just like 'read' (see ) except that data are + put in VECTOR instead of a contiguous buffer. */ +ssize_t readv (int fd, const struct iovec *vector, int count) +{ + /* Find the total number of bytes to be read. */ + size_t bytes = 0; + for (int i = 0; i < count; ++i) + { + /* Check for ssize_t overflow. */ + if (SSIZE_MAX - bytes < vector[i].iov_len) + { + return -1; + } + bytes += vector[i].iov_len; + } + + char *buffer; + char *malloced_buffer __attribute__ ((__cleanup__ (ifree))) = NULL; + + malloced_buffer = buffer = (char *) malloc (bytes); + if (buffer == NULL) + return -1; + + /* Read the data. */ + ssize_t bytes_read = read (fd, buffer, bytes); + if (bytes_read < 0) + return -1; + + /* Copy the data from BUFFER into the memory specified by VECTOR. */ + bytes = bytes_read; + for (int i = 0; i < count; ++i) + { + size_t copy = MIN (vector[i].iov_len, bytes); + + (void) memcpy ((void *) vector[i].iov_base, (void *) buffer, copy); + + buffer += copy; + bytes -= copy; + if (bytes == 0) + break; + } + + return bytes_read; +} From 49bf54bb8d75d78af29f7d90138c6cac75be034c Mon Sep 17 00:00:00 2001 From: Vladimir Atamanenko Date: Mon, 1 Nov 2021 03:49:32 +0400 Subject: [PATCH 3/5] Update socket.h --- newlib/libc/sys/vita/sys/socket.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/newlib/libc/sys/vita/sys/socket.h b/newlib/libc/sys/vita/sys/socket.h index 116aa441a..d30c9a808 100644 --- a/newlib/libc/sys/vita/sys/socket.h +++ b/newlib/libc/sys/vita/sys/socket.h @@ -70,6 +70,7 @@ extern "C" { #include #include #include +#include typedef uint8_t sa_family_t; typedef uint32_t socklen_t; @@ -245,11 +246,6 @@ struct sockaddr_storage { #define SHUT_WR 1 /* Disallow further sends. */ #define SHUT_RDWR 2 /* Disallow further sends/receives. */ -struct iovec { - void *iov_base; /* Base address. */ - size_t iov_len; /* Length. */ -}; - struct msghdr { void *msg_name; /* optional address */ socklen_t msg_namelen; /* size of address */ From 5be309abc0f8cef602548c068d5d1cda0b24b62c Mon Sep 17 00:00:00 2001 From: Vladimir Atamanenko Date: Mon, 1 Nov 2021 03:51:07 +0400 Subject: [PATCH 4/5] Update Makefile.am --- newlib/libc/sys/vita/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newlib/libc/sys/vita/Makefile.am b/newlib/libc/sys/vita/Makefile.am index 573b0b6b3..0c296de7a 100755 --- a/newlib/libc/sys/vita/Makefile.am +++ b/newlib/libc/sys/vita/Makefile.am @@ -14,7 +14,7 @@ DIRENT_OBJS = closedir.o opendir.o readdir.o readdir_r.o rewinddir.o seekdir.o t NET_SOURCES = net/gethostbyaddr.c net/gethostbyname.c net/getaddrinfo.c net/freeaddrinfo.c net/getservbyname.c net/inet_ntop.c net/inet_ntoa.c net/inet_netof.c net/inet_pton.c net/inet_lnaof.c net/inet_addr.c net/inet_network.c net/inet_net_ntop.c net/inet_aton.c net/inet_net_pton.c net/inet_makeaddr.c STUB_SOURCES = chroot.c getentropy.c groups.c -lib_a_SOURCES = syscalls.c access.c sbrk.c threading.c mlock.c io.c socket.c dup.c select.c error.c dirent.c lcltime_r.c sleep.c usleep.c truncate.c fs.c clock.c pread.c ${STUB_SOURCES} ${NET_SOURCES} +lib_a_SOURCES = syscalls.c access.c sbrk.c threading.c mlock.c io.c socket.c dup.c select.c error.c dirent.c lcltime_r.c sleep.c usleep.c truncate.c fs.c clock.c pread.c uio.c ${STUB_SOURCES} ${NET_SOURCES} lib_a_LIBADD = ${SOCKET_OBJS} ${NET_OBJS} ${DIRENT_OBJS} lib_a_CCASFLAGS = $(AM_CCASFLAGS) lib_a_CFLAGS = $(AM_CFLAGS) From a8f753d7a31528784137ff1d5e911a9db73478b2 Mon Sep 17 00:00:00 2001 From: v-atamanenko Date: Mon, 1 Nov 2021 03:52:14 +0400 Subject: [PATCH 5/5] Update Makefile.in --- newlib/libc/sys/vita/Makefile.in | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/newlib/libc/sys/vita/Makefile.in b/newlib/libc/sys/vita/Makefile.in index c3a4858d8..65fc34191 100644 --- a/newlib/libc/sys/vita/Makefile.in +++ b/newlib/libc/sys/vita/Makefile.in @@ -88,8 +88,8 @@ am_lib_a_OBJECTS = lib_a-syscalls.$(OBJEXT) lib_a-access.$(OBJEXT) \ lib_a-dirent.$(OBJEXT) lib_a-lcltime_r.$(OBJEXT) \ lib_a-sleep.$(OBJEXT) lib_a-usleep.$(OBJEXT) \ lib_a-truncate.$(OBJEXT) lib_a-fs.$(OBJEXT) \ - lib_a-clock.$(OBJEXT) lib_a-pread.$(OBJEXT) $(am__objects_1) \ - $(am__objects_2) + lib_a-clock.$(OBJEXT) lib_a-pread.$(OBJEXT) \ + lib_a-uio.$(OBJEXT) $(am__objects_1) $(am__objects_2) lib_a_OBJECTS = $(am_lib_a_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = @@ -220,7 +220,7 @@ NET_OBJS = gethostbyaddr.o gethostbyname.o getaddrinfo.o freeaddrinfo.o getservb DIRENT_OBJS = closedir.o opendir.o readdir.o readdir_r.o rewinddir.o seekdir.o telldir.o NET_SOURCES = net/gethostbyaddr.c net/gethostbyname.c net/getaddrinfo.c net/freeaddrinfo.c net/getservbyname.c net/inet_ntop.c net/inet_ntoa.c net/inet_netof.c net/inet_pton.c net/inet_lnaof.c net/inet_addr.c net/inet_network.c net/inet_net_ntop.c net/inet_aton.c net/inet_net_pton.c net/inet_makeaddr.c STUB_SOURCES = chroot.c getentropy.c groups.c -lib_a_SOURCES = syscalls.c access.c sbrk.c threading.c mlock.c io.c socket.c dup.c select.c error.c dirent.c lcltime_r.c sleep.c usleep.c truncate.c fs.c clock.c pread.c ${STUB_SOURCES} ${NET_SOURCES} +lib_a_SOURCES = syscalls.c access.c sbrk.c threading.c mlock.c io.c socket.c dup.c select.c error.c dirent.c lcltime_r.c sleep.c usleep.c truncate.c fs.c clock.c pread.c uio.c ${STUB_SOURCES} ${NET_SOURCES} lib_a_LIBADD = ${SOCKET_OBJS} ${NET_OBJS} ${DIRENT_OBJS} lib_a_CCASFLAGS = $(AM_CCASFLAGS) lib_a_CFLAGS = $(AM_CFLAGS) @@ -392,6 +392,12 @@ lib_a-pread.o: pread.c lib_a-pread.obj: pread.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-pread.obj `if test -f 'pread.c'; then $(CYGPATH_W) 'pread.c'; else $(CYGPATH_W) '$(srcdir)/pread.c'; fi` +lib_a-uio.o: uio.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-uio.o `test -f 'uio.c' || echo '$(srcdir)/'`uio.c + +lib_a-uio.obj: uio.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-uio.obj `if test -f 'uio.c'; then $(CYGPATH_W) 'uio.c'; else $(CYGPATH_W) '$(srcdir)/uio.c'; fi` + lib_a-chroot.o: chroot.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-chroot.o `test -f 'chroot.c' || echo '$(srcdir)/'`chroot.c