Skip to content

Commit

Permalink
LibC: Implement enough missing stuff to get bash-5.0 running. :^)
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Feb 8, 2019
1 parent 5158bee commit 736e852
Show file tree
Hide file tree
Showing 26 changed files with 125 additions and 37 deletions.
1 change: 0 additions & 1 deletion Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,6 @@ bool Process::validate_write(void* address, size_t size) const
if (check_kernel_memory_access(LinearAddress((dword)address), true))
return true;
}
ASSERT(size);
if (!size)
return false;
LinearAddress first_address((dword)address);
Expand Down
2 changes: 1 addition & 1 deletion Launcher/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.o
*.d
FontEditor
Launcher
Binary file removed Launcher/Launcher
Binary file not shown.
1 change: 1 addition & 0 deletions LibC/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ LIBC_OBJS = \
gui.o \
sys/select.o \
poll.o \
locale.o \
entry.o

ASM_OBJS = setjmp.no
Expand Down
25 changes: 25 additions & 0 deletions LibC/fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ __BEGIN_DECLS
#define O_ 00400000
#define O_CLOEXEC 02000000

#define S_IFMT 0170000
#define S_IFDIR 0040000
#define S_IFCHR 0020000
#define S_IFBLK 0060000
#define S_IFREG 0100000
#define S_IFIFO 0010000
#define S_IFLNK 0120000
#define S_IFSOCK 0140000

#define S_ISUID 04000
#define S_ISGID 02000
#define S_ISVTX 01000
#define S_IRUSR 0400
#define S_IWUSR 0200
#define S_IXUSR 0100
#define S_IRGRP 0040
#define S_IWGRP 0020
#define S_IXGRP 0010
#define S_IROTH 0004
#define S_IWOTH 0002
#define S_IXOTH 0001

#define S_IRWXG (S_IRWXU >> 3)
#define S_IRWXO (S_IRWXG >> 3)

int fcntl(int fd, int cmd, ...);

__END_DECLS
Empty file added LibC/float.h
Empty file.
13 changes: 13 additions & 0 deletions LibC/locale.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <locale.h>
#include <assert.h>
#include <stdio.h>

extern "C" {

char* setlocale(int category, const char* locale)
{
dbgprintf("FIXME(LibC): setlocale(%d, %s)\n", category, locale);
return nullptr;
}

}
1 change: 1 addition & 0 deletions LibC/locale.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
enum {
LC_ALL,
LC_NUMERIC,
LC_CTYPE,
};

__BEGIN_DECLS
Expand Down
4 changes: 2 additions & 2 deletions LibC/setjmp.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global setjmp
setjmp:
mov eax, [esp + 4]
mov [eax * 4], ebx
mov [eax + 0 * 4], ebx
mov [eax + 1 * 4], esi
mov [eax + 2 * 4], edi
mov [eax + 3 * 4], ebp
Expand All @@ -18,7 +18,7 @@ global longjmp
longjmp:
mov edx, [esp + 4]
mov eax, [esp + 8]
mov ebx, [edx * 4]
mov ebx, [edx + 0 * 4]
mov esi, [edx + 1 * 4]
mov edi, [edx + 2 * 4]
mov ebp, [edx + 3 * 4]
Expand Down
8 changes: 8 additions & 0 deletions LibC/stat.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <sys/stat.h>
#include <errno.h>
#include <assert.h>
#include <stdio.h>
#include <Kernel/Syscall.h>

extern "C" {
Expand All @@ -21,5 +23,11 @@ int chmod(const char* pathname, mode_t mode)
__RETURN_WITH_ERRNO(rc, rc, -1);
}

int fchmod(int fd, mode_t mode)
{
dbgprintf("FIXME(LibC): fchmod(%d, %o)\n", fd, mode);
ASSERT_NOT_REACHED();
}

}

13 changes: 13 additions & 0 deletions LibC/stdbool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <sys/cdefs.h>

__BEGIN_DECLS

#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_Defined 1

__END_DECLS

2 changes: 2 additions & 0 deletions LibC/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ typedef signed int int32_t;
typedef signed short int16_t;
typedef signed char int8_t;

typedef uint32_t uintptr_t;

#define INT8_MIN (-128)
#define INT16_MIN (-32767-1)
#define INT32_MIN (-2147483647-1)
Expand Down
6 changes: 6 additions & 0 deletions LibC/stdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,5 +365,11 @@ int fclose(FILE* stream)
return rc;
}

int rename(const char* oldpath, const char* newpath)
{
dbgprintf("FIXME(LibC): rename(%s, %s)\n", oldpath, newpath);
ASSERT_NOT_REACHED();
}

}

1 change: 1 addition & 0 deletions LibC/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ int fscanf(FILE*, const char* fmt, ...);
int setvbuf(FILE*, char* buf, int mode, size_t);
void setbuf(FILE*, char* buf);
void setlinebuf(FILE*);
int rename(const char* oldpath, const char* newpath);

