build.bat can create the image if missing, split the shell into native, posix and win32, clean up the build by moving executables into directories, the bootloader is no longer responsible to resolve drivers, fix ResolvePath, every process gets a copy of a module (dll), the child always inherits the cwd, fix function exports in posix, add unlink and exit to posix, add path translator to win32, first bugcheck.
This commit is contained in:
1 parent
0c7f461c6d
commit
f80e66ecde
38 files changed
+1620
-462
No files matched your search
+27
-18
@@ -1,23 +1,11 @@
|
||||
// posix_io.c - open, read, write, close, lseek
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <syscall.h>
|
||||
#include "posix.h"
|
||||
#include "posix_fd.h"
|
||||
#include "posix_path.h"
|
||||
|
||||
extern uint32_t SysGetCurrentPid(void);
|
||||
extern uint32_t SysOpenFile (const char* path, uint32_t* handleOut);
|
||||
extern uint32_t SysCreateFile (const char* path, uint32_t* handleOut);
|
||||
extern uint32_t SysTruncateFile(uint32_t handle, uint64_t newSize);
|
||||
extern uint32_t SysReadFile (uint32_t handle, void* buf, size_t size, size_t* bytesRead);
|
||||
extern uint32_t SysWriteFile (uint32_t handle, const void* buf, size_t size, size_t* written);
|
||||
extern uint32_t SysSeekFile (uint32_t handle, uint64_t offset);
|
||||
extern uint64_t SysGetFilePos (uint32_t handle);
|
||||
extern uint64_t SysGetFileSize(uint32_t handle);
|
||||
extern void SysCloseHandle(uint32_t handle);
|
||||
extern void SysWriteConsole(const char* buf, size_t len);
|
||||
extern char SysKbReadChar(void);
|
||||
|
||||
// KSTATUS -> errno
|
||||
static int KsToErrno(uint32_t s) {
|
||||
switch (s) {
|
||||
@@ -34,7 +22,12 @@ static int KsToErrno(uint32_t s) {
|
||||
}
|
||||
}
|
||||
|
||||
int open(const char* path, int flags, ...) {
|
||||
__declspec(dllexport) int ClearConsoleScreenBuffer(void* hConsole) {
|
||||
SysScreenClear(0x00000000);
|
||||
return 1;
|
||||
}
|
||||
|
||||
__declspec(dllexport) int open(const char* path, int flags, ...) {
|
||||
char native[512];
|
||||
const char* p = PosixTranslatePath(path, native, sizeof(native));
|
||||
|
||||
@@ -72,7 +65,7 @@ int open(const char* path, int flags, ...) {
|
||||
return fd;
|
||||
}
|
||||
|
||||
ssize_t read(int fd, void* buf, size_t count) {
|
||||
__declspec(dllexport) ssize_t read(int fd, void* buf, size_t count) {
|
||||
if (count == 0) return 0;
|
||||
uint32_t pid = SysGetCurrentPid();
|
||||
FD_ENTRY* e = FdGet(pid, fd);
|
||||
@@ -105,7 +98,7 @@ ssize_t read(int fd, void* buf, size_t count) {
|
||||
}
|
||||
}
|
||||
|
||||
ssize_t write(int fd, const void* buf, size_t count) {
|
||||
__declspec(dllexport) ssize_t write(int fd, const void* buf, size_t count) {
|
||||
if (count == 0) return 0;
|
||||
uint32_t pid = SysGetCurrentPid();
|
||||
FD_ENTRY* e = FdGet(pid, fd);
|
||||
@@ -130,7 +123,7 @@ ssize_t write(int fd, const void* buf, size_t count) {
|
||||
}
|
||||
}
|
||||
|
||||
int close(int fd) {
|
||||
__declspec(dllexport) int close(int fd) {
|
||||
uint32_t pid = SysGetCurrentPid();
|
||||
FD_ENTRY* e = FdGet(pid, fd);
|
||||
if (!e) return -1;
|
||||
@@ -140,7 +133,23 @@ int close(int fd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence) {
|
||||
__declspec(dllexport) int unlink(const char* path) {
|
||||
if (!path) { errno = EINVAL; return -1; }
|
||||
|
||||
char native[512];
|
||||
const char* p = PosixTranslatePath(path, native, sizeof(native));
|
||||
|
||||
if (strcmp(p, SYNTH_DEVNULL) == 0 || strcmp(p, SYNTH_DEVZERO) == 0) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t s = SysDeleteFile(p);
|
||||
if (s != 0) { errno = KsToErrno(s); return -1; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
__declspec(dllexport) off_t lseek(int fd, off_t offset, int whence) {
|
||||
uint32_t pid = SysGetCurrentPid();
|
||||
FD_ENTRY* e = FdGet(pid, fd);
|
||||
if (!e || e->Type != FD_FILE) { errno = (e ? ESPIPE : EBADF); return -1; }
|
||||
|
||||
Reference in new issue
Block a user