Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import 64-bit fixes and rewinddir from dcload-ip #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions example-src/dcload-syscall.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#ifndef __DCLOAD_SYSCALL_H__
#define __DCLOAD_SYSCALL_H__

#include <stdnoreturn.h>

int dcloadsyscall(unsigned int syscall, ...);

/* From crt0.S */
noreturn void __exit(int status);

#define pcreadnr 0
#define pcwritenr 1
#define pcopennr 2
Expand Down
2 changes: 1 addition & 1 deletion example-src/dcload-syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int unlink(const char *path) {
return -1;
}

void exit(int status) {
noreturn void exit(int status) {
if(*DCLOADMAGICADDR == DCLOADMAGICVALUE)
dcloadsyscall(pcexitnr);

Expand Down
61 changes: 47 additions & 14 deletions host-src/tool/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
#define O_BINARY 0
#endif

/* Sigh... KOS treats anything under 100 as invalid for a dirent from dcload, so
we need to offset by a bit. This aught to do. */
#define DIRENT_OFFSET 1337

#define MAX_OPEN_DIRS 512

static DIR *opendirs[MAX_OPEN_DIRS];

void dc_fstat(void) {
int filedes;
struct stat filestat;
Expand Down Expand Up @@ -362,38 +370,58 @@ void dc_opendir(void) {
DIR *somedir;
unsigned char *dirname;
int namelen;
uint32_t i;

namelen = recv_uint();

dirname = malloc(namelen);

recv_data(dirname, namelen, 0);

somedir = opendir((const char *)dirname);
/* Find an open entry */
for(i = 0; i < MAX_OPEN_DIRS; ++i) {
if(!opendirs[i])
break;
}

if(i < MAX_OPEN_DIRS) {
if(!(opendirs[i] = opendir((const char *)dirname)))
i = 0;
else
i += DIRENT_OFFSET;
}
else {
i = 0;
}

send_uint((unsigned int)somedir);
send_uint(i);

free(dirname);
}

void dc_closedir(void) {
DIR *somedir;
int retval;
uint32_t i = recv_uint();

somedir = (DIR *) recv_uint();

retval = closedir(somedir);
if(i >= DIRENT_OFFSET && i < MAX_OPEN_DIRS + DIRENT_OFFSET) {
retval = closedir(opendirs[i - DIRENT_OFFSET]);
opendirs[i - DIRENT_OFFSET] = NULL;
}
else {
retval = -1;
}

send_uint(retval);
}

void dc_readdir(void) {
DIR *somedir;
struct dirent *somedirent;
uint32_t i = recv_uint();

somedir = (DIR *) recv_uint();

somedirent = readdir(somedir);
if(i >= DIRENT_OFFSET && i < MAX_OPEN_DIRS + DIRENT_OFFSET)
somedirent = readdir(opendirs[i - DIRENT_OFFSET]);
else
somedirent = NULL;

if(!somedirent) {
send_uint(0);
Expand Down Expand Up @@ -424,12 +452,17 @@ void dc_readdir(void) {
}

void dc_rewinddir(void) {
DIR *somedir;
int retval;
uint32_t i = recv_uint();

somedir = (DIR *) recv_uint();

rewinddir(somedir);
if(i >= DIRENT_OFFSET && i < MAX_OPEN_DIRS + DIRENT_OFFSET) {
rewinddir(opendirs[i - DIRENT_OFFSET]);
opendirs[i - DIRENT_OFFSET] = NULL;
retval = 0;
}
else {
retval = -1;
}

send_uint(0);
}
Expand Down