__END_DECLS

11 changes: 11 additions & 0 deletions LibC/stdlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ int system(const char* command)
return execl("/bin/sh", "sh", "-c", command, nullptr);
}

char* mktemp(char*)
{
ASSERT_NOT_REACHED();
}

void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, int (*compar)(const void *, const void *))
{
dbgprintf("FIXME(LibC): bsearch(%p, %p, %u, %u, %p)\n", key, base, nmemb, size, compar);
ASSERT_NOT_REACHED();
}

div_t div(int numerator, int denominator)
{
div_t result;
Expand Down
3 changes: 3 additions & 0 deletions LibC/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __BEGIN_DECLS

#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#define MB_CUR_MAX 1

void* malloc(size_t) __MALLOC;
void free(void*);
Expand All @@ -22,6 +23,8 @@ char* ptsname(int fd);
int ptsname_r(int fd, char* buffer, size_t);
int abs(int);
int system(const char* command);
char* mktemp(char*);
void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));

#define RAND_MAX 32767
int rand();
Expand Down
10 changes: 10 additions & 0 deletions LibC/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,15 @@ char* strstr(const char* haystack, const char* needle)
return const_cast<char*>(haystack);
}

char* strpbrk(const char* s, const char* accept)
{
while (*s)
if(strchr(accept, *s++))
return (char*)--s;
return nullptr;
}



}

1 change: 1 addition & 0 deletions LibC/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ size_t strspn(const char*, const char* accept);
size_t strcspn(const char*, const char* reject);
char* strerror(int errnum);
char* strsignal(int signum);
char* strpbrk(const char*, const char* accept);

__END_DECLS

9 changes: 9 additions & 0 deletions LibC/sys/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

#include <sys/cdefs.h>
#include <sys/types.h>
#include <fcntl.h>

__BEGIN_DECLS

#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)

mode_t umask(mode_t);
int chmod(const char* pathname, mode_t);
int fchmod(int fd, mode_t);
int mkdir(const char* pathname, mode_t);

inline dev_t makedev(unsigned int major, unsigned int minor) { return (minor & 0xffu) | (major << 8u) | ((minor & ~0xffu) << 12u); }
Expand Down
5 changes: 4 additions & 1 deletion LibC/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ struct tm* localtime(const time_t* t)
return &tm_buf;
}

long timezone = 0;
long timezone;
long altzone;
char* tzname[2];
int daylight;

void tzset()
{
Expand Down
3 changes: 3 additions & 0 deletions LibC/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ struct tm {
};

extern long timezone;
extern long altzone;
extern char* tzname[2];
extern int daylight;

int gettimeofday(struct timeval*, struct timezone* tz);
struct tm* localtime(const time_t*);
Expand Down
1 change: 0 additions & 1 deletion LibC/ulimit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ long ulimit(int cmd, long newlimit)
}

}

5 changes: 5 additions & 0 deletions LibC/unistd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <Kernel/Syscall.h>
Expand Down Expand Up @@ -186,6 +187,10 @@ int chdir(const char* path)

char* getcwd(char* buffer, size_t size)
{
if (!buffer) {
size = size ? size : PATH_MAX;
buffer = (char*)malloc(size);
}
int rc = syscall(SC_getcwd, buffer, size);
__RETURN_WITH_ERRNO(rc, buffer, nullptr);
}
Expand Down
35 changes: 4 additions & 31 deletions LibC/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,10 @@ enum {

#define HOST_NAME_MAX 64

#define S_IFMT 0170000
#define S_IFDIR 0040000
#define S_IFCHR 0020000
#define S_IFBLK 0060000
#define S_IFREG 0100000
#define S_IFIFO 0010000
#define S_IFLNK 0120000
#define S_IFSOCK 0140000

#define S_ISUID 04000
#define S_ISGID 02000
#define S_ISVTX 01000
#define S_IRUSR 0400
#define S_IWUSR 0200
#define S_IXUSR 0100
#define S_IRGRP 0040
#define S_IWGRP 0020
#define S_IXGRP 0010
#define S_IROTH 0004
#define S_IWOTH 0002
#define S_IXOTH 0001

#define S_IRWXG (S_IRWXU >> 3)
#define S_IRWXO (S_IRWXG >> 3)

#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
#define R_OK 4
#define W_OK 2
#define X_OK 1
#define F_OK 0

__END_DECLS

1 change: 1 addition & 0 deletions Userland/ls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string.h>
#include <getopt.h>
#include <time.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <AK/AKString.h>
Expand Down
1 change: 1 addition & 0 deletions Userland/sh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <fcntl.h>
#include <termios.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <AK/FileSystemPath.h>

Expand Down

0 comments on commit 736e852

Please sign in to comment.