1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:47:35 +00:00

Compat work towards porting vim.

This commit is contained in:
Andreas Kling 2019-02-26 15:57:59 +01:00
parent 2e5b9d318f
commit a356746d04
17 changed files with 200 additions and 77 deletions

View file

@ -8,6 +8,7 @@ int main(int, char**);
int errno;
char** environ;
//bool __environ_is_malloced;
void __malloc_init();
void __stdio_init();
@ -16,6 +17,7 @@ int _start(int argc, char** argv, char** env)
{
errno = 0;
environ = env;
//__environ_is_malloced = false;
__stdio_init();
__malloc_init();

View file

@ -1,3 +1,16 @@
#include <ctype.h>
#include <string.h>
int __tolower(int c)
{
if (c >= 'A' && c <= 'Z')
return c | 0x20;
return c;
}
int __toupper(int c)
{
if (c >= 'a' && c <= 'z')
return c & ~0x20;
return c;
}

View file

@ -25,19 +25,8 @@ ALWAYS_INLINE int __isupper(int c)
return c >= 'A' && c <= 'Z';
}
ALWAYS_INLINE int __tolower(int c)
{
if (__isupper(c))
return c | 0x20;
return c;
}
ALWAYS_INLINE int __toupper(int c)
{
if (__islower(c))
return c & ~0x20;
return c;
}
int __tolower(int);
int __toupper(int);
ALWAYS_INLINE int __isdigit(int c)
{

View file

@ -102,10 +102,38 @@ int sigpending(sigset_t* set)
}
const char* sys_siglist[NSIG] = {
#undef __SIGNAL
#define __SIGNAL(a, b) b,
__ENUMERATE_ALL_SIGNALS
#undef __SIGNAL
"Invalid signal number",
"Hangup",
"Interrupt",
"Quit",
"Illegal instruction",
"Trap",
"Aborted",
"Bus error",
"FP exception",
"Killed",
"User signal 1",
"Segmentation violation",
"User signal 2",
"Broken pipe",
"Alarm clock",
"Terminated",
"Stack fault",
"Child exited",
"Continued",
"Stopped (signal)",
"Stopped",
"Stopped (tty input)",
"Stopped (tty output)",
"Urgent I/O condition)",
"CPU limit exceeded",
"File size limit exceeded",
"Virtual timer expired",
"Profiling timer expired",
"Window changed",
"I/O possible",
"Power failure",
"Bad system call",
};
int sigsetjmp(jmp_buf env, int savesigs)

View file

@ -35,7 +35,6 @@ int sigprocmask(int how, const sigset_t* set, sigset_t* old_set);
int sigpending(sigset_t*);
int raise(int sig);
#define NSIG 32
extern const char* sys_siglist[NSIG];
#define SIG_DFL ((__sighandler_t)0)

View file

@ -1,44 +1,35 @@
#pragma once
#define __ENUMERATE_ALL_SIGNALS \
__SIGNAL(SIGINVAL, "Invalid signal number") \
__SIGNAL(SIGHUP, "Hangup") \
__SIGNAL(SIGINT, "Interrupt") \
__SIGNAL(SIGQUIT, "Quit") \
__SIGNAL(SIGILL, "Illegal instruction") \
__SIGNAL(SIGTRAP, "Trap") \
__SIGNAL(SIGABRT, "Aborted") \
__SIGNAL(SIGBUS, "Bus error") \
__SIGNAL(SIGFPE, "FP exception") \
__SIGNAL(SIGKILL, "Killed") \
__SIGNAL(SIGUSR1, "User signal 1") \
__SIGNAL(SIGSEGV, "Segmentation violation") \
__SIGNAL(SIGUSR2, "User signal 2") \
__SIGNAL(SIGPIPE, "Broken pipe") \
__SIGNAL(SIGALRM, "Alarm clock") \
__SIGNAL(SIGTERM, "Terminated") \
__SIGNAL(SIGSTKFLT, "Stack fault") \
__SIGNAL(SIGCHLD, "Child exited") \
__SIGNAL(SIGCONT, "Continued") \
__SIGNAL(SIGSTOP, "Stopped (signal)") \
__SIGNAL(SIGTSTP, "Stopped") \
__SIGNAL(SIGTTIN, "Stopped (tty input)") \
__SIGNAL(SIGTTOU, "Stopped (tty output)") \
__SIGNAL(SIGURG, "Urgent I/O condition)") \
__SIGNAL(SIGXCPU, "CPU limit exceeded") \
__SIGNAL(SIGXFSZ, "File size limit exceeded") \
__SIGNAL(SIGVTALRM, "Virtual timer expired") \
__SIGNAL(SIGPROF, "Profiling timer expired") \
__SIGNAL(SIGWINCH, "Window changed") \
__SIGNAL(SIGIO, "I/O possible") \
__SIGNAL(SIGPWR, "Power failure") \
__SIGNAL(SIGSYS, "Bad system call") \
enum __signal_numbers {
#undef __SIGNAL
#define __SIGNAL(a, b) a,
__ENUMERATE_ALL_SIGNALS
#undef __SIGNAL
__signal_count
};
#define SIGINVAL 0
#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SIGTRAP 5
#define SIGABRT 6
#define SIGBUS 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGUSR1 10
#define SIGSEGV 11
#define SIGUSR2 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGSTKFLT 16
#define SIGCHLD 17
#define SIGCONT 18
#define SIGSTOP 19
#define SIGTSTP 20
#define SIGTTIN 21
#define SIGTTOU 22
#define SIGURG 23
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define SIGWINCH 28
#define SIGIO 29
#define SIGPWR 30
#define SIGSYS 31
#define NSIG 32

