Skip to content

Commit 227cb42

Browse files
committed
compile syscall.c without errors
1 parent 49833bd commit 227cb42

File tree

7 files changed

+548
-580
lines changed

7 files changed

+548
-580
lines changed

Makefile.target

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ QEMU_CFLAGS+=-I$(SRC_PATH)/darwin-user/$(TARGET_ABI_DIR) \
139139
-I$(SRC_PATH)/darwin-user
140140

141141
obj-y += darwin-user/
142-
obj-y += gdbstub.o
142+
obj-y += gdbstub.o thunk.o
143143

144144
endif #CONFIG_DARWIN_USER
145145

darwin-user/irix/target_syscall.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct target_dirent {
4141
char d_name[1];
4242
};
4343
/* size of struct target_dirent without the name array */
44-
#define target_dirent_len (offsetof(struct target_dirent, d_name));
44+
#define target_dirent_len (offsetof(struct target_dirent, d_name))
4545

4646
/* IRIX sys/types.h */
4747
typedef uint64_t target_ino64_t;

darwin-user/shim_fallocate.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/** Shim for macOS lack of `fallocate`
2+
* Based on:
3+
* https://stackoverflow.com/questions/11497567/fallocate-command-equivalent-in-os-x
4+
*/
5+
6+
#include <fcntl.h>
7+
8+
#include "shim_fallocate.h"
9+
10+
/** This emulates the Linux fallocate, so the errno is set, not returned
11+
* as in Posix
12+
*/
13+
int shim_fallocate(int fd, int mode, off_t offset, off_t len) {
14+
if (mode == SHIM_FALLOC_DEFAULT) {
15+
fstore_t store = {F_ALLOCATECONTIG | F_ALLOCATEALL, F_PEOFPOSMODE, 0, len, 0};
16+
// Try to get a continous chunk of disk space
17+
int ret = fcntl(fd, F_PREALLOCATE, &store);
18+
// If too fragmented, allocated non-continous
19+
if (ret == -1) {
20+
store.fst_flags = F_ALLOCATEALL;
21+
ret = fcntl(fd, F_PREALLOCATE, &store);
22+
}
23+
24+
return ret;
25+
} else if (mode == SHIM_FALLOC_FL_PUNCH_HOLE) {
26+
fpunchhole_t hole = {0, 0, offset, len};
27+
int ret = fcntl(fd, F_PUNCHHOLE, &hole);
28+
29+
return ret;
30+
} else {
31+
// TODO: set errno EINVAL, but this should be unreachable
32+
return -1;
33+
}
34+
}

darwin-user/shim_fallocate.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef SHIM_FALLOCATE_H
2+
#define SHIM_FALLOCATE_H
3+
4+
#include <sys/types.h>
5+
6+
int shim_fallocate(int fd, int mode, off_t offset, off_t len);
7+
8+
enum FALLOCATE_SHIM_MODES {
9+
SHIM_FALLOC_DEFAULT = 0,
10+
SHIM_FALLOC_FL_PUNCH_HOLE
11+
};
12+
13+
#endif /* SHIM_FALLOCATE_H */

darwin-user/shim_timers.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/** Shim for macOS lack of POSIX `timer_*` functions and types
2+
* Right now, the timers don't seem to match IRIX anyways, so
3+
* these are all stub functions.
4+
*
5+
* The irix timer_t function is a struct, but `tagert_timer_t` is
6+
* defined for Linux qemu-irix as an int...
7+
*
8+
* For later:
9+
* https://nitschinger.at/Scheduling-Timers-on-OS-X-with-Rust-and-Kqueue/
10+
* https://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_getoverrun.html
11+
*/
12+
13+
#include <errno.h>
14+
#include <time.h>
15+
#include <sys/signal.h>
16+
17+
#include "shim_timers.h"
18+
19+
20+
int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid) {
21+
errno = EINVAL;
22+
return -1;
23+
}
24+
25+
int timer_delete(timer_t timerid) {
26+
return 0;
27+
}
28+
29+
int timer_getoverrun(timer_t timerid) {
30+
errno = EINVAL;
31+
return -1;
32+
}
33+
34+
int timer_gettime(timer_t timerid, struct itimerspec *value) {
35+
errno = EINVAL;
36+
return -1;
37+
}
38+
39+
int timer_settime(
40+
timer_t timerid,
41+
int flags,
42+
const struct itimerspec *value,
43+
struct itimerspec *ovalue
44+
){
45+
errno = EINVAL;
46+
return -1;
47+
}

darwin-user/shim_timers.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef SHIM_TIMERS_H
2+
#define SHIM_TIMERS_H
3+
4+
#include <sys/types.h>
5+
#include <time.h>
6+
7+
struct itimerspec {
8+
struct timespec it_interval; /* timer period */
9+
struct timespec it_value; /* timer expiration */
10+
};
11+
12+
typedef int timer_t;
13+
14+
int timer_create(clockid_t, struct sigevent *, timer_t *);
15+
int timer_delete(timer_t);
16+
int timer_getoverrun(timer_t);
17+
int timer_gettime(timer_t, struct itimerspec *);
18+
int timer_settime(timer_t, int, const struct itimerspec *, struct itimerspec *);
19+
20+
#endif /* SHIM_TIMERS_H */

0 commit comments

Comments
 (0)