mescc: Support GNU Bash.

* include/errno.h (EACCES, ENOSPC, ESPIPE): New macro.
* include/linux/x86/syscall.h (SYS_setuid, SYS_geteuid, SYS_getegid,
SYS_setgid): New macro.
* include/linux/x86_64/syscall.h: Likewise.
* include/stdint.h (LLONG_MIN, LLONG_MAX, SIZE_MAX): New macro.
* include/sys/stat.h (S_ISUID, S_ISGID, S_IXGRP, S_IXOTH, S_IRGRP,
S_IROTH, S_IWGRP, S_IWOTH, S_IRWXG, S_IRWXO): New macro.
* include/termio.h: New file.
* include/unistd.h (_POSIX_VERSION): New macro.
* lib/linux/gnu.c (geteuid, getegid, setuid, setgid): New function.
* lib/string/memchr.c: New file.
* lib/stub/getpwuid.c: New file.
* lib/stub/rand.c: New file.
* lib/stub/ttyname.c: New file.
* include/string.h (memchr): Declare.
* include/unistd.h (geteuid, getegid, setuid, setgid): Declare.
This commit is contained in:
Jan Nieuwenhuizen 2018-11-09 21:26:10 +01:00
parent 23d4019d13
commit cd30bee788
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
16 changed files with 273 additions and 1 deletions

View File

@ -44,11 +44,14 @@ int errno;
#define ECHILD 10
#define EAGAIN 11
#define ENOMEM 12
#define EACCES 13
#define EEXIST 17
#define ENOTDIR 20
#define EISDIR 21
#define EINVAL 22
#define EMFILE 24
#define ENOSPC 28
#define ESPIPE 29
#define EPIPE 32
#define ERANGE 34

View File

@ -73,4 +73,10 @@
#define SYS_getdents 0x8d
#define SYS_clock_gettime 0x109
// bash
#define SYS_setuid 0x17
#define SYS_geteuid 0x31
#define SYS_getegid 0x32
#define SYS_setgid 0x3e
#endif // __MES_LINUX_X86_SYSCALL_H

View File

@ -69,4 +69,10 @@
#define SYS_getdents 0x4e
#define SYS_clock_gettime 0xe4
// bash
#define SYS_setuid 0x69
#define SYS_setgid 0x6a
#define SYS_geteuid 0x6b
#define SYS_getegid 0x6c
#endif // __MES_LINUX_X86_64_SYSCALL_H

View File

@ -36,6 +36,9 @@ struct passwd
char *pw_shell;
};
struct passwd * getpwuid ();
#endif // ! WITH_GLIBC
#endif // __MES_PWD_H

View File

@ -108,11 +108,17 @@ typedef long ptrdiff_t;
#define LONG_MAX INT_MAX
#define UINT_MAX UINT32_MAX
#define ULONG_MAX UINT32_MAX
#define LLONG_MIN INT64_MIN
#define LLONG_MAX INT64_MAX
#define SIZE_MAX UINT32_MAX
#elif __x86_64__
#define LONG_MIN INT64_MIN
#define LONG_MAX INT64_MAX
#define UINT_MAX UINT32_MAX
#define ULONG_MAX UINT64_MAX
#define LLONG_MIN INT64_MIN
#define LLONG_MAX INT64_MAX
#define SIZE_MAX UINT64_MAX
#endif
#endif // ! WITH_GLIBC

View File

@ -42,6 +42,7 @@ int setenv (char const* s, char const* v, int overwrite_p);
void unsetenv (char const *name);
void *malloc (size_t);
void qsort (void *base, size_t nmemb, size_t size, int (*compar)(void const *, void const *));
int rand (void);
void *realloc (void *p, size_t size);
double strtod (char const *string, char **tailptr);
float strtof (char const *string, char **tailptr);

View File

@ -45,6 +45,7 @@ typedef unsigned long size_t;
typedef long ssize_t;
#endif
void * memchr (void const *block, int c, size_t size);
void *memcpy (void *dest, void const *src, size_t n);
void *memmove (void *dest, void const *src, size_t n);
void *memset (void *s, int c, size_t n);

View File

