aboutsummaryrefslogtreecommitdiff
path: root/semihosting
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2022-08-22 15:12:24 +0100
committerRichard Henderson <richard.henderson@linaro.org>2022-09-13 17:18:21 +0100
commit5202861b20d77b1d638da5f10af0f51ebcfc61bf (patch)
tree8b45da5525a74d97488a8d7e7a4f799adc5f23d1 /semihosting
parent7327e60237c36e9aa089141de547ca224ec5f3be (diff)
downloadqemu-5202861b20d77b1d638da5f10af0f51ebcfc61bf.zip
qemu-5202861b20d77b1d638da5f10af0f51ebcfc61bf.tar.gz
qemu-5202861b20d77b1d638da5f10af0f51ebcfc61bf.tar.bz2
semihosting: Allow optional use of semihosting from userspace
Currently our semihosting implementations generally prohibit use of semihosting calls in system emulation from the guest userspace. This is a very long standing behaviour justified originally "to provide some semblance of security" (since code with access to the semihosting ABI can do things like read and write arbitrary files on the host system). However, it is sometimes useful to be able to run trusted guest code which performs semihosting calls from guest userspace, notably for test code. Add a command line suboption to the existing semihosting-config option group so that you can explicitly opt in to semihosting from guest userspace with -semihosting-config userspace=on (There is no equivalent option for the user-mode emulator, because there by definition all code runs in userspace and has access to semihosting already.) This commit adds the infrastructure for the command line option and adds a bool 'is_user' parameter to the function semihosting_userspace_enabled() that target code can use to check whether it should be permitting the semihosting call for userspace. It mechanically makes all the callsites pass 'false', so they continue checking "is semihosting enabled in general". Subsequent commits will make each target that implements semihosting honour the userspace=on option by passing the correct value and removing whatever "don't do this for userspace" checking they were doing by hand. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Acked-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20220822141230.3658237-2-peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'semihosting')
-rw-r--r--semihosting/config.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/semihosting/config.c b/semihosting/config.c
index e171d4d..89a1759 100644
--- a/semihosting/config.c
+++ b/semihosting/config.c
@@ -35,6 +35,9 @@ QemuOptsList qemu_semihosting_config_opts = {
.name = "enable",
.type = QEMU_OPT_BOOL,
}, {
+ .name = "userspace",
+ .type = QEMU_OPT_BOOL,
+ }, {
.name = "target",
.type = QEMU_OPT_STRING,
}, {
@@ -50,6 +53,7 @@ QemuOptsList qemu_semihosting_config_opts = {
typedef struct SemihostingConfig {
bool enabled;
+ bool userspace_enabled;
SemihostingTarget target;
char **argv;
int argc;
@@ -59,9 +63,9 @@ typedef struct SemihostingConfig {
static SemihostingConfig semihosting;
static const char *semihost_chardev;
-bool semihosting_enabled(void)
+bool semihosting_enabled(bool is_user)
{
- return semihosting.enabled;
+ return semihosting.enabled && (!is_user || semihosting.userspace_enabled);
}
SemihostingTarget semihosting_get_target(void)
@@ -137,6 +141,8 @@ int qemu_semihosting_config_options(const char *optarg)
if (opts != NULL) {
semihosting.enabled = qemu_opt_get_bool(opts, "enable",
true);
+ semihosting.userspace_enabled = qemu_opt_get_bool(opts, "userspace",
+ false);
const char *target = qemu_opt_get(opts, "target");
/* setup of chardev is deferred until they are initialised */
semihost_chardev = qemu_opt_get(opts, "chardev");