mescc: Mes C Library: Support gcc-4.6.4: Add mmap, munmap.

* include/linux/x86/syscall.h (SYS_mmap, SYS_munmap): New macro.
* include/linux/x86_64/syscall.h (SYS_mmap, SYS_munmap): New macro.
* include/sys/mman.h (MAP_SHARED, MAP_PRIVATE, MAP_ANONYMOUS,
MAP_POPULATE, MAP_ANON, MAP_FAILED): New macro.
(mmap, munmap): Declare.
* lib/linux/gnu.c (mmap, munmap): New function.
* lib/linux/x86-mes-gcc/mes.c (_sys_call6): New function.
* lib/linux/x86-mes/mes.c (__sys_call6): New function.
(_sys_call6): New function.
* lib/linux/x86_64-mes-gcc/mes.c (_sys_call6): New function.
* lib/linux/x86_64-mes/mes.c (__sys_call): Cater for 6 syscall parameters.
(_sys_call6): New function.
* lib/x86-mes/x86.M1 (pop____%ebp): New macro.
* lib/x86_64-mes/x86_64.M1 (mov____0x8(%rbp),%r9): New macro.
This commit is contained in:
Jan Nieuwenhuizen 2019-02-08 16:51:37 +01:00
parent 96b585aba4
commit 0f7af7ac61
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
10 changed files with 103 additions and 7 deletions

View File

@ -88,4 +88,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

View File

@ -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

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -25,19 +25,25 @@
#include_next <sys/mman.h>
#else // ! WITH_GLIBC
#ifndef __MES_SIZE_T
#define __MES_SIZE_T
typedef unsigned long size_t;
#endif
#include <sys/types.h>
#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 // ! WITH_GLIBC
#endif // __MES_SYS_MMAN_H

View File

@ -20,6 +20,7 @@
#include <sys/resource.h>
#include <time.h>
#include <sys/mman.h>
int
link (char const *old_name, char const *new_name)
@ -216,3 +217,16 @@ mknod (char const *file_name, mode_t mode, dev_t dev)
{
return _sys_call3 (SYS_mknod, (long)file_name, (long)mode, (long)dev);
}
// gcc-4.6.4
void *
mmap (void* addr, size_t len, int prot, int flags, int fd, off_t offset)
{
return _sys_call6 (SYS_mmap, (long)addr, (long)len, (int)prot, (int)flags, (int)fd, (long)offset);
}
int
munmap (void *addr, size_t length)
{
return _sys_call2 (SYS_munmap, (long)addr, (long)length);
}

View File

@ -140,3 +140,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;
}

View File

@ -66,6 +66,15 @@ __sys_call4 (int sys_call, int one, int two, int three, int four)
asm ("int____$0x80");
}
int
__sys_call6 (int sys_call, int one, int two, int three, int four, int five, int six)
{
asm ("mov____0x8(%ebp),%eax !0x08");
asm ("mov____%ebp,%ebx");
asm ("add____$i8,%ebx !0x0c");
asm ("int____$0x80");
}
int
_sys_call (int sys_call)
{
@ -135,3 +144,9 @@ _sys_call4 (int sys_call, int one, int two, int three, int 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);
}

View File

@ -149,3 +149,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;
}

View File

@ -23,7 +23,7 @@
long
//__sys_call (long one, long two, long three, long four)
__sys_call (long sys_call, long one, long two, long three, long four)
__sys_call (long sys_call, long one, long two, long three, long four, long five, long six)
{
#if 1 // !MES_CCAMD64
// asm ("mov____0x8(%rbp),%rdi !0x10");
@ -37,6 +37,8 @@ __sys_call (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");
@ -121,3 +123,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;
}

View File

@ -161,6 +161,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

View File

@ -136,6 +136,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