@ -101,6 +101,17 @@ int stat (char const *file_name, struct stat *buf);
#define S_IWUSR 00200
#define S_IRUSR 00400
#define S_ISUID 0400
#define S_ISGID 02000
#define S_IXGRP 00010
#define S_IXOTH 00001
#define S_IRGRP 00040
#define S_IROTH 00004
#define S_IWGRP 00020
#define S_IWOTH 00002
#define S_IRWXG 00070
#define S_IRWXO 00007
#endif // ! WITH_GLIBC
#endif // __MES_SYS_STAT_H

64
include/termio.h Normal file
View File

@ -0,0 +1,64 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef __MES_TERMIO_H
#define __MES_TERMIO_H 1
#if WITH_GLIBC
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#undef __MES_TERMIO_H
#include_next <termio.h>
#else // ! WITH_GLIBC
#define TIOCGWINSZ 0x5413
#define TCGETA 0x5405
#define TCSETAW 0x5407
#define VTIME 5
#define VMIN 6
#define ISIG 0000001
#define ICANON 0000002
#define ECHO 0000010
#define ECHOK 0000040
#define ECHONL 0000100
#define ISTRIP 0000040
#define INLCR 0000100
#define ICRNL 0000400
#define CS8 0000060
#define PARENB 0000400
struct termio
{
unsigned short c_iflag;
unsigned short c_oflag;
unsigned short c_cflag;
unsigned short c_lflag;
unsigned char c_line;
unsigned char c_cc[8];
};
#endif // ! WITH_GLIBC
#endif // __MES_TERMIO_H

View File

@ -29,6 +29,8 @@
#else // ! WITH_GLIBC
#define _POSIX_VERSION 199009L
#include <sys/types.h>
#ifndef NULL
#define NULL 0
@ -62,8 +64,12 @@ int execve (char const *file, char *const argv[], char *const env[]);
int execvp (char const *file, char *const argv[]);
int fork (void);
char *getcwd (char *buf, size_t size);
gid_t getgid (void);
uid_t getuid (void);
gid_t getgid (void);
int setgid (gid_t newgid);
int setuid (uid_t newuid);
uid_t geteuid (void);
gid_t getegid (void);
int isatty (int fd);
int link (char const *oldname, char const *newname);
off_t lseek (int fd, off_t offset, int whence);

View File

@ -113,3 +113,8 @@
#include <stub/sigblock.c>
#include <stub/sigaddset.c>
#include <stub/setlocale.c>
// bash
#include <stub/getpwuid.c>
#include <stub/rand.c>
#include <stub/ttyname.c>

View File

@ -173,3 +173,28 @@ chdir (char const *file_name)
{
return _sys_call1 (SYS_chdir, (long)file_name);
}
// bash
uid_t
geteuid ()
{
return _sys_call (SYS_geteuid);
}
gid_t
getegid ()
{
return _sys_call (SYS_getegid);
}
int
setuid (uid_t newuid)
{
return _sys_call1 (SYS_setuid, (long)newuid);
}
int
setgid (gid_t newgid)
{
return _sys_call1 (SYS_setgid, (long)newgid);
}

34
lib/string/memchr.c Normal file
View File

@ -0,0 +1,34 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <string.h>
void *
memchr (void const *block, int c, size_t size)
{
char const *p = block;
while (size--)
{
if (c == *p)
return p;
p++;
}
return 0;
}

33
lib/stub/getpwuid.c Normal file
View File

@ -0,0 +1,33 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <libmes.h>
#include <pwd.h>
struct passwd *
getpwuid ()
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("getpwuid stub\n");
stub = 1;
errno = 0;
return 0;
}

33
lib/stub/rand.c Normal file
View File

@ -0,0 +1,33 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <libmes.h>
#include <pwd.h>
int
rand (void)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("rand stub\n");
stub = 1;
errno = 0;
return 0;
}

35
lib/stub/ttyname.c Normal file
View File

@ -0,0 +1,35 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <libmes.h>
#include <unistd.h>
char *
ttyname (int filedes)
{
static int stub = 0;
if (__mes_debug () && !stub)
eputs ("ttyname stub\n");
stub = 1;
errno = 0;
if (isatty (filedes))
return "/dev/tty0";
return 0;
}