Преглед на файлове

LibC: Enough compat work to make binutils-2.32 build and run.

Andreas Kling преди 6 години
родител
ревизия
a7a456002e
променени са 14 файла, в които са добавени 110 реда и са изтрити 45 реда
  1. 1 1
      Kernel/kmalloc.cpp
  2. 2 1
      Kernel/sync.sh
  3. 0 25
      LibC/ctype.cpp
  4. 48 14
      LibC/ctype.h
  5. 9 0
      LibC/inttypes.h
  6. 1 0
      LibC/locale.h
  7. 6 0
      LibC/signal.cpp
  8. 1 0
      LibC/signal.h
  9. 15 4
      LibC/stdlib.cpp
  10. 10 0
      LibC/time.cpp
  11. 5 0
      LibC/unistd.cpp
  12. 2 0
      LibC/unistd.h
  13. 0 0
      LibC/wchar.h
  14. 10 0
      Userland/sh.cpp

+ 1 - 1
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

+ 2 - 1
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

+ 0 - 25
LibC/ctype.cpp

@@ -1,28 +1,3 @@
 #include <ctype.h>
 #include <string.h>
 
-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;
-}

+ 48 - 14
LibC/ctype.h

@@ -1,52 +1,86 @@
 #pragma once
 
 #include <sys/cdefs.h>
+#include <string.h>
 
 __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

+ 9 - 0
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"

+ 1 - 0
LibC/locale.h

@@ -6,6 +6,7 @@ enum {
     LC_ALL,
     LC_NUMERIC,
     LC_CTYPE,
+    LC_COLLATE,
 };
 
 __BEGIN_DECLS

+ 6 - 0
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;

+ 1 - 0
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];

+ 15 - 4
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);
+}
+
 }

+ 10 - 0
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];

+ 5 - 0
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);

+ 2 - 0
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);

+ 0 - 0
LibC/wchar.h


+ 10 - 0
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;