migration/rdma: Eliminate error_propagate()
[qemu/armbru.git] / include / semihosting / guestfd.h
blob3d426fedab39060a600b76b4b8a01b4f6b795a8e
1 /*
2 * Hosted file support for semihosting syscalls.
4 * Copyright (c) 2005, 2007 CodeSourcery.
5 * Copyright (c) 2019 Linaro
6 * Copyright © 2020 by Keith Packard <keithp@keithp.com>
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #ifndef SEMIHOSTING_GUESTFD_H
12 #define SEMIHOSTING_GUESTFD_H
14 typedef enum GuestFDType {
15 GuestFDUnused = 0,
16 GuestFDHost,
17 GuestFDGDB,
18 GuestFDStatic,
19 GuestFDConsole,
20 } GuestFDType;
23 * Guest file descriptors are integer indexes into an array of
24 * these structures (we will dynamically resize as necessary).
26 typedef struct GuestFD {
27 GuestFDType type;
28 union {
29 int hostfd;
30 struct {
31 const uint8_t *data;
32 size_t len;
33 size_t off;
34 } staticfile;
36 } GuestFD;
39 * For ARM semihosting, we have a separate structure for routing
40 * data for the console which is outside the guest fd address space.
42 extern GuestFD console_in_gf;
43 extern GuestFD console_out_gf;
45 /**
46 * alloc_guestfd:
48 * Allocate an unused GuestFD index. The associated guestfd index
49 * will still be GuestFDUnused until it is initialized.
51 int alloc_guestfd(void);
53 /**
54 * dealloc_guestfd:
55 * @guestfd: GuestFD index
57 * Deallocate a GuestFD index. The associated GuestFD structure
58 * will be recycled for a subsequent allocation.
60 void dealloc_guestfd(int guestfd);
62 /**
63 * get_guestfd:
64 * @guestfd: GuestFD index
66 * Return the GuestFD structure associated with an initialized @guestfd,
67 * or NULL if it has not been allocated, or hasn't been initialized.
69 GuestFD *get_guestfd(int guestfd);
71 /**
72 * associate_guestfd:
73 * @guestfd: GuestFD index
74 * @hostfd: host file descriptor
76 * Initialize the GuestFD for @guestfd to GuestFDHost using @hostfd.
78 void associate_guestfd(int guestfd, int hostfd);
80 /**
81 * staticfile_guestfd:
82 * @guestfd: GuestFD index
83 * @data: data to be read
84 * @len: length of @data
86 * Initialize the GuestFD for @guestfd to GuestFDStatic.
87 * The @len bytes at @data will be returned to the guest on reads.
89 void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len);
91 #endif /* SEMIHOSTING_GUESTFD_H */