2 * Syscall implementations for semihosting.
4 * Copyright (c) 2022 Linaro
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "qemu/osdep.h"
11 #include "gdbstub/syscalls.h"
12 #include "semihosting/guestfd.h"
13 #include "semihosting/syscalls.h"
14 #include "semihosting/console.h"
15 #ifdef CONFIG_USER_ONLY
18 #include "semihosting/softmmu-uaccess.h"
23 * Validate or compute the length of the string (including terminator).
25 static int validate_strlen(CPUState
*cs
, target_ulong str
, target_ulong tlen
)
27 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
31 ssize_t slen
= target_strlen(str
);
36 if (slen
>= INT32_MAX
) {
41 if (tlen
> INT32_MAX
) {
44 if (get_user_u8(c
, str
+ tlen
- 1)) {
53 static int validate_lock_user_string(char **pstr
, CPUState
*cs
,
54 target_ulong tstr
, target_ulong tlen
)
56 int ret
= validate_strlen(cs
, tstr
, tlen
);
57 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
61 str
= lock_user(VERIFY_READ
, tstr
, ret
, true);
62 ret
= str
? 0 : -EFAULT
;
69 * TODO: Note that gdb always stores the stat structure big-endian.
70 * So far, that's ok, as the only two targets using this are also
71 * big-endian. Until we do something with gdb, also produce the
72 * same big-endian result from the host.
74 static int copy_stat_to_user(CPUState
*cs
, target_ulong addr
,
77 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
80 if (s
->st_dev
!= (uint32_t)s
->st_dev
||
81 s
->st_ino
!= (uint32_t)s
->st_ino
) {
85 p
= lock_user(VERIFY_WRITE
, addr
, sizeof(struct gdb_stat
), 0);
90 p
->gdb_st_dev
= cpu_to_be32(s
->st_dev
);
91 p
->gdb_st_ino
= cpu_to_be32(s
->st_ino
);
92 p
->gdb_st_mode
= cpu_to_be32(s
->st_mode
);
93 p
->gdb_st_nlink
= cpu_to_be32(s
->st_nlink
);
94 p
->gdb_st_uid
= cpu_to_be32(s
->st_uid
);
95 p
->gdb_st_gid
= cpu_to_be32(s
->st_gid
);
96 p
->gdb_st_rdev
= cpu_to_be32(s
->st_rdev
);
97 p
->gdb_st_size
= cpu_to_be64(s
->st_size
);
99 /* Windows stat is missing some fields. */
100 p
->gdb_st_blksize
= 0;
101 p
->gdb_st_blocks
= 0;
103 p
->gdb_st_blksize
= cpu_to_be64(s
->st_blksize
);
104 p
->gdb_st_blocks
= cpu_to_be64(s
->st_blocks
);
106 p
->gdb_st_atime
= cpu_to_be32(s
->st_atime
);
107 p
->gdb_st_mtime
= cpu_to_be32(s
->st_mtime
);
108 p
->gdb_st_ctime
= cpu_to_be32(s
->st_ctime
);
110 unlock_user(p
, addr
, sizeof(struct gdb_stat
));
115 * GDB semihosting syscall implementations.
118 static gdb_syscall_complete_cb gdb_open_complete
;
120 static void gdb_open_cb(CPUState
*cs
, uint64_t ret
, int err
)
123 int guestfd
= alloc_guestfd();
124 associate_guestfd(guestfd
, ret
);
127 gdb_open_complete(cs
, ret
, err
);
130 static void gdb_open(CPUState
*cs
, gdb_syscall_complete_cb complete
,
131 target_ulong fname
, target_ulong fname_len
,
132 int gdb_flags
, int mode
)
134 int len
= validate_strlen(cs
, fname
, fname_len
);
136 complete(cs
, -1, -len
);
140 gdb_open_complete
= complete
;
141 gdb_do_syscall(gdb_open_cb
, "open,%s,%x,%x",
142 fname
, len
, (target_ulong
)gdb_flags
, (target_ulong
)mode
);
145 static void gdb_close(CPUState
*cs
, gdb_syscall_complete_cb complete
,
148 gdb_do_syscall(complete
, "close,%x", (target_ulong
)gf
->hostfd
);
151 static void gdb_read(CPUState
*cs
, gdb_syscall_complete_cb complete
,
152 GuestFD
*gf
, target_ulong buf
, target_ulong len
)
154 gdb_do_syscall(complete
, "read,%x,%x,%x",
155 (target_ulong
)gf
->hostfd
, buf
, len
);
158 static void gdb_write(CPUState
*cs
, gdb_syscall_complete_cb complete
,
159 GuestFD
*gf
, target_ulong buf
, target_ulong len
)
161 gdb_do_syscall(complete
, "write,%x,%x,%x",
162 (target_ulong
)gf
->hostfd
, buf
, len
);
165 static void gdb_lseek(CPUState
*cs
, gdb_syscall_complete_cb complete
,
166 GuestFD
*gf
, int64_t off
, int gdb_whence
)
168 gdb_do_syscall(complete
, "lseek,%x,%lx,%x",
169 (target_ulong
)gf
->hostfd
, off
, (target_ulong
)gdb_whence
);
172 static void gdb_isatty(CPUState
*cs
, gdb_syscall_complete_cb complete
,
175 gdb_do_syscall(complete
, "isatty,%x", (target_ulong
)gf
->hostfd
);
178 static void gdb_fstat(CPUState
*cs
, gdb_syscall_complete_cb complete
,
179 GuestFD
*gf
, target_ulong addr
)
181 gdb_do_syscall(complete
, "fstat,%x,%x", (target_ulong
)gf
->hostfd
, addr
);
184 static void gdb_stat(CPUState
*cs
, gdb_syscall_complete_cb complete
,
185 target_ulong fname
, target_ulong fname_len
,
188 int len
= validate_strlen(cs
, fname
, fname_len
);
190 complete(cs
, -1, -len
);
194 gdb_do_syscall(complete
, "stat,%s,%x", fname
, len
, addr
);
197 static void gdb_remove(CPUState
*cs
, gdb_syscall_complete_cb complete
,
198 target_ulong fname
, target_ulong fname_len
)
200 int len
= validate_strlen(cs
, fname
, fname_len
);
202 complete(cs
, -1, -len
);
206 gdb_do_syscall(complete
, "unlink,%s", fname
, len
);
209 static void gdb_rename(CPUState
*cs
, gdb_syscall_complete_cb complete
,
210 target_ulong oname
, target_ulong oname_len
,
211 target_ulong nname
, target_ulong nname_len
)
215 olen
= validate_strlen(cs
, oname
, oname_len
);
217 complete(cs
, -1, -olen
);
220 nlen
= validate_strlen(cs
, nname
, nname_len
);
222 complete(cs
, -1, -nlen
);
226 gdb_do_syscall(complete
, "rename,%s,%s", oname
, olen
, nname
, nlen
);
229 static void gdb_system(CPUState
*cs
, gdb_syscall_complete_cb complete
,
230 target_ulong cmd
, target_ulong cmd_len
)
232 int len
= validate_strlen(cs
, cmd
, cmd_len
);
234 complete(cs
, -1, -len
);
238 gdb_do_syscall(complete
, "system,%s", cmd
, len
);
241 static void gdb_gettimeofday(CPUState
*cs
, gdb_syscall_complete_cb complete
,
242 target_ulong tv_addr
, target_ulong tz_addr
)
244 gdb_do_syscall(complete
, "gettimeofday,%x,%x", tv_addr
, tz_addr
);
248 * Host semihosting syscall implementations.
251 static void host_open(CPUState
*cs
, gdb_syscall_complete_cb complete
,
252 target_ulong fname
, target_ulong fname_len
,
253 int gdb_flags
, int mode
)
255 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
257 int ret
, host_flags
= O_BINARY
;
259 ret
= validate_lock_user_string(&p
, cs
, fname
, fname_len
);
261 complete(cs
, -1, -ret
);
265 if (gdb_flags
& GDB_O_WRONLY
) {
266 host_flags
|= O_WRONLY
;
267 } else if (gdb_flags
& GDB_O_RDWR
) {
268 host_flags
|= O_RDWR
;
270 host_flags
|= O_RDONLY
;
272 if (gdb_flags
& GDB_O_CREAT
) {
273 host_flags
|= O_CREAT
;
275 if (gdb_flags
& GDB_O_TRUNC
) {
276 host_flags
|= O_TRUNC
;
278 if (gdb_flags
& GDB_O_EXCL
) {
279 host_flags
|= O_EXCL
;
282 ret
= open(p
, host_flags
, mode
);
284 complete(cs
, -1, errno
);
286 int guestfd
= alloc_guestfd();
287 associate_guestfd(guestfd
, ret
);
288 complete(cs
, guestfd
, 0);
290 unlock_user(p
, fname
, 0);
293 static void host_close(CPUState
*cs
, gdb_syscall_complete_cb complete
,
297 * Only close the underlying host fd if it's one we opened on behalf
298 * of the guest in SYS_OPEN.
300 if (gf
->hostfd
!= STDIN_FILENO
&&
301 gf
->hostfd
!= STDOUT_FILENO
&&
302 gf
->hostfd
!= STDERR_FILENO
&&
303 close(gf
->hostfd
) < 0) {
304 complete(cs
, -1, errno
);
310 static void host_read(CPUState
*cs
, gdb_syscall_complete_cb complete
,
311 GuestFD
*gf
, target_ulong buf
, target_ulong len
)
313 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
314 void *ptr
= lock_user(VERIFY_WRITE
, buf
, len
, 0);
318 complete(cs
, -1, EFAULT
);
321 ret
= RETRY_ON_EINTR(read(gf
->hostfd
, ptr
, len
));
323 unlock_user(ptr
, buf
, 0);
324 complete(cs
, -1, errno
);
326 unlock_user(ptr
, buf
, ret
);
327 complete(cs
, ret
, 0);
331 static void host_write(CPUState
*cs
, gdb_syscall_complete_cb complete
,
332 GuestFD
*gf
, target_ulong buf
, target_ulong len
)
334 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
335 void *ptr
= lock_user(VERIFY_READ
, buf
, len
, 1);
339 complete(cs
, -1, EFAULT
);
342 ret
= write(gf
->hostfd
, ptr
, len
);
343 unlock_user(ptr
, buf
, 0);
344 complete(cs
, ret
, ret
== -1 ? errno
: 0);
347 static void host_lseek(CPUState
*cs
, gdb_syscall_complete_cb complete
,
348 GuestFD
*gf
, int64_t off
, int whence
)
350 /* So far, all hosts use the same values. */
351 QEMU_BUILD_BUG_ON(GDB_SEEK_SET
!= SEEK_SET
);
352 QEMU_BUILD_BUG_ON(GDB_SEEK_CUR
!= SEEK_CUR
);
353 QEMU_BUILD_BUG_ON(GDB_SEEK_END
!= SEEK_END
);
359 ret
= lseek(gf
->hostfd
, ret
, whence
);
367 complete(cs
, ret
, err
);
370 static void host_isatty(CPUState
*cs
, gdb_syscall_complete_cb complete
,
373 int ret
= isatty(gf
->hostfd
);
374 complete(cs
, ret
, ret
? 0 : errno
);
377 static void host_flen(CPUState
*cs
, gdb_syscall_complete_cb complete
,
382 if (fstat(gf
->hostfd
, &buf
) < 0) {
383 complete(cs
, -1, errno
);
385 complete(cs
, buf
.st_size
, 0);
389 static void host_fstat(CPUState
*cs
, gdb_syscall_complete_cb complete
,
390 GuestFD
*gf
, target_ulong addr
)
395 ret
= fstat(gf
->hostfd
, &buf
);
397 complete(cs
, -1, errno
);
400 ret
= copy_stat_to_user(cs
, addr
, &buf
);
401 complete(cs
, ret
? -1 : 0, ret
? -ret
: 0);
404 static void host_stat(CPUState
*cs
, gdb_syscall_complete_cb complete
,
405 target_ulong fname
, target_ulong fname_len
,
408 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
413 ret
= validate_lock_user_string(&name
, cs
, fname
, fname_len
);
415 complete(cs
, -1, -ret
);
419 ret
= stat(name
, &buf
);
423 ret
= copy_stat_to_user(cs
, addr
, &buf
);
430 unlock_user(name
, fname
, 0);
431 complete(cs
, ret
, err
);
434 static void host_remove(CPUState
*cs
, gdb_syscall_complete_cb complete
,
435 target_ulong fname
, target_ulong fname_len
)
437 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
441 ret
= validate_lock_user_string(&p
, cs
, fname
, fname_len
);
443 complete(cs
, -1, -ret
);
448 unlock_user(p
, fname
, 0);
449 complete(cs
, ret
, ret
? errno
: 0);
452 static void host_rename(CPUState
*cs
, gdb_syscall_complete_cb complete
,
453 target_ulong oname
, target_ulong oname_len
,
454 target_ulong nname
, target_ulong nname_len
)
456 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
460 ret
= validate_lock_user_string(&ostr
, cs
, oname
, oname_len
);
462 complete(cs
, -1, -ret
);
465 ret
= validate_lock_user_string(&nstr
, cs
, nname
, nname_len
);
467 unlock_user(ostr
, oname
, 0);
468 complete(cs
, -1, -ret
);
472 ret
= rename(ostr
, nstr
);
473 unlock_user(ostr
, oname
, 0);
474 unlock_user(nstr
, nname
, 0);
475 complete(cs
, ret
, ret
? errno
: 0);
478 static void host_system(CPUState
*cs
, gdb_syscall_complete_cb complete
,
479 target_ulong cmd
, target_ulong cmd_len
)
481 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
485 ret
= validate_lock_user_string(&p
, cs
, cmd
, cmd_len
);
487 complete(cs
, -1, -ret
);
492 unlock_user(p
, cmd
, 0);
493 complete(cs
, ret
, ret
== -1 ? errno
: 0);
496 static void host_gettimeofday(CPUState
*cs
, gdb_syscall_complete_cb complete
,
497 target_ulong tv_addr
, target_ulong tz_addr
)
499 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
500 struct gdb_timeval
*p
;
503 /* GDB fails on non-null TZ, so be consistent. */
505 complete(cs
, -1, EINVAL
);
509 p
= lock_user(VERIFY_WRITE
, tv_addr
, sizeof(struct gdb_timeval
), 0);
511 complete(cs
, -1, EFAULT
);
515 /* TODO: Like stat, gdb always produces big-endian results; match it. */
516 rt
= g_get_real_time();
517 p
->tv_sec
= cpu_to_be32(rt
/ G_USEC_PER_SEC
);
518 p
->tv_usec
= cpu_to_be64(rt
% G_USEC_PER_SEC
);
519 unlock_user(p
, tv_addr
, sizeof(struct gdb_timeval
));
522 #ifndef CONFIG_USER_ONLY
523 static void host_poll_one(CPUState
*cs
, gdb_syscall_complete_cb complete
,
524 GuestFD
*gf
, GIOCondition cond
, int timeout
)
527 * Since this is only used by xtensa in system mode, and stdio is
528 * handled through GuestFDConsole, and there are no semihosting
529 * system calls for sockets and the like, that means this descriptor
530 * must be a normal file. Normal files never block and are thus
533 complete(cs
, cond
& (G_IO_IN
| G_IO_OUT
), 0);
538 * Static file semihosting syscall implementations.
541 static void staticfile_read(CPUState
*cs
, gdb_syscall_complete_cb complete
,
542 GuestFD
*gf
, target_ulong buf
, target_ulong len
)
544 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
545 target_ulong rest
= gf
->staticfile
.len
- gf
->staticfile
.off
;
551 ptr
= lock_user(VERIFY_WRITE
, buf
, len
, 0);
553 complete(cs
, -1, EFAULT
);
556 memcpy(ptr
, gf
->staticfile
.data
+ gf
->staticfile
.off
, len
);
557 gf
->staticfile
.off
+= len
;
558 unlock_user(ptr
, buf
, len
);
559 complete(cs
, len
, 0);
562 static void staticfile_lseek(CPUState
*cs
, gdb_syscall_complete_cb complete
,
563 GuestFD
*gf
, int64_t off
, int gdb_whence
)
567 switch (gdb_whence
) {
572 ret
= gf
->staticfile
.off
+ off
;
575 ret
= gf
->staticfile
.len
+ off
;
581 if (ret
>= 0 && ret
<= gf
->staticfile
.len
) {
582 gf
->staticfile
.off
= ret
;
583 complete(cs
, ret
, 0);
585 complete(cs
, -1, EINVAL
);
589 static void staticfile_flen(CPUState
*cs
, gdb_syscall_complete_cb complete
,
592 complete(cs
, gf
->staticfile
.len
, 0);
596 * Console semihosting syscall implementations.
599 static void console_read(CPUState
*cs
, gdb_syscall_complete_cb complete
,
600 GuestFD
*gf
, target_ulong buf
, target_ulong len
)
602 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
606 ptr
= lock_user(VERIFY_WRITE
, buf
, len
, 0);
608 complete(cs
, -1, EFAULT
);
611 ret
= qemu_semihosting_console_read(cs
, ptr
, len
);
612 unlock_user(ptr
, buf
, ret
);
613 complete(cs
, ret
, 0);
616 static void console_write(CPUState
*cs
, gdb_syscall_complete_cb complete
,
617 GuestFD
*gf
, target_ulong buf
, target_ulong len
)
619 CPUArchState
*env G_GNUC_UNUSED
= cs
->env_ptr
;
620 char *ptr
= lock_user(VERIFY_READ
, buf
, len
, 1);
624 complete(cs
, -1, EFAULT
);
627 ret
= qemu_semihosting_console_write(ptr
, len
);
628 unlock_user(ptr
, buf
, 0);
629 complete(cs
, ret
? ret
: -1, ret
? 0 : EIO
);
632 static void console_fstat(CPUState
*cs
, gdb_syscall_complete_cb complete
,
633 GuestFD
*gf
, target_ulong addr
)
635 static const struct stat tty_buf
= {
636 .st_mode
= 020666, /* S_IFCHR, ugo+rw */
637 .st_rdev
= 5, /* makedev(5, 0) -- linux /dev/tty */
641 ret
= copy_stat_to_user(cs
, addr
, &tty_buf
);
642 complete(cs
, ret
? -1 : 0, ret
? -ret
: 0);
645 #ifndef CONFIG_USER_ONLY
646 static void console_poll_one(CPUState
*cs
, gdb_syscall_complete_cb complete
,
647 GuestFD
*gf
, GIOCondition cond
, int timeout
)
649 /* The semihosting console does not support urgent data or errors. */
650 cond
&= G_IO_IN
| G_IO_OUT
;
653 * Since qemu_semihosting_console_write never blocks, we can
654 * consider output always ready -- leave G_IO_OUT alone.
655 * All that remains is to conditionally signal input ready.
656 * Since output ready causes an immediate return, only block
659 * TODO: Implement proper timeout. For now, only support
660 * indefinite wait or immediate poll.
662 if (cond
== G_IO_IN
&& timeout
< 0) {
663 qemu_semihosting_console_block_until_ready(cs
);
664 /* We returned -- input must be ready. */
665 } else if ((cond
& G_IO_IN
) && !qemu_semihosting_console_ready()) {
669 complete(cs
, cond
, 0);
674 * Syscall entry points.
677 void semihost_sys_open(CPUState
*cs
, gdb_syscall_complete_cb complete
,
678 target_ulong fname
, target_ulong fname_len
,
679 int gdb_flags
, int mode
)
681 if (use_gdb_syscalls()) {
682 gdb_open(cs
, complete
, fname
, fname_len
, gdb_flags
, mode
);
684 host_open(cs
, complete
, fname
, fname_len
, gdb_flags
, mode
);
688 void semihost_sys_close(CPUState
*cs
, gdb_syscall_complete_cb complete
, int fd
)
690 GuestFD
*gf
= get_guestfd(fd
);
693 complete(cs
, -1, EBADF
);
698 gdb_close(cs
, complete
, gf
);
701 host_close(cs
, complete
, gf
);
708 g_assert_not_reached();
713 void semihost_sys_read_gf(CPUState
*cs
, gdb_syscall_complete_cb complete
,
714 GuestFD
*gf
, target_ulong buf
, target_ulong len
)
717 * Bound length for 64-bit guests on 32-bit hosts, not overlowing ssize_t.
718 * Note the Linux kernel does this with MAX_RW_COUNT, so it's not a bad
719 * idea to do this unconditionally.
721 if (len
> INT32_MAX
) {
726 gdb_read(cs
, complete
, gf
, buf
, len
);
729 host_read(cs
, complete
, gf
, buf
, len
);
732 staticfile_read(cs
, complete
, gf
, buf
, len
);
735 console_read(cs
, complete
, gf
, buf
, len
);
738 g_assert_not_reached();
742 void semihost_sys_read(CPUState
*cs
, gdb_syscall_complete_cb complete
,
743 int fd
, target_ulong buf
, target_ulong len
)
745 GuestFD
*gf
= get_guestfd(fd
);
748 semihost_sys_read_gf(cs
, complete
, gf
, buf
, len
);
750 complete(cs
, -1, EBADF
);
754 void semihost_sys_write_gf(CPUState
*cs
, gdb_syscall_complete_cb complete
,
755 GuestFD
*gf
, target_ulong buf
, target_ulong len
)
758 * Bound length for 64-bit guests on 32-bit hosts, not overlowing ssize_t.
759 * Note the Linux kernel does this with MAX_RW_COUNT, so it's not a bad
760 * idea to do this unconditionally.
762 if (len
> INT32_MAX
) {
767 gdb_write(cs
, complete
, gf
, buf
, len
);
770 host_write(cs
, complete
, gf
, buf
, len
);
773 console_write(cs
, complete
, gf
, buf
, len
);
776 /* Static files are never open for writing: EBADF. */
777 complete(cs
, -1, EBADF
);
780 g_assert_not_reached();
784 void semihost_sys_write(CPUState
*cs
, gdb_syscall_complete_cb complete
,
785 int fd
, target_ulong buf
, target_ulong len
)
787 GuestFD
*gf
= get_guestfd(fd
);
790 semihost_sys_write_gf(cs
, complete
, gf
, buf
, len
);
792 complete(cs
, -1, EBADF
);
796 void semihost_sys_lseek(CPUState
*cs
, gdb_syscall_complete_cb complete
,
797 int fd
, int64_t off
, int gdb_whence
)
799 GuestFD
*gf
= get_guestfd(fd
);
802 complete(cs
, -1, EBADF
);
807 gdb_lseek(cs
, complete
, gf
, off
, gdb_whence
);
810 host_lseek(cs
, complete
, gf
, off
, gdb_whence
);
813 staticfile_lseek(cs
, complete
, gf
, off
, gdb_whence
);
816 complete(cs
, -1, ESPIPE
);
819 g_assert_not_reached();
823 void semihost_sys_isatty(CPUState
*cs
, gdb_syscall_complete_cb complete
, int fd
)
825 GuestFD
*gf
= get_guestfd(fd
);
828 complete(cs
, 0, EBADF
);
833 gdb_isatty(cs
, complete
, gf
);
836 host_isatty(cs
, complete
, gf
);
839 complete(cs
, 0, ENOTTY
);
845 g_assert_not_reached();
849 void semihost_sys_flen(CPUState
*cs
, gdb_syscall_complete_cb fstat_cb
,
850 gdb_syscall_complete_cb flen_cb
, int fd
,
851 target_ulong fstat_addr
)
853 GuestFD
*gf
= get_guestfd(fd
);
856 flen_cb(cs
, -1, EBADF
);
861 gdb_fstat(cs
, fstat_cb
, gf
, fstat_addr
);
864 host_flen(cs
, flen_cb
, gf
);
867 staticfile_flen(cs
, flen_cb
, gf
);
871 g_assert_not_reached();
875 void semihost_sys_fstat(CPUState
*cs
, gdb_syscall_complete_cb complete
,
876 int fd
, target_ulong addr
)
878 GuestFD
*gf
= get_guestfd(fd
);
881 complete(cs
, -1, EBADF
);
886 gdb_fstat(cs
, complete
, gf
, addr
);
889 host_fstat(cs
, complete
, gf
, addr
);
892 console_fstat(cs
, complete
, gf
, addr
);
896 g_assert_not_reached();
900 void semihost_sys_stat(CPUState
*cs
, gdb_syscall_complete_cb complete
,
901 target_ulong fname
, target_ulong fname_len
,
904 if (use_gdb_syscalls()) {
905 gdb_stat(cs
, complete
, fname
, fname_len
, addr
);
907 host_stat(cs
, complete
, fname
, fname_len
, addr
);
911 void semihost_sys_remove(CPUState
*cs
, gdb_syscall_complete_cb complete
,
912 target_ulong fname
, target_ulong fname_len
)
914 if (use_gdb_syscalls()) {
915 gdb_remove(cs
, complete
, fname
, fname_len
);
917 host_remove(cs
, complete
, fname
, fname_len
);
921 void semihost_sys_rename(CPUState
*cs
, gdb_syscall_complete_cb complete
,
922 target_ulong oname
, target_ulong oname_len
,
923 target_ulong nname
, target_ulong nname_len
)
925 if (use_gdb_syscalls()) {
926 gdb_rename(cs
, complete
, oname
, oname_len
, nname
, nname_len
);
928 host_rename(cs
, complete
, oname
, oname_len
, nname
, nname_len
);
932 void semihost_sys_system(CPUState
*cs
, gdb_syscall_complete_cb complete
,
933 target_ulong cmd
, target_ulong cmd_len
)
935 if (use_gdb_syscalls()) {
936 gdb_system(cs
, complete
, cmd
, cmd_len
);
938 host_system(cs
, complete
, cmd
, cmd_len
);
942 void semihost_sys_gettimeofday(CPUState
*cs
, gdb_syscall_complete_cb complete
,
943 target_ulong tv_addr
, target_ulong tz_addr
)
945 if (use_gdb_syscalls()) {
946 gdb_gettimeofday(cs
, complete
, tv_addr
, tz_addr
);
948 host_gettimeofday(cs
, complete
, tv_addr
, tz_addr
);
952 #ifndef CONFIG_USER_ONLY
953 void semihost_sys_poll_one(CPUState
*cs
, gdb_syscall_complete_cb complete
,
954 int fd
, GIOCondition cond
, int timeout
)
956 GuestFD
*gf
= get_guestfd(fd
);
959 complete(cs
, G_IO_NVAL
, 1);
964 complete(cs
, G_IO_NVAL
, 1);
967 host_poll_one(cs
, complete
, gf
, cond
, timeout
);
970 console_poll_one(cs
, complete
, gf
, cond
, timeout
);
974 g_assert_not_reached();