Skip to content

Commit

Permalink
Lots of minor compat stuff while seeing if bash would build.
Browse files Browse the repository at this point in the history
We're quite far from bash building, but we'll get there eventually!
  • Loading branch information
awesomekling committed Nov 5, 2018
1 parent e461124 commit e76312a
Show file tree
Hide file tree
Showing 21 changed files with 172 additions and 38 deletions.
1 change: 1 addition & 0 deletions LibC/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ LIBC_OBJS = \
getopt.o \
scanf.o \
pwd.o \
times.o \
entry.o

OBJS = $(AK_OBJS) $(LIBC_OBJS)
Expand Down
11 changes: 11 additions & 0 deletions LibC/endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <sys/cdefs.h>

__BEGIN_DECLS

#define LITTLE_ENDIAN 1234
#define BIG_ENDIAN 4321
#define BYTE_ORDER LITTLE_ENDIAN

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

#include <sys/cdefs.h>

__BEGIN_DECLS

#define F_DUPFD 0
#define F_GETFD 1
#define F_SETFD 2
#define F_GETFL 3
#define F_SETFL 4

__END_DECLS
4 changes: 2 additions & 2 deletions LibC/scanf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static int vsscanf(const char *buf, const char *s, va_list ap)
for (tc = s; isdigit(*s); s++);
strncpy (tmp, tc, s - tc);
tmp[s - tc] = '\0';
atob ((dword*)&width, tmp, 10);
atob ((uint32_t*)&width, tmp, 10);
s--;
}
}
Expand Down Expand Up @@ -232,7 +232,7 @@ static int vsscanf(const char *buf, const char *s, va_list ap)
tmp[width] = '\0';
buf += width;
if (!noassign)
atob(va_arg(ap, dword*), tmp, base);
atob(va_arg(ap, uint32_t*), tmp, base);
}
if (!noassign)
++count;
Expand Down
Empty file added LibC/setjmp.cpp
Empty file.
13 changes: 13 additions & 0 deletions LibC/setjmp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

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

__BEGIN_DECLS

typedef uint32_t jmp_buf[6];

int setjmp(jmp_buf);
void longjmp(jmp_buf, int val);

__END_DECLS
5 changes: 3 additions & 2 deletions LibC/signal.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "unistd.h"
#include "errno.h"
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <Kernel/Syscall.h>

