From: "Andreas Dröscher" <musl@bugfree.ch>
To: musl@lists.openwall.com
Subject: [musl] mips32 little endian -ENOSYS is not -(-ENOSYS)
Date: Tue, 10 Mar 2020 22:10:15 +0100 [thread overview]
Message-ID: <d5009e59-7a8d-58d0-f736-a4e09cac8ec5@droescher.ch> (raw)
Hi
I'm building a new toolchain for a very old hardware with a very old Linux
Kernel (2.6.20). The CPU is a Alchemy (now AMD) AU1100 (production was
discontinued).
Obviously the Kernel lacks a lot of the modern system calls. I however expect
the general system call interface to be consistent. Moreover, musl has fallbacks
for many system-calls in place, kudos! However, the fallback is never triggered.
I will present the issue on one example (epoll):
excerpt from src/linux/epoll.c:
int epoll_create1(int flags)
{
int r = __syscall(SYS_epoll_create1, flags);
#ifdef SYS_epoll_create
if (r==-ENOSYS && !flags) r = __syscall(SYS_epoll_create, 1);
#endif
return __syscall_ret(r);
}
If r is -89 (negative ENOSYS) the fallback is triggered else the result is
returned as it is. However, in my case __syscall returnes 89 (positive ENOSYS).
I've tracked the return into the kernel and there the negative value is
returned. The Kernel additionally sets r7 to 1.
excerpt from arch/mips/syscall_arch.h:
static inline long __syscall1(long n, long a)
{
register long r4 __asm__("$4") = a;
register long r7 __asm__("$7");
register long r2 __asm__("$2") = n;
__asm__ __volatile__ (
"syscall"
: "+r"(r2), "=r"(r7)
: "r"(r4)
: SYSCALL_CLOBBERLIST, "$8", "$9", "$10");
return r7 ? -r2 : r2;
}
I assume the "bug" is triggered by __syscall1 If r7 is set it will change the
sign of r2. I can patch that by replacing:
return r7 ? -r2 : r2;
with
return (r7 && r2 > 0) ? -r2 : r2;
However I've no idea if I'm triggering any side effects or if I selected the
wrong implementation for my architecture.
Any suggestions are appreciated.
~Andreas
next reply other threads:[~2020-03-10 21:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-10 21:10 Andreas Dröscher [this message]
2020-03-11 0:55 ` Rich Felker
2020-03-11 1:19 ` Andreas Dröscher
2020-03-11 1:40 ` Rich Felker
2020-03-11 2:08 ` Andreas Dröscher
2020-03-11 2:18 ` Rich Felker
2020-03-11 21:08 ` Andreas Dröscher
2020-03-11 21:35 ` Rich Felker
2020-03-11 23:08 ` Rich Felker
2020-03-20 16:34 ` Rich Felker
2020-03-20 22:18 ` Andreas Dröscher
2020-03-20 22:33 ` Rich Felker
2020-03-29 21:46 ` Andreas Dröscher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d5009e59-7a8d-58d0-f736-a4e09cac8ec5@droescher.ch \
--to=musl@bugfree.ch \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).