View file

@ -10,6 +10,8 @@
#include <AK/Types.h>
#include <Kernel/Syscall.h>
#include <AK/StdLibExtras.h>
#include <AK/HashMap.h>
#include <AK/AKString.h>
extern "C" {
@ -31,8 +33,8 @@ struct MallocFooter {
uint32_t xorcheck;
};
#define CHUNK_SIZE 8
#define POOL_SIZE 128 * 1024
#define CHUNK_SIZE 16
#define POOL_SIZE 4 * 1048576
static const size_t malloc_budget = POOL_SIZE;
static byte s_malloc_map[POOL_SIZE / CHUNK_SIZE / 8];
@ -201,13 +203,56 @@ char* getenv(const char* name)
return nullptr;
}
int putenv(char*)
int putenv(char* new_var)
{
assert(false);
HashMap<String, String> environment;
auto handle_environment_entry = [&environment] (const char* decl) {
char* eq = strchr(decl, '=');
if (!eq)
return;
size_t var_length = eq - decl;
char* var = (char*)alloca(var_length + 1);
memcpy(var, decl, var_length);
var[var_length] = '\0';
const char* value = eq + 1;
environment.set(var, value);
};
for (size_t i = 0; environ[i]; ++i)
handle_environment_entry(environ[i]);
handle_environment_entry(new_var);
//extern bool __environ_is_malloced;
//if (__environ_is_malloced)
// free(environ);
//__environ_is_malloced = true;
int environment_size = sizeof(char*); // For the null sentinel.
for (auto& it : environment)
environment_size += (int)sizeof(char*) + it.key.length() + 1 + it.value.length() + 1;
char* buffer = (char*)malloc(environment_size);
environ = (char**)buffer;
char* bufptr = buffer + sizeof(char*) * (environment.size() + 1);
int i = 0;
for (auto& it : environment) {
environ[i] = bufptr;
memcpy(bufptr, it.key.characters(), it.key.length());
bufptr += it.key.length();
*(bufptr++) = '=';
memcpy(bufptr, it.value.characters(), it.value.length());
bufptr += it.value.length();
*(bufptr++) = '\0';
++i;
}
environ[environment.size()] = nullptr;
return 0;
}
double atof(const char*)
double atof(const char* str)
{
dbgprintf("LibC: atof: '%s'\n", str);
assert(false);
}

View file

@ -260,7 +260,7 @@ char* strerror(int errnum)
char* strsignal(int signum)
{
if (signum >= __signal_count) {
if (signum >= NSIG) {
printf("strsignal() missing string for signum=%d\n", signum);
return const_cast<char*>("Unknown signal");
}

View file

@ -1,16 +1,36 @@
#include <strings.h>
#include <assert.h>
#include <ctype.h>
extern "C" {
int strcasecmp(const char*, const char*)
static char foldcase(char ch)
{
assert(false);
if (isalpha(ch))
return tolower(ch);
return ch;
}
int strncasecmp(const char*, const char*, size_t)
int strcasecmp(const char* s1, const char* s2)
{
assert(false);
for (; foldcase(*s1) == foldcase(*s2); ++s1, ++s2) {
if (*s1 == 0)
return 0;
}
return foldcase(*(const unsigned char*)s1) < foldcase(*(const unsigned char*)s2) ? -1 : 1;
}
int strncasecmp(const char* s1, const char* s2, size_t n)
{
if (!n)
return 0;
do {
if (foldcase(*s1) != foldcase(*s2++))
return foldcase(*(const unsigned char*)s1) - foldcase(*(const unsigned char*)--s2);
if (*s1++ == 0)
break;
} while (--n);
return 0;
}
}

View file

@ -39,9 +39,14 @@ int tcflush(int fd, int queue_selector)
assert(false);
}
speed_t cfgetospeed(const struct termios*)
speed_t cfgetispeed(const struct termios* tp)
{
assert(false);
return tp->c_ispeed;
}
speed_t cfgetospeed(const struct termios* tp)
{
return tp->c_ospeed;
}
}

View file

@ -17,6 +17,8 @@ struct termios {
tcflag_t c_cflag;
tcflag_t c_lflag;
cc_t c_cc[NCCS];
speed_t c_ispeed;
speed_t c_ospeed;
};
int tcgetattr(int fd, struct termios*);