Explorar el Código

A bunch of LibC boilerplate stuff added while trying to get figlet to build.

Andreas Kling hace 6 años
padre
commit
bb90c8ecab
Se han modificado 23 ficheros con 117 adiciones y 45 borrados
  1. 1 1
      LibC/Makefile
  2. 4 2
      LibC/assert.h
  3. 4 0
      LibC/ctype.h
  4. 4 3
      LibC/dirent.h
  5. 15 0
      LibC/entry.cpp
  6. 3 2
      LibC/errno.h
  7. 0 0
      LibC/fcntl.h
  8. 5 3
      LibC/mman.h
  9. 4 2
      LibC/process.h
  10. 3 3
      LibC/signal.h
  11. 4 2
      LibC/stdarg.h
  12. 6 6
      LibC/stdio.cpp
  13. 19 2
      LibC/stdio.h
  14. 4 3
      LibC/stdlib.h
  15. 4 3
      LibC/string.h
  16. 10 0
      LibC/sys/cdefs.h
  17. 0 0
      LibC/sys/ioctl.h
  18. 0 0
      LibC/sys/stat.h
  19. 10 2
      LibC/sys/types.h
  20. 4 3
      LibC/time.h
  21. 6 4
      LibC/unistd.h
  22. 5 2
      LibC/utsname.h
  23. 2 2
      Userland/Makefile

+ 1 - 1
LibC/Makefile

@@ -23,7 +23,7 @@ OBJS = $(AK_OBJS) $(LIBC_OBJS)
 
 LIBRARY = LibC.a
 ARCH_FLAGS =
-STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib
+STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
 LIBC_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
 WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
 FLAVOR_FLAGS = -fomit-frame-pointer -mregparm=3 -march=i386 -m32 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -fmerge-all-constants -fno-unroll-loops -falign-functions=1 -falign-jumps=1 -falign-loops=1 -fno-pie -fno-pic

+ 4 - 2
LibC/assert.h

@@ -1,6 +1,8 @@
 #pragma once
 
-extern "C" {
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
 
 void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func);
 
@@ -10,5 +12,5 @@ void __assertion_failed(const char* msg, const char* file, unsigned line, const
 #define RELEASE_ASSERT assert
 #define ASSERT_NOT_REACHED() assert(false)
 
-}
+__END_DECLS
 

+ 4 - 0
LibC/ctype.h

@@ -0,0 +1,4 @@
+#pragma once
+
+#define isascii(c)    (((c) & ~0x7f) == 0)
+

+ 4 - 3
LibC/dirent.h

@@ -1,8 +1,9 @@
 #pragma once
 
-#include "types.h"
+#include <sys/cdefs.h>
+#include <sys/types.h>
 
-extern "C" {
+__BEGIN_DECLS
 
 struct dirent {
     ino_t d_ino;
@@ -23,5 +24,5 @@ struct DIR {
 DIR* opendir(const char* name);
 dirent* readdir(DIR* dirp);
 
-}
+__END_DECLS
 

+ 15 - 0
LibC/entry.cpp

@@ -1,14 +1,29 @@
+#include <stdio.h>
 #include <Kernel/Syscall.h>
 #include <AK/StringImpl.h>
 
 extern "C" int main(int, char**);
 
+FILE __default_streams[3];
+
 int errno;
+FILE* stdin;
+FILE* stdout;
+FILE* stderr;
 
 extern "C" int _start()
 {
     errno = 0;
 
+    __default_streams[0].fd = 0;
+    stdin = &__default_streams[0];
+
+    __default_streams[1].fd = 1;
+    stdout = &__default_streams[1];
+
+    __default_streams[2].fd = 2;
+    stderr = &__default_streams[2];
+
     StringImpl::initializeGlobals();
 
     int argc;

+ 3 - 2
LibC/errno.h

@@ -1,5 +1,6 @@
 #pragma once
 
+#include <sys/cdefs.h>
 #include <Kernel/errno.h>
 
 #define __RETURN_WITH_ERRNO(rc, good_ret, bad_ret) \
@@ -13,9 +14,9 @@
         } \
     } while(0)
 
-extern "C" {
+__BEGIN_DECLS
 
 extern int errno;
 
-};
+__END_DECLS
 

+ 0 - 0
LibC/fcntl.h


+ 5 - 3
LibC/mman.h

@@ -1,11 +1,13 @@
 #pragma once
 
-#include "types.h"
+#include <sys/cdefs.h>
+#include <sys/types.h>
 
-extern "C" {
+__BEGIN_DECLS
 
 void* mmap(void*, size_t);
 int munmap(void*, size_t);
 int set_mmap_name(void*, size_t, const char*);
 
-}
+__END_DECLS
+

+ 4 - 2
LibC/process.h

@@ -1,8 +1,10 @@
 #pragma once
 
-extern "C" {
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
 
 int spawn(const char* path, const char** args);
 
-}
+__END_DECLS
 

+ 3 - 3
LibC/signal.h

@@ -1,8 +1,8 @@
 #pragma once
 
-#include "types.h"
+#include <sys/types.h>
 
-extern "C" {
+__BEGIN_DECLS
 
 int kill(pid_t, int sig);
 
@@ -22,5 +22,5 @@ int kill(pid_t, int sig);
 #define SIGALRM  14
 #define SIGTERM  15
 
-}
+__END_DECLS
 

+ 4 - 2
LibC/stdarg.h

@@ -1,6 +1,8 @@
 #pragma once
 
-extern "C" {
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
 
 typedef char* va_list;
 
@@ -8,5 +10,5 @@ typedef char* va_list;
 #define va_arg(ap, t) ((t*)(ap += sizeof(t)))[-1]
 #define va_end(ap) ap = nullptr
 
-}
+__END_DECLS
 

+ 6 - 6
LibC/stdio.cpp

@@ -1,9 +1,9 @@
-#include "stdio.h"
-#include "stdarg.h"
-#include "types.h"
-#include "string.h"
-#include "errno.h"
-#include "unistd.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include <sys/types.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
 #include <Kernel/Syscall.h>
 #include <AK/printf.cpp>
 

+ 19 - 2
LibC/stdio.h

@@ -1,11 +1,28 @@
 #pragma once
 
-extern "C" {
+#include <sys/cdefs.h>
 
+__BEGIN_DECLS
+
+#ifndef EOF
+#define EOF (-1)
+#endif
+
+struct __STDIO_FILE {
+    int fd;
+};
+
+typedef struct __STDIO_FILE FILE;
+
+extern FILE* stdin;
+extern FILE* stdout;
+extern FILE* stderr;
+
+int fprintf(FILE*, const char* fmt, ...);
 int printf(const char* fmt, ...);
 int sprintf(char* buffer, const char* fmt, ...);
 int putchar(int ch);
 void perror(const char*);
 
-}
+__END_DECLS
 

+ 4 - 3
LibC/stdlib.h

@@ -1,8 +1,9 @@
 #pragma once
 
-#include "types.h"
+#include <sys/cdefs.h>
+#include <sys/types.h>
 
-extern "C" {
+__BEGIN_DECLS
 
 void* malloc(size_t);
 void free(void*);
@@ -12,5 +13,5 @@ void* realloc(void *ptr, size_t);
 void exit(int status);
 void abort();
 
-}
+__END_DECLS
 

+ 4 - 3
LibC/string.h

@@ -1,8 +1,9 @@
 #pragma once
 
-#include "types.h"
+#include <sys/cdefs.h>
+#include <sys/types.h>
 
-extern "C" {
+__BEGIN_DECLS
 
 size_t strlen(const char*);
 int strcmp(const char*, const char*);
@@ -10,5 +11,5 @@ int memcmp(const void*, const void*, size_t);
 void memcpy(void*, const void*, size_t);
 const char* strerror(int errnum);
 
-}
+__END_DECLS
 

+ 10 - 0
LibC/sys/cdefs.h

@@ -0,0 +1,10 @@
+#pragma once
+
+#ifdef __cplusplus
+#define __BEGIN_DECLS extern "C" {
+#define __END_DECLS }
+#else
+#define __BEGIN_DECLS
+#define __END_DECLS
+#endif
+

+ 0 - 0
LibC/sys/ioctl.h


+ 0 - 0
LibC/sys/stat.h


+ 10 - 2
LibC/types.h → LibC/sys/types.h

@@ -1,6 +1,8 @@
 #pragma once
 
-extern "C" {
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
 
 typedef unsigned int dword;
 typedef unsigned short word;
@@ -49,5 +51,11 @@ struct stat {
     time_t    st_ctime;   /* time of last status change */
 };
 
-}
+#ifdef __cplusplus
+#define NULL nullptr
+#else
+#define NULL 0
+#endif
+
+__END_DECLS
 

+ 4 - 3
LibC/time.h

@@ -1,11 +1,12 @@
 #pragma once
 
-#include "types.h"
+#include <sys/cdefs.h>
+#include <sys/types.h>
 
-extern "C" {
+__BEGIN_DECLS
 
 int gettimeofday(timeval*);
 time_t time(time_t*);
 
-}
+__END_DECLS
 

+ 6 - 4
LibC/unistd.h

@@ -1,8 +1,9 @@
 #pragma once
 
-#include "types.h"
+#include <sys/cdefs.h>
+#include <sys/types.h>
 
-extern "C" {
+__BEGIN_DECLS
 
 uid_t getuid();
 gid_t getgid();
@@ -14,7 +15,7 @@ int close(int fd);
 pid_t waitpid(pid_t, int* wstatus, int options);
 int chdir(const char* path);
 char* getcwd(char* buffer, size_t size);
-int lstat(const char* path, stat* statbuf);
+int lstat(const char* path, struct stat* statbuf);
 int sleep(unsigned seconds);
 int gethostname(char*, size_t);
 ssize_t readlink(const char* path, char* buffer, size_t);
@@ -62,4 +63,5 @@ int ttyname_r(int fd, char* buffer, size_t);
 #define O_DIRECTORY 00200000
 #define O_NOFOLLOW 00400000
 
-}
+__END_DECLS
+

+ 5 - 2
LibC/utsname.h

@@ -1,8 +1,10 @@
 #pragma once
 
+#include <sys/cdefs.h>
+
 #define UTSNAME_ENTRY_LEN 65
 
-extern "C" {
+__BEGIN_DECLS
 
 struct utsname {
     char sysname[UTSNAME_ENTRY_LEN];
@@ -14,4 +16,5 @@ struct utsname {
 
 int uname(struct utsname*);
 
-}
+__END_DECLS
+

+ 2 - 2
Userland/Makefile

@@ -35,12 +35,12 @@ APPS = \
        kill
 
 ARCH_FLAGS =
-STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib
+STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
 USERLAND_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
 WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
 FLAVOR_FLAGS = -march=i386 -mregparm=3 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
 OPTIMIZATION_FLAGS = -Os -fno-asynchronous-unwind-tables
-INCLUDE_FLAGS = -I.. -I.
+INCLUDE_FLAGS = -I.. -I. -I../LibC
 
 DEFINES = -DSERENITY -DSANITIZE_PTRS -DUSERLAND