Skip to content

Commit

Permalink
More compat work.
Browse files Browse the repository at this point in the history
Move syscall to int 0x82 since using int 0x80 was kinda prone to fork bombs
when building things on Linux. :^)
  • Loading branch information
awesomekling committed Feb 26, 2019
1 parent f6b41d1 commit cccc8d8
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,8 @@ ShouldUnblockProcess Process::dispatch_signal(byte signal)
*code_ptr++ = 0xb8; // mov eax, <dword>
*(dword*)code_ptr = Syscall::SC_sigreturn;
code_ptr += sizeof(dword);
*code_ptr++ = 0xcd; // int 0x80
*code_ptr++ = 0x80;
*code_ptr++ = 0xcd; // int 0x82
*code_ptr++ = 0x82;
*code_ptr++ = 0x0f; // ud2
*code_ptr++ = 0x0b;

Expand Down
4 changes: 2 additions & 2 deletions Kernel/Syscall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace Syscall {

void initialize()
{
register_user_callable_interrupt_handler(0x80, syscall_trap_handler);
kprintf("Syscall: int 0x80 handler installed\n");
register_user_callable_interrupt_handler(0x82, syscall_trap_handler);
kprintf("Syscall: int 0x82 handler installed\n");
}

int sync()
Expand Down
8 changes: 4 additions & 4 deletions Kernel/Syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,31 +131,31 @@ int sync();
inline dword invoke(Function function)
{
dword result;
asm volatile("int $0x80":"=a"(result):"a"(function):"memory");
asm volatile("int $0x82":"=a"(result):"a"(function):"memory");
return result;
}

template<typename T1>
inline dword invoke(Function function, T1 arg1)
{
dword result;
asm volatile("int $0x80":"=a"(result):"a"(function),"d"((dword)arg1):"memory");
asm volatile("int $0x82":"=a"(result):"a"(function),"d"((dword)arg1):"memory");
return result;
}

template<typename T1, typename T2>
inline dword invoke(Function function, T1 arg1, T2 arg2)
{
dword result;
asm volatile("int $0x80":"=a"(result):"a"(function),"d"((dword)arg1),"c"((dword)arg2):"memory");
asm volatile("int $0x82":"=a"(result):"a"(function),"d"((dword)arg1),"c"((dword)arg2):"memory");
return result;
}

template<typename T1, typename T2, typename T3>
inline dword invoke(Function function, T1 arg1, T2 arg2, T3 arg3)
{
dword result;
asm volatile("int $0x80":"=a"(result):"a"(function),"d"((dword)arg1),"c"((dword)arg2),"b"((dword)arg3):"memory");
asm volatile("int $0x82":"=a"(result):"a"(function),"d"((dword)arg1),"c"((dword)arg2),"b"((dword)arg3):"memory");
return result;
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions LibC/locale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ char* setlocale(int category, const char* locale)
return nullptr;
}

struct lconv* localeconv()
{
assert(false);
}

}
2 changes: 2 additions & 0 deletions LibC/locale.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ enum {
LC_NUMERIC,
LC_CTYPE,
LC_COLLATE,
LC_TIME,
};

struct lconv {
char *decimal_point;
};

struct lconv* localeconv();
Expand Down
17 changes: 17 additions & 0 deletions LibC/stdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,5 +384,22 @@ int rename(const char* oldpath, const char* newpath)
ASSERT_NOT_REACHED();
}

char* tmpnam(char*)
{
assert(false);
}

FILE* popen(const char* command, const char* type)
{
(void)command;
(void)type;
assert(false);
}

int pclose(FILE*)
{
assert(false);
}

}

3 changes: 3 additions & 0 deletions LibC/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ void setbuf(FILE*, char* buf);
void setlinebuf(FILE*);
int rename(const char* oldpath, const char* newpath);
FILE* tmpfile();
char* tmpnam(char*);
FILE* popen(const char* command, const char* type);
int pclose(FILE*);

__END_DECLS

5 changes: 5 additions & 0 deletions LibC/stdlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ char* getenv(const char* name)
return nullptr;
}

int putenv(char*)
{
assert(false);
}

double atof(const char*)
{
assert(false);
Expand Down
1 change: 1 addition & 0 deletions LibC/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ __attribute__((malloc)) __attribute__((alloc_size(1, 2))) void* calloc(size_t nm
void free(void*);
void* realloc(void *ptr, size_t);
char* getenv(const char* name);
int putenv(char*);
int atoi(const char*);
long atol(const char*);
double strtod(const char*, char** endptr);
Expand Down
7 changes: 7 additions & 0 deletions LibC/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,12 @@ char* strpbrk(const char* s, const char* accept)
return nullptr;
}

char *strtok(char* str, const char* delim)
{
(void)str;
(void)delim;
assert(false);
}

}

4 changes: 3 additions & 1 deletion LibC/sys/select.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ __BEGIN_DECLS
#define FD_SET(fd, set) ((set)->bits[(fd / 8)] |= (1 << (fd) % 8))
#define FD_ISSET(fd, set) ((set)->bits[(fd / 8)] & (1 << (fd) % 8))

struct fd_set {
struct __fd_set {
unsigned char bits[FD_SETSIZE / 8];
};

typedef struct __fd_set fd_set;

int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, struct timeval* timeout);

__END_DECLS
Expand Down
5 changes: 5 additions & 0 deletions LibC/sys/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ struct stat {
time_t st_ctime; /* time of last status change */
};

struct utimbuf {
time_t actime;
time_t modtime;
};

#ifdef __cplusplus
#define NULL nullptr
#else
Expand Down
1 change: 1 addition & 0 deletions LibC/sys/wait.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

__BEGIN_DECLS

#define WNOHANG 1
pid_t wait(int* wstatus);

__END_DECLS
12 changes: 12 additions & 0 deletions LibC/termios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,17 @@ int tcflow(int fd, int action)
assert(false);
}

int tcflush(int fd, int queue_selector)
{
(void)fd;
(void)queue_selector;
assert(false);
}

speed_t cfgetospeed(const struct termios*)
{
assert(false);
}

}

2 changes: 2 additions & 0 deletions LibC/termios.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ __BEGIN_DECLS

typedef uint32_t tcflag_t;
typedef uint8_t cc_t;
typedef uint32_t speed_t;

struct termios {
tcflag_t c_iflag;
Expand All @@ -21,6 +22,7 @@ struct termios {
int tcgetattr(int fd, struct termios*);
int tcsetattr(int fd, int optional_actions, const struct termios*);
int tcflow(int fd, int action);
int tcflush(int fd, int queue_selector);

/* c_cc characters */
#define VINTR 0
Expand Down
5 changes: 5 additions & 0 deletions LibC/unistd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,9 @@ int release_shared_buffer(int shared_buffer_id)
__RETURN_WITH_ERRNO(rc, rc, -1);
}

char* getlogin()
{
assert(false);
}

}
5 changes: 5 additions & 0 deletions LibC/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
#include <sys/cdefs.h>
#include <sys/types.h>
#include <limits.h>
#include <errno.h>

__BEGIN_DECLS

#define HZ 1000
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2

extern char** environ;

Expand Down Expand Up @@ -68,6 +72,7 @@ int isatty(int fd);
int mknod(const char* pathname, mode_t, dev_t);
long fpathconf(int fd, int name);
long pathconf(const char *path, int name);
char* getlogin();

enum {
_PC_NAME_MAX,
Expand Down

0 comments on commit cccc8d8

Please sign in to comment.