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
11 #ifndef SEMIHOSTING_GUESTFD_H
12 #define SEMIHOSTING_GUESTFD_H
14 typedef enum 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
{
41 * Allocate an unused GuestFD index. The associated guestfd index
42 * will still be GuestFDUnused until it is initialized.
44 int alloc_guestfd(void);
48 * @guestfd: GuestFD index
50 * Deallocate a GuestFD index. The associated GuestFD structure
51 * will be recycled for a subsequent allocation.
53 void dealloc_guestfd(int guestfd
);
57 * @guestfd: GuestFD index
59 * Return the GuestFD structure associated with an initialized @guestfd,
60 * or NULL if it has not been allocated, or hasn't been initialized.
62 GuestFD
*get_guestfd(int guestfd
);
66 * @guestfd: GuestFD index
67 * @hostfd: host file descriptor
69 * Initialize the GuestFD for @guestfd to GuestFDHost using @hostfd.
71 void associate_guestfd(int guestfd
, int hostfd
);
75 * @guestfd: GuestFD index
76 * @data: data to be read
77 * @len: length of @data
79 * Initialize the GuestFD for @guestfd to GuestFDStatic.
80 * The @len bytes at @data will be returned to the guest on reads.
82 void staticfile_guestfd(int guestfd
, const uint8_t *data
, size_t len
);
84 #endif /* SEMIHOSTING_GUESTFD_H */