extern "C" {
Expand Down
23 changes: 23 additions & 0 deletions LibC/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,31 @@

__BEGIN_DECLS

typedef void (*__sighandler_t)(int);
typedef __sighandler_t sighandler_t;

typedef uint32_t sigset_t;
typedef void siginfo_t;

struct sigaction {
void (*sa_handler)(int);
void (*sa_sigaction)(int, siginfo_t*, void*);
sigset_t sa_mask;
int sa_flags;
void (*sa_restorer)(void);
};

int kill(pid_t, int sig);

#define SIG_DFL ((__sighandler_t)0)
#define SIG_ERR ((__sighandler_t)-1)
#define SIG_IGN ((__sighandler_t)1)

#define SIG_BLOCK 0
#define SIG_UNBLOCK 1
#define SIG_SETMASK 2


#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
Expand Down
Empty file added LibC/stddef.h
Empty file.
16 changes: 16 additions & 0 deletions LibC/stdint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <sys/cdefs.h>

__BEGIN_DECLS

typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;

typedef signed int int32_t;
typedef signed short int16_t;
typedef signed char int8_t;

__END_DECLS

1 change: 1 addition & 0 deletions LibC/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ int sprintf(char* buffer, const char* fmt, ...);
int putchar(int ch);
void perror(const char*);
int sscanf (const char* buf, const char* fmt, ...);
int fscanf(FILE*, const char* fmt, ...);

__END_DECLS

6 changes: 3 additions & 3 deletions LibC/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern "C" {

void* memset(void* dest, int c, size_t n)
{
byte* bdest = (byte*)dest;
uint8_t* bdest = (uint8_t*)dest;
for (; n; --n)
*(bdest++) = c;
return dest;
Expand Down Expand Up @@ -57,8 +57,8 @@ int strcmp(const char* s1, const char* s2)

int memcmp(const void* v1, const void* v2, size_t n)
{
auto* s1 = (const byte*)v1;
auto* s2 = (const byte*)v2;
auto* s1 = (const uint8_t*)v1;
auto* s2 = (const uint8_t*)v2;
while (n-- > 0) {
if (*s1++ != *s2++)
return s1[-1] < s2[-1] ? -1 : 1;
Expand Down
2 changes: 2 additions & 0 deletions LibC/sys/cdefs.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#define _POSIX_VERSION 200809L

#define ALWAYS_INLINE inline __attribute__ ((always_inline))
#define __NORETURN __attribute__ ((noreturn))

Expand Down
4 changes: 4 additions & 0 deletions LibC/sys/param.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

#include <endian.h>

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

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

__BEGIN_DECLS

struct tms {
clock_t tms_utime;
clock_t tms_stime;
clock_t tms_cutime;
clock_t tms_cstime;
};

clock_t times(struct tms*);

__END_DECLS
37 changes: 16 additions & 21 deletions LibC/sys/types.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
#pragma once

#include <sys/cdefs.h>
#include <stdint.h>

__BEGIN_DECLS

typedef unsigned int dword;
typedef unsigned short word;
typedef unsigned char byte;

typedef signed int signed_dword;
typedef signed short signed_word;
typedef signed char signed_byte;

typedef dword uid_t;
typedef dword gid_t;
typedef uint32_t uid_t;
typedef uint32_t gid_t;
typedef int pid_t;

typedef dword size_t;
typedef signed_dword ssize_t;
typedef uint32_t size_t;
typedef int32_t ssize_t;

typedef uint32_t ino_t;
typedef int32_t off_t;

typedef dword ino_t;
typedef signed_dword off_t;
typedef uint32_t dev_t;
typedef uint32_t mode_t;
typedef uint32_t nlink_t;
typedef uint32_t blksize_t;
typedef uint32_t blkcnt_t;
typedef uint32_t time_t;
typedef uint32_t suseconds_t;

typedef dword dev_t;
typedef dword mode_t;
typedef dword nlink_t;
typedef dword blksize_t;
typedef dword blkcnt_t;
typedef dword time_t;
typedef dword suseconds_t;
typedef uint32_t clock_t;

struct timeval {
time_t tv_sec;
Expand Down
7 changes: 4 additions & 3 deletions LibC/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ extern "C" {

time_t time(time_t* tloc)
{
timeval tv;
if (gettimeofday(&tv) < 0)
struct timeval tv;
struct timezone tz;
if (gettimeofday(&tv, &tz) < 0)
return (time_t)-1;
return tv.tv_sec;
}

int gettimeofday(timeval* tv)
int gettimeofday(struct timeval* tv, struct timezone*)
{
int rc = Syscall::invoke(Syscall::PosixGettimeofday, (dword)tv);
__RETURN_WITH_ERRNO(rc, rc, -1);
Expand Down
7 changes: 6 additions & 1 deletion LibC/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

__BEGIN_DECLS

int gettimeofday(timeval*);
typedef struct timezone {
int tz_minuteswest;
int tz_dsttime;
};

int gettimeofday(struct timeval*, struct timezone* tz);
time_t time(time_t*);

__END_DECLS
Expand Down
8 changes: 8 additions & 0 deletions LibC/times.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <sys/times.h>
#include <assert.h>

clock_t times(struct tms*)
{
assert(false);
return 0;
}
25 changes: 20 additions & 5 deletions LibC/unistd.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "unistd.h"
#include "string.h"
#include "errno.h"
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include <assert.h>
#include <Kernel/Syscall.h>

extern "C" {
Expand Down Expand Up @@ -78,9 +80,12 @@ pid_t getpgrp()
__RETURN_WITH_ERRNO(rc, rc, -1);
}

int open(const char* path, int options)
int open(const char* path, int options, ...)
{
int rc = Syscall::invoke(Syscall::PosixOpen, (dword)path, (dword)options);
va_list ap;
va_start(ap, options);
int rc = Syscall::invoke(Syscall::PosixOpen, (dword)path, (dword)options, (dword)ap);
va_end(ap);
__RETURN_WITH_ERRNO(rc, rc, -1);
}

Expand Down Expand Up @@ -169,5 +174,15 @@ off_t lseek(int fd, off_t offset, int whence)
__RETURN_WITH_ERRNO(rc, rc, -1);
}

int link(const char*, const char*)
{
assert(false);
}

int unlink(const char*)
{
assert(false);
}

}

10 changes: 9 additions & 1 deletion LibC/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gid_t getgid();
pid_t getpid();
pid_t tcgetpgrp(int fd);
int tcsetpgrp(int fd, pid_t pgid);
int open(const char* path, int options);
int open(const char* path, int options, ...);
ssize_t read(int fd, void* buf, size_t count);
ssize_t write(int fd, const void* buf, size_t count);
int close(int fd);
Expand All @@ -37,6 +37,8 @@ ssize_t readlink(const char* path, char* buffer, size_t);
char* ttyname(int fd);
int ttyname_r(int fd, char* buffer, size_t);
off_t lseek(int fd, off_t, int whence);
int link(const char* oldpath, const char* newpath);
int unlink(const char* pathname);

#define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
#define WTERMSIG(status) ((status) & 0x7f)
Expand Down Expand Up @@ -83,6 +85,12 @@ off_t lseek(int fd, off_t, int whence);
#define O_RDONLY 0
#define O_WRONLY 1
#define O_RDWR 2
#define O_CREAT 0100
#define O_EXCL 0200
#define O_NOCTTY 0400
#define O_TRUNC 01000
#define O_APPEND 02000
#define O_NONBLOCK 04000
#define O_DIRECTORY 00200000
#define O_ 00400000

Expand Down

0 comments on commit e76312a

Please sign in to comment.