diff --git a/build-aux/configure-lib.sh b/build-aux/configure-lib.sh index e1da64f0..1a254437 100644 --- a/build-aux/configure-lib.sh +++ b/build-aux/configure-lib.sh @@ -422,6 +422,8 @@ lib/linux/link.c lib/linux/lstat.c lib/linux/mkdir.c lib/linux/mknod.c +lib/linux/mmap.c +lib/linux/munmap.c lib/linux/nanosleep.c lib/linux/pipe.c lib/linux/readlink.c diff --git a/include/linux/arm/syscall.h b/include/linux/arm/syscall.h index 62029463..66ee496a 100644 --- a/include/linux/arm/syscall.h +++ b/include/linux/arm/syscall.h @@ -91,4 +91,8 @@ #define SYS_readlink 0x55 #define SYS_mknod 0x0e +// gcc-4.6.4 +#define SYS_mmap 0x5a +#define SYS_munmap 0x5b + #endif /* __MES_LINUX_ARM_SYSCALL_H */ diff --git a/include/linux/x86/syscall.h b/include/linux/x86/syscall.h index c1271f06..736c3db6 100644 --- a/include/linux/x86/syscall.h +++ b/include/linux/x86/syscall.h @@ -92,4 +92,8 @@ #define SYS_readlink 0x55 #define SYS_mknod 0x0e +// gcc-4.6.4 +#define SYS_mmap 0x5a +#define SYS_munmap 0x5b + #endif /* __MES_LINUX_X86_SYSCALL_H */ diff --git a/include/linux/x86_64/syscall.h b/include/linux/x86_64/syscall.h index 36ef06bc..ad1e22d3 100644 --- a/include/linux/x86_64/syscall.h +++ b/include/linux/x86_64/syscall.h @@ -85,4 +85,8 @@ #define SYS_readlink 0x59 #define SYS_mknod 0x85 +// gcc-4.6.4 +#define SYS_mmap 0x09 +#define SYS_munmap 0x0b + #endif // __MES_LINUX_X86_64_SYSCALL_H diff --git a/include/sys/mman.h b/include/sys/mman.h index 9f696b01..d58d95c0 100644 --- a/include/sys/mman.h +++ b/include/sys/mman.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -25,19 +25,25 @@ #include_next #else // ! SYSTEM_LIBC -#ifndef __MES_SIZE_T -#define __MES_SIZE_T -typedef unsigned long size_t; -#endif +#include + +#define MAP_SHARED 0x01 +#define MAP_PRIVATE 0x02 +#define MAP_ANONYMOUS 0x20 +#define MAP_POPULATE 0x08000 + +#define MAP_ANON MAP_ANONYMOUS +#define MAP_FAILED ((void*)-1) #define PROT_NONE 0 #define PROT_READ 1 #define PROT_WRITE 2 #define PROT_EXEC 4 +void *mmap (void *address, size_t length, int protect, int flags, int filedes, off_t offset); int mprotect (void *addr, size_t len, int prot); +int munmap (void *addr, size_t length); #endif // ! SYSTEM_LIBC #endif // __MES_SYS_MMAN_H - diff --git a/lib/linux/arm-mes-gcc/syscall.c b/lib/linux/arm-mes-gcc/syscall.c index 790d0928..ec85f93a 100644 --- a/lib/linux/arm-mes-gcc/syscall.c +++ b/lib/linux/arm-mes-gcc/syscall.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -19,7 +19,7 @@ */ #include -#include +#include #if !__TINYC__ // *INDENT-OFF* @@ -187,7 +187,6 @@ __sys_call4 (long sys_call, long one, long two, long three, long four) } #endif //__TINYC__ -#if 0 long __sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six) { @@ -208,7 +207,6 @@ __sys_call6 (long sys_call, long one, long two, long three, long four, long five ); return r; } -#endif // *INDENT-ON* @@ -282,7 +280,6 @@ _sys_call4 (long sys_call, long one, long two, long three, long four) return r; } -#if 0 long _sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six) { @@ -296,4 +293,3 @@ _sys_call6 (long sys_call, long one, long two, long three, long four, long five, errno = 0; return r; } -#endif diff --git a/lib/linux/mmap.c b/lib/linux/mmap.c new file mode 100644 index 00000000..43f83fe4 --- /dev/null +++ b/lib/linux/mmap.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include +#include + +void * +mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) +{ + return (void *)_sys_call6 (SYS_mmap, (long) addr, (long) len, (int) prot, (int) flags, (int) fd, (long) offset); +} diff --git a/lib/linux/munmap.c b/lib/linux/munmap.c new file mode 100644 index 00000000..1c180998 --- /dev/null +++ b/lib/linux/munmap.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include +#include + +int +munmap (void *addr, size_t length) +{ + return _sys_call2 (SYS_munmap, (long) addr, (long) length); +} diff --git a/lib/linux/x86-mes-gcc/syscall.c b/lib/linux/x86-mes-gcc/syscall.c index 39c23cdc..109ad8a1 100644 --- a/lib/linux/x86-mes-gcc/syscall.c +++ b/lib/linux/x86-mes-gcc/syscall.c @@ -177,3 +177,20 @@ _sys_call4 (long sys_call, long one, long two, long three, long four) errno = 0; return r; } + +long +_sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six) +{ + long r; + asm ( + "mov %1,%%eax\n\t" + "mov %%ebp,%%ebx\n\t" + "add $0x0c,%%ebx\n\t" + "int $0x80\n\t" + "mov %%eax,%0\n\t" + : "=r" (r) + : "rm" (sys_call) + : "eax", "ebx" + ); + return r; +} diff --git a/lib/linux/x86-mes-mescc/syscall.c b/lib/linux/x86-mes-mescc/syscall.c index 20395650..6b96930e 100644 --- a/lib/linux/x86-mes-mescc/syscall.c +++ b/lib/linux/x86-mes-mescc/syscall.c @@ -66,6 +66,15 @@ __sys_call4 (long sys_call, long one, long two, long three, long four) asm ("int____$0x80"); } +long +__sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six) +{ + asm ("mov____0x8(%ebp),%eax !0x08"); + asm ("mov____%ebp,%ebx"); + asm ("add____$i8,%ebx !0x0c"); + asm ("int____$0x80"); +} + long _sys_call (long sys_call) { @@ -135,3 +144,9 @@ _sys_call4 (long sys_call, long one, long two, long three, long four) errno = 0; return r; } + +int +_sys_call6 (int sys_call, int one, int two, int three, int four, int five, int six) +{ + return __sys_call6 (sys_call, one, two, three, four, five, six); +} diff --git a/lib/linux/x86_64-mes-gcc/syscall.c b/lib/linux/x86_64-mes-gcc/syscall.c index f55a4a3a..d65e31b5 100644 --- a/lib/linux/x86_64-mes-gcc/syscall.c +++ b/lib/linux/x86_64-mes-gcc/syscall.c @@ -179,3 +179,26 @@ _sys_call4 (long sys_call, long one, long two, long three, long four) errno = 0; return r; } + +long +_sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six) +{ + long r; + asm ( + "mov %2,%%rdi\n\t" + "mov %3,%%rsi\n\t" + "mov %4,%%rdx\n\t" + "mov %5,%%r10\n\t" + "mov %6,%%r8\n\t" + "mov %7,%%r9\n\t" + "mov %1,%%rax\n\t" + // ); + // asm ( + "syscall \n\t" + "mov %%rax,%0\n\t" + : "=r" (r) + : "rm" (sys_call), "rm" (one), "rm" (two), "rm" (three), "rm" (four), "rm" (five), "rm" (six) + : "rax", "rdi", "rsi", "rdx", "r10", "r8", "r9" + ); + return r; +} diff --git a/lib/linux/x86_64-mes-mescc/syscall.c b/lib/linux/x86_64-mes-mescc/syscall.c index 1ebb3b67..32be4e2e 100644 --- a/lib/linux/x86_64-mes-mescc/syscall.c +++ b/lib/linux/x86_64-mes-mescc/syscall.c @@ -96,6 +96,8 @@ __sys_call4 (long sys_call, long one, long two, long three, long four) asm ("mov____0x8(%rbp),%rsi !0x20"); asm ("mov____0x8(%rbp),%rdx !0x28"); asm ("mov____0x8(%rbp),%r10 !0x30"); + asm ("mov____0x8(%rbp),%r8 !0x38"); + asm ("mov____0x8(%rbp),%r9 !0x40"); #endif asm ("syscall"); @@ -170,3 +172,12 @@ _sys_call4 (long sys_call, long one, long two, long three, long four) errno = 0; return r; } + +long +_sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six) +{ + // long rax = sys_call; + // long r = __sys_call6 (one, two, three, four, five, six); + long r = __sys_call (sys_call, one, two, three, four, five, six); + return r; +} diff --git a/lib/x86-mes/x86.M1 b/lib/x86-mes/x86.M1 index ede79799..5836006b 100644 --- a/lib/x86-mes/x86.M1 +++ b/lib/x86-mes/x86.M1 @@ -163,6 +163,7 @@ DEFINE not____%ebx f7d3 DEFINE or_____%ebx,%eax 09d8 DEFINE pop____%eax 58 DEFINE pop____%ebx 5b +DEFINE pop____%ebp 5d DEFINE pop____%edx 5a DEFINE push___$i32 68 DEFINE push___%eax 50 diff --git a/lib/x86_64-mes/x86_64.M1 b/lib/x86_64-mes/x86_64.M1 index 6bb2b0b2..6f7913ad 100644 --- a/lib/x86_64-mes/x86_64.M1 +++ b/lib/x86_64-mes/x86_64.M1 @@ -141,6 +141,7 @@ DEFINE mov____0x32,%rdi 488b3c25 DEFINE mov____0x8(%rbp),%eax 8b45 DEFINE mov____0x8(%rbp),%r10 4c8b55 DEFINE mov____0x8(%rbp),%r8 4c8b45 +DEFINE mov____0x8(%rbp),%r9 4c8b4d DEFINE mov____0x8(%rbp),%rax 488b45 DEFINE mov____0x8(%rbp),%rbp 488b6d DEFINE mov____0x8(%rbp),%rbx 488b5d