Re: [PATCH V2 09/14] LoongArch: Adjust system call for 32BIT/64BIT

From: Huacai Chen

Date: Thu Nov 20 2025 - 07:05:36 EST


On Thu, Nov 20, 2025 at 6:40 PM WANG Xuerui <kernel@xxxxxxxxxx> wrote:
>
> On 11/18/25 19:27, Huacai Chen wrote:
> > Adjust system call for both 32BIT and 64BIT, including: add the uapi
> > unistd_{32,64}.h and syscall_table_{32,64}.h inclusion, add sys_mmap2()
> > definition, change the system call entry routines, etc.
> >
> > Signed-off-by: Jiaxun Yang <jiaxun.yang@xxxxxxxxxxx>
> > Signed-off-by: Huacai Chen <chenhuacai@xxxxxxxxxxx>
> > ---
> > arch/loongarch/include/asm/Kbuild | 1 +
> > arch/loongarch/include/uapi/asm/Kbuild | 1 +
> > arch/loongarch/include/uapi/asm/unistd.h | 6 ++++++
> > arch/loongarch/kernel/Makefile.syscalls | 1 +
> > arch/loongarch/kernel/entry.S | 22 +++++++++++-----------
> > arch/loongarch/kernel/syscall.c | 13 +++++++++++++
> > 6 files changed, 33 insertions(+), 11 deletions(-)
> >
> > [snip]
> > diff --git a/arch/loongarch/kernel/syscall.c b/arch/loongarch/kernel/syscall.c
> > index ab94eb5ce039..1249d82c1cd0 100644
> > --- a/arch/loongarch/kernel/syscall.c
> > +++ b/arch/loongarch/kernel/syscall.c
> > @@ -34,9 +34,22 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, unsigned long,
> > return ksys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
> > }
> >
> > +SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len, unsigned long,
> > + prot, unsigned long, flags, unsigned long, fd, unsigned long, offset)
> > +{
> > + if (offset & (~PAGE_MASK >> 12))
> > + return -EINVAL;
> > +
> > + return ksys_mmap_pgoff(addr, len, prot, flags, fd, offset >> (PAGE_SHIFT - 12));
> > +}
> > +
>
> Why not guard this with #ifdef CONFIG_32BIT?
Because it is not only used by CONFIG_32BIT, but also by CONFIG_COMPAT.

Huacai

>
> > void *sys_call_table[__NR_syscalls] = {
> > [0 ... __NR_syscalls - 1] = sys_ni_syscall,
> > +#ifdef CONFIG_32BIT
> > +#include <asm/syscall_table_32.h>
> > +#else
> > #include <asm/syscall_table_64.h>
> > +#endif
> > };
> >
> > typedef long (*sys_call_fn)(unsigned long, unsigned long,
>
> --
> WANG "xen0n" Xuerui
>
> Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/