This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "uClibc-ng - small C library for embedded systems".
The branch, 1.0 has been updated via 9fae2ad9937279c9f7f40975ac14cb7b57f4a36d (commit) via 4480f9b5558906fce2c35f1819d4e1fe5922a9fa (commit) via 2eb8070e678937e7e7835d167cffb11628b8862e (commit) from 39e50d004f9b2cfd0988f670a877d83ee17d2418 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit 9fae2ad9937279c9f7f40975ac14cb7b57f4a36d Author: Yuriy Kolerov yuriy.kolerov@synopsys.com Date: Wed Sep 23 15:43:39 2015 +0300
libc: posix_fallocate must return an error number on failure
posix_fallocate implementation in uClibc relies on fallocate system call - it just returns what fallocate returns. However fallocate returns -1 on failure and assigns an error number to errno variable. In the same time posix_fallocate must return an error number but not -1.
What does this patch: if fallocate returns -1 then posix_fallocate returns errno. Otherwise posix_fallocate returns 0 on success.
However there is a side effect - posix_fallocate sets errno on failure because fallocate does it. But POSIX does not forbid it thus it's not a problem.
Signed-off-by: Yuriy Kolerov yuriy.kolerov@synopsys.com
commit 4480f9b5558906fce2c35f1819d4e1fe5922a9fa Author: Yuriy Kolerov yuriy.kolerov@synopsys.com Date: Wed Sep 23 15:43:38 2015 +0300
libc: fix sign extension in fallocate()
For common generic syscall ABI fallocate syscall handler in kernel expects a 64-bit signed arguments for offset and len. However uClibc has 2 wrappers for this syscall: fallocate and fallocate64.
On 32-bit machines fallocate (not fallocate64) expects 32-bit values of offset and len. Thus in this case uClibc's fallocate must pass to the syscall those values with sign extension. High word of 64-bit value must be 0 or 0xFFFFFFFF depending on sign of the original 32-bit value (offset or len). It is how sign extansion works - all high bits of the negative value must be 1.
So on 32-bit machines uClibc's fallocate does sign extension incorrectly when 32-bit values are passed (offset or len). It just fills the second word of 64-bit value by zeros. E.g. fallocate works incorrectly when offset or length is negative value - in this case kernel thinks that positive values are passed.
Solution is to call fallocate64 from fallocate and pass 32-bit values of offset and len to fallocate64. off_t type is automatically converted to off64_t with an appropriate sign extension. Then fallocate64 invokes kernel's system call properly.
This error is detected in LTP's test kernel/syscalls/fallocate02:
----------->8---------- fallocate(..., 1, -1024, 1024) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, 1024, -1024) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, 12288, -1024) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, -24576, 1024) failed, expected errno:22: TEST_ERRNO=0 ----------->8----------
fallocate does not emit an error because negative values are passed to the kernel without sign extension and kernel thinks that it got valid positive values.
Signed-off-by: Yuriy Kolerov yuriy.kolerov@synopsys.com
commit 2eb8070e678937e7e7835d167cffb11628b8862e Author: Yuriy Kolerov yuriy.kolerov@synopsys.com Date: Wed Sep 23 15:43:37 2015 +0300
libc: fix setting return value and errno in fallocate()
fallocate system call must return 0 on success. On error, -1 is returned and errno is set to indicate the error.
However there is an error in fallocate which is fixed by this patch - it does not set errno and returns invalid value on error (it returns error code instead of -1).
This error is detected in LTP's test kernel/syscalls/fallocate02:
----------->8---------- fallocate(..., 1, 0, 1024) failed, expected errno:9: TEST_ERRNO=0 fallocate(..., 1, -1024, 1024) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, 1024, -1024) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, 12288, 0) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, 12288, -1024) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, -24576, 1024) failed, expected errno:22: TEST_ERRNO=0 ----------->8----------
Signed-off-by: Yuriy Kolerov yuriy.kolerov@synopsys.com
-----------------------------------------------------------------------
Summary of changes: libc/sysdeps/linux/common/fallocate.c | 21 ++++++++------------- libc/sysdeps/linux/common/fallocate64.c | 9 ++++++--- libc/sysdeps/linux/common/posix_fallocate.c | 5 ++++- libc/sysdeps/linux/common/posix_fallocate64.c | 5 ++++- 4 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/libc/sysdeps/linux/common/fallocate.c b/libc/sysdeps/linux/common/fallocate.c index b231226..0f80fb4 100644 --- a/libc/sysdeps/linux/common/fallocate.c +++ b/libc/sysdeps/linux/common/fallocate.c @@ -12,31 +12,26 @@ #include <fcntl.h> #include <bits/kernel-features.h> #include <stdint.h> +#include <errno.h>
#if defined __NR_fallocate extern __typeof(fallocate) __libc_fallocate attribute_hidden; int attribute_hidden __libc_fallocate(int fd, int mode, __off_t offset, __off_t len) { - int ret; - # if __WORDSIZE == 32 - uint32_t off_low = offset; - uint32_t len_low = len; - /* may assert that these >>31 are 0 */ - uint32_t zero = 0; - INTERNAL_SYSCALL_DECL(err); - ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, mode, - __LONG_LONG_PAIR (zero, off_low), - __LONG_LONG_PAIR (zero, len_low))); + return fallocate64(fd, mode, offset, len); # elif __WORDSIZE == 64 + int ret; INTERNAL_SYSCALL_DECL(err); ret = (int) (INTERNAL_SYSCALL(fallocate, err, 4, fd, mode, offset, len)); + if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) { + __set_errno(INTERNAL_SYSCALL_ERRNO (ret, err)); + ret = -1; + } + return ret; # else # error your machine is neither 32 bit or 64 bit ... it must be magical # endif - if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) - return INTERNAL_SYSCALL_ERRNO (ret, err); - return 0; }
# if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU diff --git a/libc/sysdeps/linux/common/fallocate64.c b/libc/sysdeps/linux/common/fallocate64.c index cf75693..1aa351e 100644 --- a/libc/sysdeps/linux/common/fallocate64.c +++ b/libc/sysdeps/linux/common/fallocate64.c @@ -13,6 +13,7 @@ #include <fcntl.h> #include <bits/kernel-features.h> #include <stdint.h> +#include <errno.h>
#if defined __NR_fallocate
@@ -27,9 +28,11 @@ int attribute_hidden __libc_fallocate64(int fd, int mode, __off64_t offset, INTERNAL_SYSCALL_DECL(err); ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, mode, OFF64_HI_LO (offset), OFF64_HI_LO (len))); - if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) - return INTERNAL_SYSCALL_ERRNO (ret, err); - return 0; + if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) { + __set_errno(INTERNAL_SYSCALL_ERRNO (ret, err)); + ret = -1; + } + return ret; }
# if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU diff --git a/libc/sysdeps/linux/common/posix_fallocate.c b/libc/sysdeps/linux/common/posix_fallocate.c index 76771e3..2316cfd 100644 --- a/libc/sysdeps/linux/common/posix_fallocate.c +++ b/libc/sysdeps/linux/common/posix_fallocate.c @@ -12,12 +12,15 @@ #include <fcntl.h> #include <bits/kernel-features.h> #include <stdint.h> +#include <errno.h>
#if defined __NR_fallocate extern __typeof(fallocate) __libc_fallocate attribute_hidden; int posix_fallocate(int fd, __off_t offset, __off_t len) { - return __libc_fallocate(fd, 0, offset, len); + if (__libc_fallocate(fd, 0, offset, len)) + return errno; + return 0; } # if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64 strong_alias(posix_fallocate,posix_fallocate64) diff --git a/libc/sysdeps/linux/common/posix_fallocate64.c b/libc/sysdeps/linux/common/posix_fallocate64.c index 12ddbc2..85614f6 100644 --- a/libc/sysdeps/linux/common/posix_fallocate64.c +++ b/libc/sysdeps/linux/common/posix_fallocate64.c @@ -12,6 +12,7 @@ #include <fcntl.h> #include <bits/kernel-features.h> #include <stdint.h> +#include <errno.h>
#if defined __NR_fallocate # if __WORDSIZE == 64 @@ -20,7 +21,9 @@ extern __typeof(fallocate64) __libc_fallocate64 attribute_hidden; int posix_fallocate64(int fd, __off64_t offset, __off64_t len) { - return __libc_fallocate64(fd, 0, offset, len); + if (__libc_fallocate64(fd, 0, offset, len)) + return errno; + return 0; } # else # error your machine is neither 32 bit or 64 bit ... it must be magical
hooks/post-receive