syscalls.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * GDB Syscall support
  3. *
  4. * Copyright (c) 2023 Linaro Ltd
  5. *
  6. * SPDX-License-Identifier: LGPL-2.0-or-later
  7. */
  8. #ifndef _SYSCALLS_H_
  9. #define _SYSCALLS_H_
  10. /* For gdb file i/o remote protocol open flags. */
  11. #define GDB_O_RDONLY 0
  12. #define GDB_O_WRONLY 1
  13. #define GDB_O_RDWR 2
  14. #define GDB_O_APPEND 8
  15. #define GDB_O_CREAT 0x200
  16. #define GDB_O_TRUNC 0x400
  17. #define GDB_O_EXCL 0x800
  18. /* For gdb file i/o remote protocol errno values */
  19. #define GDB_EPERM 1
  20. #define GDB_ENOENT 2
  21. #define GDB_EINTR 4
  22. #define GDB_EBADF 9
  23. #define GDB_EACCES 13
  24. #define GDB_EFAULT 14
  25. #define GDB_EBUSY 16
  26. #define GDB_EEXIST 17
  27. #define GDB_ENODEV 19
  28. #define GDB_ENOTDIR 20
  29. #define GDB_EISDIR 21
  30. #define GDB_EINVAL 22
  31. #define GDB_ENFILE 23
  32. #define GDB_EMFILE 24
  33. #define GDB_EFBIG 27
  34. #define GDB_ENOSPC 28
  35. #define GDB_ESPIPE 29
  36. #define GDB_EROFS 30
  37. #define GDB_ENAMETOOLONG 91
  38. #define GDB_EUNKNOWN 9999
  39. /* For gdb file i/o remote protocol lseek whence. */
  40. #define GDB_SEEK_SET 0
  41. #define GDB_SEEK_CUR 1
  42. #define GDB_SEEK_END 2
  43. /* For gdb file i/o stat/fstat. */
  44. typedef uint32_t gdb_mode_t;
  45. typedef uint32_t gdb_time_t;
  46. struct gdb_stat {
  47. uint32_t gdb_st_dev; /* device */
  48. uint32_t gdb_st_ino; /* inode */
  49. gdb_mode_t gdb_st_mode; /* protection */
  50. uint32_t gdb_st_nlink; /* number of hard links */
  51. uint32_t gdb_st_uid; /* user ID of owner */
  52. uint32_t gdb_st_gid; /* group ID of owner */
  53. uint32_t gdb_st_rdev; /* device type (if inode device) */
  54. uint64_t gdb_st_size; /* total size, in bytes */
  55. uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */
  56. uint64_t gdb_st_blocks; /* number of blocks allocated */
  57. gdb_time_t gdb_st_atime; /* time of last access */
  58. gdb_time_t gdb_st_mtime; /* time of last modification */
  59. gdb_time_t gdb_st_ctime; /* time of last change */
  60. } QEMU_PACKED;
  61. struct gdb_timeval {
  62. gdb_time_t tv_sec; /* second */
  63. uint64_t tv_usec; /* microsecond */
  64. } QEMU_PACKED;
  65. typedef void (*gdb_syscall_complete_cb)(CPUState *cpu, uint64_t ret, int err);
  66. /**
  67. * gdb_do_syscall:
  68. * @cb: function to call when the system call has completed
  69. * @fmt: gdb syscall format string
  70. * ...: list of arguments to interpolate into @fmt
  71. *
  72. * Send a GDB syscall request. This function will return immediately;
  73. * the callback function will be called later when the remote system
  74. * call has completed.
  75. *
  76. * @fmt should be in the 'call-id,parameter,parameter...' format documented
  77. * for the F request packet in the GDB remote protocol. A limited set of
  78. * printf-style format specifiers is supported:
  79. * %x - target_ulong argument printed in hex
  80. * %lx - 64-bit argument printed in hex
  81. * %s - string pointer (target_ulong) and length (int) pair
  82. */
  83. void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...);
  84. /**
  85. * use_gdb_syscalls() - report if GDB should be used for syscalls
  86. *
  87. * This is mostly driven by the semihosting mode the user configures
  88. * but assuming GDB is allowed by that we report true if GDB is
  89. * connected to the stub.
  90. */
  91. int use_gdb_syscalls(void);
  92. /**
  93. * gdb_exit: exit gdb session, reporting inferior status
  94. * @code: exit code reported
  95. *
  96. * This closes the session and sends a final packet to GDB reporting
  97. * the exit status of the program. It also cleans up any connections
  98. * detritus before returning.
  99. */
  100. void gdb_exit(int code);
  101. /**
  102. * gdb_qemu_exit: ask qemu to exit
  103. * @code: exit code reported
  104. *
  105. * This requests qemu to exit. This function is allowed to return as
  106. * the exit request might be processed asynchronously by qemu backend.
  107. */
  108. void gdb_qemu_exit(int code);
  109. #endif /* _SYSCALLS_H_ */