From a7a456002e91d9f13793e23aab4c24519c4e87c7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 23 Feb 2019 17:24:50 +0100 Subject: [PATCH] LibC: Enough compat work to make binutils-2.32 build and run. --- Kernel/kmalloc.cpp | 2 +- Kernel/sync.sh | 3 ++- LibC/ctype.cpp | 25 ------------------- LibC/ctype.h | 62 +++++++++++++++++++++++++++++++++++----------- LibC/inttypes.h | 9 +++++++ LibC/locale.h | 1 + LibC/signal.cpp | 6 +++++ LibC/signal.h | 1 + LibC/stdlib.cpp | 19 +++++++++++--- LibC/time.cpp | 10 ++++++++ LibC/unistd.cpp | 5 ++++ LibC/unistd.h | 2 ++ LibC/wchar.h | 0 Userland/sh.cpp | 10 ++++++++ 14 files changed, 110 insertions(+), 45 deletions(-) create mode 100644 LibC/wchar.h diff --git a/Kernel/kmalloc.cpp b/Kernel/kmalloc.cpp index 3fcd9c92e9..4689a9b196 100644 --- a/Kernel/kmalloc.cpp +++ b/Kernel/kmalloc.cpp @@ -19,7 +19,7 @@ struct [[gnu::packed]] allocation_t { size_t nchunk; }; -#define CHUNK_SIZE 64 +#define CHUNK_SIZE 32 #define POOL_SIZE (1024 * 1024) #define ETERNAL_BASE_PHYSICAL 0x100000 diff --git a/Kernel/sync.sh b/Kernel/sync.sh index c6373007e5..7f63733dca 100755 --- a/Kernel/sync.sh +++ b/Kernel/sync.sh @@ -4,7 +4,7 @@ if [ $(id -u) != 0 ]; then fi rm -vf _fs_contents.lock rm -vf _fs_contents -dd if=/dev/zero of=_fs_contents bs=1M count=12 +dd if=/dev/zero of=_fs_contents bs=1M count=256 mke2fs _fs_contents chown 1000:1000 _fs_contents mkdir -vp mnt @@ -32,6 +32,7 @@ ln -s /proc/self/fd/0 mnt/dev/stdin ln -s /proc/self/fd/1 mnt/dev/stdout ln -s /proc/self/fd/2 mnt/dev/stderr cp -vR ../Base/* mnt/ +cp -vR ../Root/* mnt/ mkdir mnt/home/anon mkdir mnt/home/nona chown -vR 100:100 mnt/home/anon diff --git a/LibC/ctype.cpp b/LibC/ctype.cpp index a443db80cd..ba4eb48a2b 100644 --- a/LibC/ctype.cpp +++ b/LibC/ctype.cpp @@ -1,28 +1,3 @@ #include #include -int ispunct(int c) -{ - const char* punctuation_characters = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; - return !!strchr(punctuation_characters, c); -} - -int isprint(int c) -{ - return c >= 0x20 && c != 0x7f; -} - -int isalnum(int c) -{ - return isalpha(c) || isdigit(c); -} - -int isalpha(int c) -{ - return isupper(c) || islower(c); -} - -int iscntrl(int c) -{ - return (c >= 0 && c <= 0x1f) || c == 0x7f; -} diff --git a/LibC/ctype.h b/LibC/ctype.h index 41178f5cb4..b55860d308 100644 --- a/LibC/ctype.h +++ b/LibC/ctype.h @@ -1,52 +1,86 @@ #pragma once #include +#include __BEGIN_DECLS -ALWAYS_INLINE int isascii(int ch) +ALWAYS_INLINE int __isascii(int ch) { return (ch & ~0x7f) == 0; } -ALWAYS_INLINE int isspace(int ch) +ALWAYS_INLINE int __isspace(int ch) { return ch == ' ' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\v'; } -ALWAYS_INLINE int islower(int c) +ALWAYS_INLINE int __islower(int c) { return c >= 'a' && c <= 'z'; } -ALWAYS_INLINE int isupper(int c) +ALWAYS_INLINE int __isupper(int c) { return c >= 'A' && c <= 'Z'; } -ALWAYS_INLINE int tolower(int c) +ALWAYS_INLINE int __tolower(int c) { - if (isupper(c)) + if (__isupper(c)) return c | 0x20; return c; } -ALWAYS_INLINE int toupper(int c) +ALWAYS_INLINE int __toupper(int c) { - if (islower(c)) + if (__islower(c)) return c & ~0x20; return c; } -ALWAYS_INLINE int isdigit(int c) +ALWAYS_INLINE int __isdigit(int c) { return c >= '0' && c <= '9'; } -int isalpha(int c); -int isalnum(int c); -int ispunct(int c); -int isprint(int c); -int iscntrl(int c); +ALWAYS_INLINE int __ispunct(int c) +{ + const char* punctuation_characters = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; + return !!strchr(punctuation_characters, c); +} + +ALWAYS_INLINE int __isprint(int c) +{ + return c >= 0x20 && c != 0x7f; +} + +ALWAYS_INLINE int __isalpha(int c) +{ + return __isupper(c) || __islower(c); +} + +ALWAYS_INLINE int __isalnum(int c) +{ + return __isalpha(c) || __isdigit(c); +} + +ALWAYS_INLINE int __iscntrl(int c) +{ + return (c >= 0 && c <= 0x1f) || c == 0x7f; +} + +#define isascii(c) __isascii(c) +#define isspace(c) __isspace(c) +#define islower(c) __islower(c) +#define isupper(c) __isupper(c) +#define tolower(c) __tolower(c) +#define toupper(c) __toupper(c) +#define isdigit(c) __isdigit(c) +#define ispunct(c) __ispunct(c) +#define isprint(c) __isprint(c) +#define isalpha(c) __isalpha(c) +#define isalnum(c) __isalnum(c) +#define iscntrl(c) __iscntrl(c) __END_DECLS diff --git a/LibC/inttypes.h b/LibC/inttypes.h index 1510aa0920..d0b8ec0509 100644 --- a/LibC/inttypes.h +++ b/LibC/inttypes.h @@ -5,3 +5,12 @@ #define PRId8 "d" #define PRId16 "d" #define PRId32 "d" +#define PRId64 "lld" +#define PRIu8 "u" +#define PRIu16 "u" +#define PRIu32 "u" +#define PRIu64 "llu" +#define PRIx8 "b" +#define PRIx16 "w" +#define PRIx32 "x" +#define PRIx64 "llx" diff --git a/LibC/locale.h b/LibC/locale.h index 5243769a83..2d79ce935a 100644 --- a/LibC/locale.h +++ b/LibC/locale.h @@ -6,6 +6,7 @@ enum { LC_ALL, LC_NUMERIC, LC_CTYPE, + LC_COLLATE, }; __BEGIN_DECLS diff --git a/LibC/signal.cpp b/LibC/signal.cpp index 9e74466793..7e0c6c394e 100644 --- a/LibC/signal.cpp +++ b/LibC/signal.cpp @@ -18,6 +18,12 @@ int killpg(int pgrp, int sig) __RETURN_WITH_ERRNO(rc, rc, -1); } +int raise(int sig) +{ + // FIXME: Support multi-threaded programs. + return kill(getpid(), sig); +} + sighandler_t signal(int signum, sighandler_t handler) { struct sigaction new_act; diff --git a/LibC/signal.h b/LibC/signal.h index f13cf62c27..2977c7e802 100644 --- a/LibC/signal.h +++ b/LibC/signal.h @@ -33,6 +33,7 @@ int sigdelset(sigset_t*, int sig); int sigismember(const sigset_t*, int sig); 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]; diff --git a/LibC/stdlib.cpp b/LibC/stdlib.cpp index 2b03f9e59b..359c9f62a3 100644 --- a/LibC/stdlib.cpp +++ b/LibC/stdlib.cpp @@ -149,11 +149,12 @@ void __malloc_init() perror("set_mmap_name failed"); } -void* calloc(size_t nmemb, size_t) +void* calloc(size_t count, size_t size) { - (void) nmemb; - ASSERT_NOT_REACHED(); - return nullptr; + size_t new_size = count * size; + auto* ptr = malloc(new_size); + memset(ptr, 0, new_size); + return ptr; } void* realloc(void *ptr, size_t size) @@ -200,6 +201,11 @@ char* getenv(const char* name) return nullptr; } +double atof(const char*) +{ + assert(false); +} + int atoi(const char* str) { size_t len = strlen(str); @@ -298,4 +304,9 @@ ldiv_t ldiv(long numerator, long denominator) return result; } +size_t mbstowcs(wchar_t*, const char*, size_t) +{ + assert(false); +} + } diff --git a/LibC/time.cpp b/LibC/time.cpp index 9c3ddaa0dd..9a6992a666 100644 --- a/LibC/time.cpp +++ b/LibC/time.cpp @@ -83,6 +83,16 @@ struct tm* localtime(const time_t* t) return &tm_buf; } +struct tm* gmtime(const time_t* t) +{ + return localtime(t); +} + +size_t strftime(char *s, size_t max, const char *format, const struct tm *tm) +{ + assert(false); +} + long timezone; long altzone; char* tzname[2]; diff --git a/LibC/unistd.cpp b/LibC/unistd.cpp index 6ae189210c..ac00004d2f 100644 --- a/LibC/unistd.cpp +++ b/LibC/unistd.cpp @@ -14,6 +14,11 @@ extern "C" { +int chown(const char* pathname, uid_t owner, gid_t group) +{ + assert(false); +} + pid_t fork() { int rc = syscall(SC_fork); diff --git a/LibC/unistd.h b/LibC/unistd.h index 35c1c7a755..20b524592d 100644 --- a/LibC/unistd.h +++ b/LibC/unistd.h @@ -6,6 +6,8 @@ __BEGIN_DECLS +#define HZ 1000 + extern char** environ; int create_shared_buffer(pid_t peer_pid, size_t, void** buffer); diff --git a/LibC/wchar.h b/LibC/wchar.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Userland/sh.cpp b/Userland/sh.cpp index 9ac70d36f8..c5795853eb 100644 --- a/Userland/sh.cpp +++ b/Userland/sh.cpp @@ -263,10 +263,20 @@ static int try_exec(const char* path, char** argv) int ret = execve(path, argv, environ); assert(ret < 0); + { const char* search_path = "/bin"; char pathbuf[128]; sprintf(pathbuf, "%s/%s", search_path, argv[0]); ret = execve(pathbuf, argv, environ); + assert(ret < 0); + } + + { + const char* search_path = "/usr/bin"; + char pathbuf[128]; + sprintf(pathbuf, "%s/%s", search_path, argv[0]); + ret = execve(pathbuf, argv, environ); + } if (ret == -1) return -1; return ret;