mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 16:37:35 +00:00
LibC: Enough compat work to make binutils-2.32 build and run.
This commit is contained in:
parent
d7753c7c8d
commit
a7a456002e
14 changed files with 110 additions and 45 deletions
|
@ -19,7 +19,7 @@ struct [[gnu::packed]] allocation_t {
|
||||||
size_t nchunk;
|
size_t nchunk;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CHUNK_SIZE 64
|
#define CHUNK_SIZE 32
|
||||||
#define POOL_SIZE (1024 * 1024)
|
#define POOL_SIZE (1024 * 1024)
|
||||||
|
|
||||||
#define ETERNAL_BASE_PHYSICAL 0x100000
|
#define ETERNAL_BASE_PHYSICAL 0x100000
|
||||||
|
|
|
@ -4,7 +4,7 @@ if [ $(id -u) != 0 ]; then
|
||||||
fi
|
fi
|
||||||
rm -vf _fs_contents.lock
|
rm -vf _fs_contents.lock
|
||||||
rm -vf _fs_contents
|
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
|
mke2fs _fs_contents
|
||||||
chown 1000:1000 _fs_contents
|
chown 1000:1000 _fs_contents
|
||||||
mkdir -vp mnt
|
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/1 mnt/dev/stdout
|
||||||
ln -s /proc/self/fd/2 mnt/dev/stderr
|
ln -s /proc/self/fd/2 mnt/dev/stderr
|
||||||
cp -vR ../Base/* mnt/
|
cp -vR ../Base/* mnt/
|
||||||
|
cp -vR ../Root/* mnt/
|
||||||
mkdir mnt/home/anon
|
mkdir mnt/home/anon
|
||||||
mkdir mnt/home/nona
|
mkdir mnt/home/nona
|
||||||
chown -vR 100:100 mnt/home/anon
|
chown -vR 100:100 mnt/home/anon
|
||||||
|
|
|
@ -1,28 +1,3 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.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;
|
|
||||||
}
|
|
||||||
|
|
62
LibC/ctype.h
62
LibC/ctype.h
|
@ -1,52 +1,86 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
||||||
ALWAYS_INLINE int isascii(int ch)
|
ALWAYS_INLINE int __isascii(int ch)
|
||||||
{
|
{
|
||||||
return (ch & ~0x7f) == 0;
|
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';
|
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';
|
return c >= 'a' && c <= 'z';
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE int isupper(int c)
|
ALWAYS_INLINE int __isupper(int c)
|
||||||
{
|
{
|
||||||
return c >= 'A' && c <= 'Z';
|
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 | 0x20;
|
||||||
return c;
|
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 & ~0x20;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE int isdigit(int c)
|
ALWAYS_INLINE int __isdigit(int c)
|
||||||
{
|
{
|
||||||
return c >= '0' && c <= '9';
|
return c >= '0' && c <= '9';
|
||||||
}
|
}
|
||||||
|
|
||||||
int isalpha(int c);
|
ALWAYS_INLINE int __ispunct(int c)
|
||||||
int isalnum(int c);
|
{
|
||||||
int ispunct(int c);
|
const char* punctuation_characters = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
|
||||||
int isprint(int c);
|
return !!strchr(punctuation_characters, c);
|
||||||
int iscntrl(int 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
|
__END_DECLS
|
||||||
|
|
|
@ -5,3 +5,12 @@
|
||||||
#define PRId8 "d"
|
#define PRId8 "d"
|
||||||
#define PRId16 "d"
|
#define PRId16 "d"
|
||||||
#define PRId32 "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"
|
||||||
|
|
|
@ -6,6 +6,7 @@ enum {
|
||||||
LC_ALL,
|
LC_ALL,
|
||||||
LC_NUMERIC,
|
LC_NUMERIC,
|
||||||
LC_CTYPE,
|
LC_CTYPE,
|
||||||
|
LC_COLLATE,
|
||||||
};
|
};
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
|
@ -18,6 +18,12 @@ int killpg(int pgrp, int sig)
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
__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)
|
sighandler_t signal(int signum, sighandler_t handler)
|
||||||
{
|
{
|
||||||
struct sigaction new_act;
|
struct sigaction new_act;
|
||||||
|
|
|
@ -33,6 +33,7 @@ int sigdelset(sigset_t*, int sig);
|
||||||
int sigismember(const sigset_t*, int sig);
|
int sigismember(const sigset_t*, int sig);
|
||||||
int sigprocmask(int how, const sigset_t* set, sigset_t* old_set);
|
int sigprocmask(int how, const sigset_t* set, sigset_t* old_set);
|
||||||
int sigpending(sigset_t*);
|
int sigpending(sigset_t*);
|
||||||
|
int raise(int sig);
|
||||||
|
|
||||||
#define NSIG 32
|
#define NSIG 32
|
||||||
extern const char* sys_siglist[NSIG];
|
extern const char* sys_siglist[NSIG];
|
||||||
|
|
|
@ -149,11 +149,12 @@ void __malloc_init()
|
||||||
perror("set_mmap_name failed");
|
perror("set_mmap_name failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void* calloc(size_t nmemb, size_t)
|
void* calloc(size_t count, size_t size)
|
||||||
{
|
{
|
||||||
(void) nmemb;
|
size_t new_size = count * size;
|
||||||
ASSERT_NOT_REACHED();
|
auto* ptr = malloc(new_size);
|
||||||
return nullptr;
|
memset(ptr, 0, new_size);
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* realloc(void *ptr, size_t size)
|
void* realloc(void *ptr, size_t size)
|
||||||
|
@ -200,6 +201,11 @@ char* getenv(const char* name)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double atof(const char*)
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
int atoi(const char* str)
|
int atoi(const char* str)
|
||||||
{
|
{
|
||||||
size_t len = strlen(str);
|
size_t len = strlen(str);
|
||||||
|
@ -298,4 +304,9 @@ ldiv_t ldiv(long numerator, long denominator)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t mbstowcs(wchar_t*, const char*, size_t)
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,16 @@ struct tm* localtime(const time_t* t)
|
||||||
return &tm_buf;
|
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 timezone;
|
||||||
long altzone;
|
long altzone;
|
||||||
char* tzname[2];
|
char* tzname[2];
|
||||||
|
|
|
@ -14,6 +14,11 @@
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
|
int chown(const char* pathname, uid_t owner, gid_t group)
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
pid_t fork()
|
pid_t fork()
|
||||||
{
|
{
|
||||||
int rc = syscall(SC_fork);
|
int rc = syscall(SC_fork);
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
#define HZ 1000
|
||||||
|
|
||||||
extern char** environ;
|
extern char** environ;
|
||||||
|
|
||||||
int create_shared_buffer(pid_t peer_pid, size_t, void** buffer);
|
int create_shared_buffer(pid_t peer_pid, size_t, void** buffer);
|
||||||
|
|
0
LibC/wchar.h
Normal file
0
LibC/wchar.h
Normal file
|
@ -263,10 +263,20 @@ static int try_exec(const char* path, char** argv)
|
||||||
int ret = execve(path, argv, environ);
|
int ret = execve(path, argv, environ);
|
||||||
assert(ret < 0);
|
assert(ret < 0);
|
||||||
|
|
||||||
|
{
|
||||||
const char* search_path = "/bin";
|
const char* search_path = "/bin";
|
||||||
char pathbuf[128];
|
char pathbuf[128];
|
||||||
sprintf(pathbuf, "%s/%s", search_path, argv[0]);
|
sprintf(pathbuf, "%s/%s", search_path, argv[0]);
|
||||||
ret = execve(pathbuf, argv, environ);
|
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)
|
if (ret == -1)
|
||||||
return -1;
|
return -1;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue