mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 16:35:06 +00:00
Compat work towards porting vim.
This commit is contained in:
parent
2e5b9d318f
commit
a356746d04
17 changed files with 200 additions and 77 deletions
|
@ -389,7 +389,7 @@ PageFaultResponse MemoryManager::handle_page_fault(const PageFault& fault)
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
return PageFaultResponse::Continue;
|
return PageFaultResponse::Continue;
|
||||||
}
|
}
|
||||||
kprintf("PV(error) fault in Region{%p}[%u]\n", region, page_index_in_region);
|
kprintf("PV(error) fault in Region{%p}[%u] at L%x\n", region, page_index_in_region, fault.laddr().get());
|
||||||
} else {
|
} else {
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,7 +226,7 @@ Process* Process::fork(RegisterDump& regs)
|
||||||
|
|
||||||
for (auto& region : m_regions) {
|
for (auto& region : m_regions) {
|
||||||
#ifdef FORK_DEBUG
|
#ifdef FORK_DEBUG
|
||||||
dbgprintf("fork: cloning Region{%p} \"%s\" L%x\n", region.ptr(), region->name.characters(), region->laddr().get());
|
dbgprintf("fork: cloning Region{%p} \"%s\" L%x\n", region.ptr(), region->name().characters(), region->laddr().get());
|
||||||
#endif
|
#endif
|
||||||
auto cloned_region = region->clone();
|
auto cloned_region = region->clone();
|
||||||
child->m_regions.append(move(cloned_region));
|
child->m_regions.append(move(cloned_region));
|
||||||
|
@ -1140,10 +1140,9 @@ int Process::sys$utime(const char* pathname, const utimbuf* buf)
|
||||||
|
|
||||||
int Process::sys$access(const char* pathname, int mode)
|
int Process::sys$access(const char* pathname, int mode)
|
||||||
{
|
{
|
||||||
(void) mode;
|
|
||||||
if (!validate_read_str(pathname))
|
if (!validate_read_str(pathname))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
ASSERT_NOT_REACHED();
|
return VFS::the().access(String(pathname), mode, cwd_inode());
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::sys$fcntl(int fd, int cmd, dword arg)
|
int Process::sys$fcntl(int fd, int cmd, dword arg)
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
#define WNOHANG 1
|
#define WNOHANG 1
|
||||||
|
|
||||||
|
#define R_OK 4
|
||||||
|
#define W_OK 2
|
||||||
|
#define X_OK 1
|
||||||
|
#define F_OK 0
|
||||||
|
|
||||||
#define SIG_DFL ((void*)0)
|
#define SIG_DFL ((void*)0)
|
||||||
#define SIG_ERR ((void*)-1)
|
#define SIG_ERR ((void*)-1)
|
||||||
#define SIG_IGN ((void*)1)
|
#define SIG_IGN ((void*)1)
|
||||||
|
@ -265,6 +270,7 @@ typedef dword blkcnt_t;
|
||||||
|
|
||||||
typedef uint32_t tcflag_t;
|
typedef uint32_t tcflag_t;
|
||||||
typedef uint8_t cc_t;
|
typedef uint8_t cc_t;
|
||||||
|
typedef uint32_t speed_t;
|
||||||
|
|
||||||
struct termios {
|
struct termios {
|
||||||
tcflag_t c_iflag;
|
tcflag_t c_iflag;
|
||||||
|
@ -272,6 +278,8 @@ struct termios {
|
||||||
tcflag_t c_cflag;
|
tcflag_t c_cflag;
|
||||||
tcflag_t c_lflag;
|
tcflag_t c_lflag;
|
||||||
cc_t c_cc[NCCS];
|
cc_t c_cc[NCCS];
|
||||||
|
speed_t c_ispeed;
|
||||||
|
speed_t c_ospeed;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stat {
|
struct stat {
|
||||||
|
|
|
@ -268,6 +268,28 @@ KResult VFS::mkdir(const String& path, mode_t mode, Inode& base)
|
||||||
return KResult(error);
|
return KResult(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KResult VFS::access(const String& path, int mode, Inode& base)
|
||||||
|
{
|
||||||
|
auto inode_or_error = resolve_path_to_inode(path, base);
|
||||||
|
if (inode_or_error.is_error())
|
||||||
|
return inode_or_error.error();
|
||||||
|
auto inode = inode_or_error.value();
|
||||||
|
auto metadata = inode->metadata();
|
||||||
|
if (mode & R_OK) {
|
||||||
|
if (!metadata.may_read(*current))
|
||||||
|
return KResult(-EACCES);
|
||||||
|
}
|
||||||
|
if (mode & W_OK) {
|
||||||
|
if (!metadata.may_write(*current))
|
||||||
|
return KResult(-EACCES);
|
||||||
|
}
|
||||||
|
if (mode & X_OK) {
|
||||||
|
if (!metadata.may_execute(*current))
|
||||||
|
return KResult(-EACCES);
|
||||||
|
}
|
||||||
|
return KSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
KResult VFS::chmod(const String& path, mode_t mode, Inode& base)
|
KResult VFS::chmod(const String& path, mode_t mode, Inode& base)
|
||||||
{
|
{
|
||||||
auto inode_or_error = resolve_path_to_inode(path, base);
|
auto inode_or_error = resolve_path_to_inode(path, base);
|
||||||
|
|
|
@ -70,6 +70,7 @@ public:
|
||||||
bool unlink(const String& path, Inode& base, int& error);
|
bool unlink(const String& path, Inode& base, int& error);
|
||||||
bool rmdir(const String& path, Inode& base, int& error);
|
bool rmdir(const String& path, Inode& base, int& error);
|
||||||
KResult chmod(const String& path, mode_t, Inode& base);
|
KResult chmod(const String& path, mode_t, Inode& base);
|
||||||
|
KResult access(const String& path, int mode, Inode& base);
|
||||||
bool stat(const String& path, int& error, int options, Inode& base, struct stat&);
|
bool stat(const String& path, int& error, int options, Inode& base, struct stat&);
|
||||||
KResult utime(const String& path, Inode& base, time_t atime, time_t mtime);
|
KResult utime(const String& path, Inode& base, time_t atime, time_t mtime);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ sudo id
|
||||||
|
|
||||||
make_cmd="make -j2"
|
make_cmd="make -j2"
|
||||||
|
|
||||||
rm -r ../Root/usr && \
|
|
||||||
$make_cmd -C ../LibC clean && \
|
$make_cmd -C ../LibC clean && \
|
||||||
$make_cmd -C ../LibC && \
|
$make_cmd -C ../LibC && \
|
||||||
(cd ../LibC && ./install.sh) && \
|
(cd ../LibC && ./install.sh) && \
|
||||||
|
|
|
@ -8,6 +8,7 @@ int main(int, char**);
|
||||||
|
|
||||||
int errno;
|
int errno;
|
||||||
char** environ;
|
char** environ;
|
||||||
|
//bool __environ_is_malloced;
|
||||||
|
|
||||||
void __malloc_init();
|
void __malloc_init();
|
||||||
void __stdio_init();
|
void __stdio_init();
|
||||||
|
@ -16,6 +17,7 @@ int _start(int argc, char** argv, char** env)
|
||||||
{
|
{
|
||||||
errno = 0;
|
errno = 0;
|
||||||
environ = env;
|
environ = env;
|
||||||
|
//__environ_is_malloced = false;
|
||||||
|
|
||||||
__stdio_init();
|
__stdio_init();
|
||||||
__malloc_init();
|
__malloc_init();
|
||||||
|
|
|
@ -1,3 +1,16 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.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;
|
||||||
|
}
|
||||||
|
|
15
LibC/ctype.h
15
LibC/ctype.h
|
@ -25,19 +25,8 @@ ALWAYS_INLINE int __isupper(int c)
|
||||||
return c >= 'A' && c <= 'Z';
|
return c >= 'A' && c <= 'Z';
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE int __tolower(int c)
|
int __tolower(int);
|
||||||
{
|
int __toupper(int);
|
||||||
if (__isupper(c))
|
|
||||||
return c | 0x20;
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
ALWAYS_INLINE int __toupper(int c)
|
|
||||||
{
|
|
||||||
if (__islower(c))
|
|
||||||
return c & ~0x20;
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
ALWAYS_INLINE int __isdigit(int c)
|
ALWAYS_INLINE int __isdigit(int c)
|
||||||
{
|
{
|
||||||
|
|
|
@ -102,10 +102,38 @@ int sigpending(sigset_t* set)
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* sys_siglist[NSIG] = {
|
const char* sys_siglist[NSIG] = {
|
||||||
#undef __SIGNAL
|
"Invalid signal number",
|
||||||
#define __SIGNAL(a, b) b,
|
"Hangup",
|
||||||
__ENUMERATE_ALL_SIGNALS
|
"Interrupt",
|
||||||
#undef __SIGNAL
|
"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)
|
int sigsetjmp(jmp_buf env, int savesigs)
|
||||||
|
|
|
@ -35,7 +35,6 @@ int sigprocmask(int how, const sigset_t* set, sigset_t* old_set);
|
||||||
int sigpending(sigset_t*);
|
int sigpending(sigset_t*);
|
||||||
int raise(int sig);
|
int raise(int sig);
|
||||||
|
|
||||||
#define NSIG 32
|
|
||||||
extern const char* sys_siglist[NSIG];
|
extern const char* sys_siglist[NSIG];
|
||||||
|
|
||||||
#define SIG_DFL ((__sighandler_t)0)
|
#define SIG_DFL ((__sighandler_t)0)
|
||||||
|
|
|
@ -1,44 +1,35 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define __ENUMERATE_ALL_SIGNALS \
|
#define SIGINVAL 0
|
||||||
__SIGNAL(SIGINVAL, "Invalid signal number") \
|
#define SIGHUP 1
|
||||||
__SIGNAL(SIGHUP, "Hangup") \
|
#define SIGINT 2
|
||||||
__SIGNAL(SIGINT, "Interrupt") \
|
#define SIGQUIT 3
|
||||||
__SIGNAL(SIGQUIT, "Quit") \
|
#define SIGILL 4
|
||||||
__SIGNAL(SIGILL, "Illegal instruction") \
|
#define SIGTRAP 5
|
||||||
__SIGNAL(SIGTRAP, "Trap") \
|
#define SIGABRT 6
|
||||||
__SIGNAL(SIGABRT, "Aborted") \
|
#define SIGBUS 7
|
||||||
__SIGNAL(SIGBUS, "Bus error") \
|
#define SIGFPE 8
|
||||||
__SIGNAL(SIGFPE, "FP exception") \
|
#define SIGKILL 9
|
||||||
__SIGNAL(SIGKILL, "Killed") \
|
#define SIGUSR1 10
|
||||||
__SIGNAL(SIGUSR1, "User signal 1") \
|
#define SIGSEGV 11
|
||||||
__SIGNAL(SIGSEGV, "Segmentation violation") \
|
#define SIGUSR2 12
|
||||||
__SIGNAL(SIGUSR2, "User signal 2") \
|
#define SIGPIPE 13
|
||||||
__SIGNAL(SIGPIPE, "Broken pipe") \
|
#define SIGALRM 14
|
||||||
__SIGNAL(SIGALRM, "Alarm clock") \
|
#define SIGTERM 15
|
||||||
__SIGNAL(SIGTERM, "Terminated") \
|
#define SIGSTKFLT 16
|
||||||
__SIGNAL(SIGSTKFLT, "Stack fault") \
|
#define SIGCHLD 17
|
||||||
__SIGNAL(SIGCHLD, "Child exited") \
|
#define SIGCONT 18
|
||||||
__SIGNAL(SIGCONT, "Continued") \
|
#define SIGSTOP 19
|
||||||
__SIGNAL(SIGSTOP, "Stopped (signal)") \
|
#define SIGTSTP 20
|
||||||
__SIGNAL(SIGTSTP, "Stopped") \
|
#define SIGTTIN 21
|
||||||
__SIGNAL(SIGTTIN, "Stopped (tty input)") \
|
#define SIGTTOU 22
|
||||||
__SIGNAL(SIGTTOU, "Stopped (tty output)") \
|
#define SIGURG 23
|
||||||
__SIGNAL(SIGURG, "Urgent I/O condition)") \
|
#define SIGXCPU 24
|
||||||
__SIGNAL(SIGXCPU, "CPU limit exceeded") \
|
#define SIGXFSZ 25
|
||||||
__SIGNAL(SIGXFSZ, "File size limit exceeded") \
|
#define SIGVTALRM 26
|
||||||
__SIGNAL(SIGVTALRM, "Virtual timer expired") \
|
#define SIGPROF 27
|
||||||
__SIGNAL(SIGPROF, "Profiling timer expired") \
|
#define SIGWINCH 28
|
||||||
__SIGNAL(SIGWINCH, "Window changed") \
|
#define SIGIO 29
|
||||||
__SIGNAL(SIGIO, "I/O possible") \
|
#define SIGPWR 30
|
||||||
__SIGNAL(SIGPWR, "Power failure") \
|
#define SIGSYS 31
|
||||||
__SIGNAL(SIGSYS, "Bad system call") \
|
#define NSIG 32
|
||||||
|
|
||||||
|
|
||||||
enum __signal_numbers {
|
|
||||||
#undef __SIGNAL
|
|
||||||
#define __SIGNAL(a, b) a,
|
|
||||||
__ENUMERATE_ALL_SIGNALS
|
|
||||||
#undef __SIGNAL
|
|
||||||
__signal_count
|
|
||||||
};
|
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <Kernel/Syscall.h>
|
#include <Kernel/Syscall.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
|
#include <AK/HashMap.h>
|
||||||
|
#include <AK/AKString.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
|
@ -31,8 +33,8 @@ struct MallocFooter {
|
||||||
uint32_t xorcheck;
|
uint32_t xorcheck;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CHUNK_SIZE 8
|
#define CHUNK_SIZE 16
|
||||||
#define POOL_SIZE 128 * 1024
|
#define POOL_SIZE 4 * 1048576
|
||||||
|
|
||||||
static const size_t malloc_budget = POOL_SIZE;
|
static const size_t malloc_budget = POOL_SIZE;
|
||||||
static byte s_malloc_map[POOL_SIZE / CHUNK_SIZE / 8];
|
static byte s_malloc_map[POOL_SIZE / CHUNK_SIZE / 8];
|
||||||
|
@ -201,13 +203,56 @@ char* getenv(const char* name)
|
||||||
return nullptr;
|
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);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -260,7 +260,7 @@ char* strerror(int errnum)
|
||||||
|
|
||||||
char* strsignal(int signum)
|
char* strsignal(int signum)
|
||||||
{
|
{
|
||||||
if (signum >= __signal_count) {
|
if (signum >= NSIG) {
|
||||||
printf("strsignal() missing string for signum=%d\n", signum);
|
printf("strsignal() missing string for signum=%d\n", signum);
|
||||||
return const_cast<char*>("Unknown signal");
|
return const_cast<char*>("Unknown signal");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,36 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
extern "C" {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,9 +39,14 @@ int tcflush(int fd, int queue_selector)
|
||||||
assert(false);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ struct termios {
|
||||||
tcflag_t c_cflag;
|
tcflag_t c_cflag;
|
||||||
tcflag_t c_lflag;
|
tcflag_t c_lflag;
|
||||||
cc_t c_cc[NCCS];
|
cc_t c_cc[NCCS];
|
||||||
|
speed_t c_ispeed;
|
||||||
|
speed_t c_ospeed;
|
||||||
};
|
};
|
||||||
|
|
||||||
int tcgetattr(int fd, struct termios*);
|
int tcgetattr(int fd, struct termios*);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue