mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:57:35 +00:00
A bunch of LibC boilerplate stuff added while trying to get figlet to build.
This commit is contained in:
parent
511ed4c4de
commit
bb90c8ecab
23 changed files with 117 additions and 45 deletions
|
@ -23,7 +23,7 @@ OBJS = $(AK_OBJS) $(LIBC_OBJS)
|
||||||
|
|
||||||
LIBRARY = LibC.a
|
LIBRARY = LibC.a
|
||||||
ARCH_FLAGS =
|
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
|
LIBC_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
|
||||||
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
|
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
|
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
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
extern "C" {
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func);
|
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 RELEASE_ASSERT assert
|
||||||
#define ASSERT_NOT_REACHED() assert(false)
|
#define ASSERT_NOT_REACHED() assert(false)
|
||||||
|
|
||||||
}
|
__END_DECLS
|
||||||
|
|
||||||
|
|
4
LibC/ctype.h
Normal file
4
LibC/ctype.h
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define isascii(c) (((c) & ~0x7f) == 0)
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types.h"
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
extern "C" {
|
__BEGIN_DECLS
|
||||||
|
|
||||||
struct dirent {
|
struct dirent {
|
||||||
ino_t d_ino;
|
ino_t d_ino;
|
||||||
|
@ -23,5 +24,5 @@ struct DIR {
|
||||||
DIR* opendir(const char* name);
|
DIR* opendir(const char* name);
|
||||||
dirent* readdir(DIR* dirp);
|
dirent* readdir(DIR* dirp);
|
||||||
|
|
||||||
}
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,29 @@
|
||||||
|
#include <stdio.h>
|
||||||
#include <Kernel/Syscall.h>
|
#include <Kernel/Syscall.h>
|
||||||
#include <AK/StringImpl.h>
|
#include <AK/StringImpl.h>
|
||||||
|
|
||||||
extern "C" int main(int, char**);
|
extern "C" int main(int, char**);
|
||||||
|
|
||||||
|
FILE __default_streams[3];
|
||||||
|
|
||||||
int errno;
|
int errno;
|
||||||
|
FILE* stdin;
|
||||||
|
FILE* stdout;
|
||||||
|
FILE* stderr;
|
||||||
|
|
||||||
extern "C" int _start()
|
extern "C" int _start()
|
||||||
{
|
{
|
||||||
errno = 0;
|
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();
|
StringImpl::initializeGlobals();
|
||||||
|
|
||||||
int argc;
|
int argc;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
#include <Kernel/errno.h>
|
#include <Kernel/errno.h>
|
||||||
|
|
||||||
#define __RETURN_WITH_ERRNO(rc, good_ret, bad_ret) \
|
#define __RETURN_WITH_ERRNO(rc, good_ret, bad_ret) \
|
||||||
|
@ -13,9 +14,9 @@
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
extern "C" {
|
__BEGIN_DECLS
|
||||||
|
|
||||||
extern int errno;
|
extern int errno;
|
||||||
|
|
||||||
};
|
__END_DECLS
|
||||||
|
|
||||||
|
|
0
LibC/fcntl.h
Normal file
0
LibC/fcntl.h
Normal file
|
@ -1,11 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types.h"
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
extern "C" {
|
__BEGIN_DECLS
|
||||||
|
|
||||||
void* mmap(void*, size_t);
|
void* mmap(void*, size_t);
|
||||||
int munmap(void*, size_t);
|
int munmap(void*, size_t);
|
||||||
int set_mmap_name(void*, size_t, const char*);
|
int set_mmap_name(void*, size_t, const char*);
|
||||||
|
|
||||||
}
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
extern "C" {
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
int spawn(const char* path, const char** args);
|
int spawn(const char* path, const char** args);
|
||||||
|
|
||||||
}
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types.h"
|
#include <sys/types.h>
|
||||||
|
|
||||||
extern "C" {
|
__BEGIN_DECLS
|
||||||
|
|
||||||
int kill(pid_t, int sig);
|
int kill(pid_t, int sig);
|
||||||
|
|
||||||
|
@ -22,5 +22,5 @@ int kill(pid_t, int sig);
|
||||||
#define SIGALRM 14
|
#define SIGALRM 14
|
||||||
#define SIGTERM 15
|
#define SIGTERM 15
|
||||||
|
|
||||||
}
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
extern "C" {
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
typedef char* va_list;
|
typedef char* va_list;
|
||||||
|
|
||||||
|
@ -8,5 +10,5 @@ typedef char* va_list;
|
||||||
#define va_arg(ap, t) ((t*)(ap += sizeof(t)))[-1]
|
#define va_arg(ap, t) ((t*)(ap += sizeof(t)))[-1]
|
||||||
#define va_end(ap) ap = nullptr
|
#define va_end(ap) ap = nullptr
|
||||||
|
|
||||||
}
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include "stdio.h"
|
#include <stdio.h>
|
||||||
#include "stdarg.h"
|
#include <stdarg.h>
|
||||||
#include "types.h"
|
#include <sys/types.h>
|
||||||
#include "string.h"
|
#include <string.h>
|
||||||
#include "errno.h"
|
#include <errno.h>
|
||||||
#include "unistd.h"
|
#include <unistd.h>
|
||||||
#include <Kernel/Syscall.h>
|
#include <Kernel/Syscall.h>
|
||||||
#include <AK/printf.cpp>
|
#include <AK/printf.cpp>
|
||||||
|
|
||||||
|
|
21
LibC/stdio.h
21
LibC/stdio.h
|
@ -1,11 +1,28 @@
|
||||||
#pragma once
|
#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 printf(const char* fmt, ...);
|
||||||
int sprintf(char* buffer, const char* fmt, ...);
|
int sprintf(char* buffer, const char* fmt, ...);
|
||||||
int putchar(int ch);
|
int putchar(int ch);
|
||||||
void perror(const char*);
|
void perror(const char*);
|
||||||
|
|
||||||
}
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types.h"
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
extern "C" {
|
__BEGIN_DECLS
|
||||||
|
|
||||||
void* malloc(size_t);
|
void* malloc(size_t);
|
||||||
void free(void*);
|
void free(void*);
|
||||||
|
@ -12,5 +13,5 @@ void* realloc(void *ptr, size_t);
|
||||||
void exit(int status);
|
void exit(int status);
|
||||||
void abort();
|
void abort();
|
||||||
|
|
||||||
}
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types.h"
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
extern "C" {
|
__BEGIN_DECLS
|
||||||
|
|
||||||
size_t strlen(const char*);
|
size_t strlen(const char*);
|
||||||
int strcmp(const char*, 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);
|
void memcpy(void*, const void*, size_t);
|
||||||
const char* strerror(int errnum);
|
const char* strerror(int errnum);
|
||||||
|
|
||||||
}
|
__END_DECLS
|
||||||
|
|
||||||
|
|
10
LibC/sys/cdefs.h
Normal file
10
LibC/sys/cdefs.h
Normal file
|
@ -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
LibC/sys/ioctl.h
Normal file
0
LibC/sys/ioctl.h
Normal file
0
LibC/sys/stat.h
Normal file
0
LibC/sys/stat.h
Normal file
|
@ -1,6 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
extern "C" {
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
typedef unsigned int dword;
|
typedef unsigned int dword;
|
||||||
typedef unsigned short word;
|
typedef unsigned short word;
|
||||||
|
@ -49,5 +51,11 @@ struct stat {
|
||||||
time_t st_ctime; /* time of last status change */
|
time_t st_ctime; /* time of last status change */
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
#ifdef __cplusplus
|
||||||
|
#define NULL nullptr
|
||||||
|
#else
|
||||||
|
#define NULL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types.h"
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
extern "C" {
|
__BEGIN_DECLS
|
||||||
|
|
||||||
int gettimeofday(timeval*);
|
int gettimeofday(timeval*);
|
||||||
time_t time(time_t*);
|
time_t time(time_t*);
|
||||||
|
|
||||||
}
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types.h"
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
extern "C" {
|
__BEGIN_DECLS
|
||||||
|
|
||||||
uid_t getuid();
|
uid_t getuid();
|
||||||
gid_t getgid();
|
gid_t getgid();
|
||||||
|
@ -14,7 +15,7 @@ int close(int fd);
|
||||||
pid_t waitpid(pid_t, int* wstatus, int options);
|
pid_t waitpid(pid_t, int* wstatus, int options);
|
||||||
int chdir(const char* path);
|
int chdir(const char* path);
|
||||||
char* getcwd(char* buffer, size_t size);
|
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 sleep(unsigned seconds);
|
||||||
int gethostname(char*, size_t);
|
int gethostname(char*, size_t);
|
||||||
ssize_t readlink(const char* path, char* buffer, 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_DIRECTORY 00200000
|
||||||
#define O_NOFOLLOW 00400000
|
#define O_NOFOLLOW 00400000
|
||||||
|
|
||||||
}
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
#define UTSNAME_ENTRY_LEN 65
|
#define UTSNAME_ENTRY_LEN 65
|
||||||
|
|
||||||
extern "C" {
|
__BEGIN_DECLS
|
||||||
|
|
||||||
struct utsname {
|
struct utsname {
|
||||||
char sysname[UTSNAME_ENTRY_LEN];
|
char sysname[UTSNAME_ENTRY_LEN];
|
||||||
|
@ -14,4 +16,5 @@ struct utsname {
|
||||||
|
|
||||||
int uname(struct utsname*);
|
int uname(struct utsname*);
|
||||||
|
|
||||||
}
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -35,12 +35,12 @@ APPS = \
|
||||||
kill
|
kill
|
||||||
|
|
||||||
ARCH_FLAGS =
|
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
|
USERLAND_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
|
||||||
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
|
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
|
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
|
OPTIMIZATION_FLAGS = -Os -fno-asynchronous-unwind-tables
|
||||||
INCLUDE_FLAGS = -I.. -I.
|
INCLUDE_FLAGS = -I.. -I. -I../LibC
|
||||||
|
|
||||||
DEFINES = -DSERENITY -DSANITIZE_PTRS -DUSERLAND
|
DEFINES = -DSERENITY -DSANITIZE_PTRS -DUSERLAND
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue