From 75b208c28316095c4685e8596ceb9e3f656592e2 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 23 Nov 2020 07:17:47 -0500 Subject: target/i386: fix operand order for PDEP and PEXT For PDEP and PEXT, the mask is provided in the memory (mod+r/m) operand, and therefore is loaded in s->T0 by gen_ldst_modrm. The source is provided in the second source operand (VEX.vvvv) and therefore is loaded in s->T1. Fix the order in which they are passed to the helpers. Reported-by: Lenard Szolnoki Analyzed-by: Lenard Szolnoki Fixes: https://bugs.launchpad.net/qemu/+bug/1605123 Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- tests/tcg/i386/Makefile.target | 3 +++ tests/tcg/i386/test-i386-bmi2.c | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/tcg/i386/test-i386-bmi2.c (limited to 'tests') diff --git a/tests/tcg/i386/Makefile.target b/tests/tcg/i386/Makefile.target index a66232a67d..ad187cb2c9 100644 --- a/tests/tcg/i386/Makefile.target +++ b/tests/tcg/i386/Makefile.target @@ -18,6 +18,9 @@ test-i386-pcmpistri: CFLAGS += -msse4.2 run-test-i386-pcmpistri: QEMU_OPTS += -cpu max run-plugin-test-i386-pcmpistri-%: QEMU_OPTS += -cpu max +run-test-i386-bmi2: QEMU_OPTS += -cpu max +run-plugin-test-i386-bmi2-%: QEMU_OPTS += -cpu max + # # hello-i386 is a barebones app # diff --git a/tests/tcg/i386/test-i386-bmi2.c b/tests/tcg/i386/test-i386-bmi2.c new file mode 100644 index 0000000000..935a4d2a73 --- /dev/null +++ b/tests/tcg/i386/test-i386-bmi2.c @@ -0,0 +1,42 @@ +/* See if various BMI2 instructions give expected results */ +#include +#include + +int main(int argc, char *argv[]) { + uint64_t ehlo = 0x202020204f4c4845ull; + uint64_t mask = 0xa080800302020001ull; + uint32_t result32; + +#ifdef __x86_64 + uint64_t result64; + + /* 64 bits */ + asm volatile ("pextq %2, %1, %0" : "=r"(result64) : "r"(ehlo), "m"(mask)); + assert(result64 == 133); + + asm volatile ("pdepq %2, %1, %0" : "=r"(result64) : "r"(result64), "m"(mask)); + assert(result64 == (ehlo & mask)); + + asm volatile ("pextq %2, %1, %0" : "=r"(result64) : "r"(-1ull), "m"(mask)); + assert(result64 == 511); /* mask has 9 bits set */ + + asm volatile ("pdepq %2, %1, %0" : "=r"(result64) : "r"(-1ull), "m"(mask)); + assert(result64 == mask); +#endif + + /* 32 bits */ + asm volatile ("pextl %2, %k1, %k0" : "=r"(result32) : "r"((uint32_t) ehlo), "m"(mask)); + assert(result32 == 5); + + asm volatile ("pdepl %2, %k1, %k0" : "=r"(result32) : "r"(result32), "m"(mask)); + assert(result32 == (uint32_t)(ehlo & mask)); + + asm volatile ("pextl %2, %k1, %k0" : "=r"(result32) : "r"(-1ull), "m"(mask)); + assert(result32 == 7); /* mask has 3 bits set */ + + asm volatile ("pdepl %2, %k1, %k0" : "=r"(result32) : "r"(-1ull), "m"(mask)); + assert(result32 == (uint32_t)mask); + + return 0; +} + -- cgit v1.2.3-55-g7522 From 991c180d740c04c2f8c08c8783ad868fc832589f Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 13 Nov 2020 03:10:52 -0500 Subject: treewide: do not use short-form boolean options They are going to be deprecated, avoid warnings on stdout while the tests run. Signed-off-by: Paolo Bonzini --- docs/specs/tpm.rst | 2 +- python/qemu/machine.py | 2 +- qemu-options.hx | 32 ++++++++++++++++---------------- tests/qtest/bios-tables-test.c | 4 ++-- tests/qtest/pflash-cfi02-test.c | 4 ++-- tests/qtest/test-filter-redirector.c | 8 ++++---- tests/qtest/vhost-user-test.c | 8 ++++---- tests/test-char.c | 8 ++++---- 8 files changed, 34 insertions(+), 34 deletions(-) (limited to 'tests') diff --git a/docs/specs/tpm.rst b/docs/specs/tpm.rst index 5e9aef4db3..3be190343a 100644 --- a/docs/specs/tpm.rst +++ b/docs/specs/tpm.rst @@ -343,7 +343,7 @@ In case an Arm virt machine is emulated, use the following command line: -device tpm-tis-device,tpmdev=tpm0 \ -device virtio-blk-pci,drive=drv0 \ -drive format=qcow2,file=hda.qcow2,if=none,id=drv0 \ - -drive if=pflash,format=raw,file=flash0.img,readonly \ + -drive if=pflash,format=raw,file=flash0.img,readonly=on \ -drive if=pflash,format=raw,file=flash1.img In case SeaBIOS is used as firmware, it should show the TPM menu item diff --git a/python/qemu/machine.py b/python/qemu/machine.py index 64d966aeeb..7a40f4604b 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -292,7 +292,7 @@ class QEMUMachine: for _ in range(self._console_index): args.extend(['-serial', 'null']) if self._console_set: - chardev = ('socket,id=console,path=%s,server,nowait' % + chardev = ('socket,id=console,path=%s,server=on,wait=off' % self._console_address) args.extend(['-chardev', chardev]) if self._console_device_type is None: diff --git a/qemu-options.hx b/qemu-options.hx index 104632ea34..e60ad42976 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1406,25 +1406,25 @@ ERST DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, "-fsdev local,id=id,path=path,security_model=mapped-xattr|mapped-file|passthrough|none\n" - " [,writeout=immediate][,readonly][,fmode=fmode][,dmode=dmode]\n" + " [,writeout=immediate][,readonly=on][,fmode=fmode][,dmode=dmode]\n" " [[,throttling.bps-total=b]|[[,throttling.bps-read=r][,throttling.bps-write=w]]]\n" " [[,throttling.iops-total=i]|[[,throttling.iops-read=r][,throttling.iops-write=w]]]\n" " [[,throttling.bps-total-max=bm]|[[,throttling.bps-read-max=rm][,throttling.bps-write-max=wm]]]\n" " [[,throttling.iops-total-max=im]|[[,throttling.iops-read-max=irm][,throttling.iops-write-max=iwm]]]\n" " [[,throttling.iops-size=is]]\n" - "-fsdev proxy,id=id,socket=socket[,writeout=immediate][,readonly]\n" - "-fsdev proxy,id=id,sock_fd=sock_fd[,writeout=immediate][,readonly]\n" + "-fsdev proxy,id=id,socket=socket[,writeout=immediate][,readonly=on]\n" + "-fsdev proxy,id=id,sock_fd=sock_fd[,writeout=immediate][,readonly=on]\n" "-fsdev synth,id=id\n", QEMU_ARCH_ALL) SRST -``-fsdev local,id=id,path=path,security_model=security_model [,writeout=writeout][,readonly][,fmode=fmode][,dmode=dmode] [,throttling.option=value[,throttling.option=value[,...]]]`` +``-fsdev local,id=id,path=path,security_model=security_model [,writeout=writeout][,readonly=on][,fmode=fmode][,dmode=dmode] [,throttling.option=value[,throttling.option=value[,...]]]`` \ -``-fsdev proxy,id=id,socket=socket[,writeout=writeout][,readonly]`` +``-fsdev proxy,id=id,socket=socket[,writeout=writeout][,readonly=on]`` \ -``-fsdev proxy,id=id,sock_fd=sock_fd[,writeout=writeout][,readonly]`` +``-fsdev proxy,id=id,sock_fd=sock_fd[,writeout=writeout][,readonly=on]`` \ -``-fsdev synth,id=id[,readonly]`` +``-fsdev synth,id=id[,readonly=on]`` Define a new file system device. Valid options are: ``local`` @@ -1467,7 +1467,7 @@ SRST guest only when the data has been reported as written by the storage subsystem. - ``readonly`` + ``readonly=on`` Enables exporting 9p share as a readonly mount for guests. By default read-write access is given. @@ -1532,18 +1532,18 @@ ERST DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs, "-virtfs local,path=path,mount_tag=tag,security_model=mapped-xattr|mapped-file|passthrough|none\n" - " [,id=id][,writeout=immediate][,readonly][,fmode=fmode][,dmode=dmode][,multidevs=remap|forbid|warn]\n" - "-virtfs proxy,mount_tag=tag,socket=socket[,id=id][,writeout=immediate][,readonly]\n" - "-virtfs proxy,mount_tag=tag,sock_fd=sock_fd[,id=id][,writeout=immediate][,readonly]\n" - "-virtfs synth,mount_tag=tag[,id=id][,readonly]\n", + " [,id=id][,writeout=immediate][,readonly=on][,fmode=fmode][,dmode=dmode][,multidevs=remap|forbid|warn]\n" + "-virtfs proxy,mount_tag=tag,socket=socket[,id=id][,writeout=immediate][,readonly=on]\n" + "-virtfs proxy,mount_tag=tag,sock_fd=sock_fd[,id=id][,writeout=immediate][,readonly=on]\n" + "-virtfs synth,mount_tag=tag[,id=id][,readonly=on]\n", QEMU_ARCH_ALL) SRST -``-virtfs local,path=path,mount_tag=mount_tag ,security_model=security_model[,writeout=writeout][,readonly] [,fmode=fmode][,dmode=dmode][,multidevs=multidevs]`` +``-virtfs local,path=path,mount_tag=mount_tag ,security_model=security_model[,writeout=writeout][,readonly=on] [,fmode=fmode][,dmode=dmode][,multidevs=multidevs]`` \ -``-virtfs proxy,socket=socket,mount_tag=mount_tag [,writeout=writeout][,readonly]`` +``-virtfs proxy,socket=socket,mount_tag=mount_tag [,writeout=writeout][,readonly=on]`` \ -``-virtfs proxy,sock_fd=sock_fd,mount_tag=mount_tag [,writeout=writeout][,readonly]`` +``-virtfs proxy,sock_fd=sock_fd,mount_tag=mount_tag [,writeout=writeout][,readonly=on]`` \ ``-virtfs synth,mount_tag=mount_tag`` Define a new virtual filesystem device and expose it to the guest using @@ -1598,7 +1598,7 @@ SRST guest only when the data has been reported as written by the storage subsystem. - ``readonly`` + ``readonly=on`` Enables exporting 9p share as a readonly mount for guests. By default read-write access is given. diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c index f2f79dd6a4..4e026f90d0 100644 --- a/tests/qtest/bios-tables-test.c +++ b/tests/qtest/bios-tables-test.c @@ -674,14 +674,14 @@ static void test_acpi_one(const char *params, test_data *data) if (data->cd) { args = g_strdup_printf("-machine %s %s -accel tcg " "-nodefaults -nographic " - "-drive if=pflash,format=raw,file=%s,readonly " + "-drive if=pflash,format=raw,file=%s,readonly=on " "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s", data->machine, data->tcg_only ? "" : "-accel kvm", data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : ""); } else { args = g_strdup_printf("-machine %s %s -accel tcg " "-nodefaults -nographic " - "-drive if=pflash,format=raw,file=%s,readonly " + "-drive if=pflash,format=raw,file=%s,readonly=on " "-drive if=pflash,format=raw,file=%s,snapshot=on %s", data->machine, data->tcg_only ? "" : "-accel kvm", data->uefi_fl1, data->uefi_fl2, params ? params : ""); diff --git a/tests/qtest/pflash-cfi02-test.c b/tests/qtest/pflash-cfi02-test.c index afb702b565..60db81a3a2 100644 --- a/tests/qtest/pflash-cfi02-test.c +++ b/tests/qtest/pflash-cfi02-test.c @@ -261,7 +261,7 @@ static void test_geometry(const void *opaque) const FlashConfig *config = opaque; QTestState *qtest; qtest = qtest_initf("-M musicpal" - " -drive if=pflash,file=%s,format=raw,copy-on-read" + " -drive if=pflash,file=%s,format=raw,copy-on-read=on" /* Device geometry properties. */ " -global driver=cfi.pflash02," "property=num-blocks0,value=%d" @@ -581,7 +581,7 @@ static void test_cfi_in_autoselect(const void *opaque) const FlashConfig *config = opaque; QTestState *qtest; qtest = qtest_initf("-M musicpal" - " -drive if=pflash,file=%s,format=raw,copy-on-read", + " -drive if=pflash,file=%s,format=raw,copy-on-read=on", image_path); FlashConfig explicit_config = expand_config_defaults(config); explicit_config.qtest = qtest; diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter-redirector.c index 829db8c2ea..4269b2cdd9 100644 --- a/tests/qtest/test-filter-redirector.c +++ b/tests/qtest/test-filter-redirector.c @@ -95,8 +95,8 @@ static void test_redirector_tx(void) qts = qtest_initf( "-netdev socket,id=qtest-bn0,fd=%d " "-device %s,netdev=qtest-bn0,id=qtest-e0 " - "-chardev socket,id=redirector0,path=%s,server,nowait " - "-chardev socket,id=redirector1,path=%s,server,nowait " + "-chardev socket,id=redirector0,path=%s,server=on,wait=off " + "-chardev socket,id=redirector1,path=%s,server=on,wait=off " "-chardev socket,id=redirector2,path=%s " "-object filter-redirector,id=qtest-f0,netdev=qtest-bn0," "queue=tx,outdev=redirector0 " @@ -165,8 +165,8 @@ static void test_redirector_rx(void) qts = qtest_initf( "-netdev socket,id=qtest-bn0,fd=%d " "-device %s,netdev=qtest-bn0,id=qtest-e0 " - "-chardev socket,id=redirector0,path=%s,server,nowait " - "-chardev socket,id=redirector1,path=%s,server,nowait " + "-chardev socket,id=redirector0,path=%s,server=on,wait=off " + "-chardev socket,id=redirector1,path=%s,server=on,wait=off " "-chardev socket,id=redirector2,path=%s " "-object filter-redirector,id=qtest-f0,netdev=qtest-bn0," "queue=rx,indev=redirector0 " diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index 3df5322614..1a5f5313ff 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -537,7 +537,7 @@ static void test_server_create_chr(TestServer *server, const gchar *opt) static void test_server_listen(TestServer *server) { - test_server_create_chr(server, ",server,nowait"); + test_server_create_chr(server, ",server=on,wait=off"); } static void test_server_free(TestServer *server) @@ -846,7 +846,7 @@ static void *vhost_user_test_setup_reconnect(GString *cmd_line, void *arg) g_thread_new("connect", connect_thread, s); append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); - s->vu_ops->append_opts(s, cmd_line, ",server"); + s->vu_ops->append_opts(s, cmd_line, ",server=on"); g_test_queue_destroy(vhost_user_test_cleanup, s); @@ -883,7 +883,7 @@ static void *vhost_user_test_setup_connect_fail(GString *cmd_line, void *arg) g_thread_new("connect", connect_thread, s); append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); - s->vu_ops->append_opts(s, cmd_line, ",server"); + s->vu_ops->append_opts(s, cmd_line, ",server=on"); g_test_queue_destroy(vhost_user_test_cleanup, s); @@ -898,7 +898,7 @@ static void *vhost_user_test_setup_flags_mismatch(GString *cmd_line, void *arg) g_thread_new("connect", connect_thread, s); append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); - s->vu_ops->append_opts(s, cmd_line, ",server"); + s->vu_ops->append_opts(s, cmd_line, ",server=on"); g_test_queue_destroy(vhost_user_test_cleanup, s); diff --git a/tests/test-char.c b/tests/test-char.c index 9196e566e9..953e0d1c1f 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -413,7 +413,7 @@ static void char_websock_test(void) CharBackend client_be; Chardev *chr_client; Chardev *chr = qemu_chr_new("server", - "websocket:127.0.0.1:0,server,nowait", NULL); + "websocket:127.0.0.1:0,server=on,wait=off", NULL); const char handshake[] = "GET / HTTP/1.1\r\n" "Upgrade: websocket\r\n" "Connection: Upgrade\r\n" @@ -696,7 +696,7 @@ char_socket_addr_to_opt_str(SocketAddress *addr, bool fd_pass, fd = ioc->fd; ioc->fd = -1; optstr = g_strdup_printf("socket,id=cdev0,fd=%d%s", - fd, is_listen ? ",server,nowait" : ""); + fd, is_listen ? ",server=on,wait=off" : ""); object_unref(OBJECT(ioc)); return optstr; } else { @@ -706,13 +706,13 @@ char_socket_addr_to_opt_str(SocketAddress *addr, bool fd_pass, addr->u.inet.host, addr->u.inet.port, reconnect ? reconnect : "", - is_listen ? ",server,nowait" : ""); + is_listen ? ",server=on,wait=off" : ""); case SOCKET_ADDRESS_TYPE_UNIX: return g_strdup_printf("socket,id=cdev0,path=%s%s%s", addr->u.q_unix.path, reconnect ? reconnect : "", - is_listen ? ",server,nowait" : ""); + is_listen ? ",server=on,wait=off" : ""); default: g_assert_not_reached(); -- cgit v1.2.3-55-g7522 From 32c02fdda49b8ace1517f1b95bfc215e0b92a154 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 9 Nov 2020 04:46:30 -0500 Subject: qemu-option: restrict qemu_opts_set to merge-lists QemuOpts qemu_opts_set is used to create default network backends and to parse sugar options -kernel, -initrd, -append, -bios and -dtb. These are very different uses: I would *expect* a function named qemu_opts_set to set an option in a merge-lists QemuOptsList, such as -kernel, and possibly to set an option in a non-merge-lists QemuOptsList with non-NULL id, similar to -set. However, it wouldn't *work* to use qemu_opts_set for the latter because qemu_opts_set uses fail_if_exists==1. So, for non-merge-lists QemuOptsList and non-NULL id, the semantics of qemu_opts_set (fail if the (QemuOptsList, id) pair already exists) are debatable. On the other hand, I would not expect qemu_opts_set to create a non-merge-lists QemuOpts with a single option; which it does, though. For this case of non-merge-lists QemuOptsList and NULL id, qemu_opts_set hardly adds value over qemu_opts_parse. It does skip some parsing and unescaping, but that's not needed when creating default network backends. So qemu_opts_set has warty behavior for non-merge-lists QemuOptsList if id is non-NULL, and it's mostly pointless if id is NULL. My solution to keeping the API as simple as possible is to limit qemu_opts_set to merge-lists QemuOptsList. For them, it's useful (we don't want comma-unescaping for -kernel) *and* has sane semantics. Network backend creation is switched to qemu_opts_parse. qemu_opts_set is now only used on merge-lists QemuOptsList... except in the testcase, which is changed to use a merge-list QemuOptsList. With this change we can also remove the id parameter. With the parameter always NULL, we know that qemu_opts_create cannot fail and can pass &error_abort to it. Signed-off-by: Paolo Bonzini --- include/qemu/option.h | 3 +-- softmmu/vl.c | 19 +++++++------------ tests/test-qemu-opts.c | 20 +++++++++++++++++--- util/qemu-option.c | 9 +++------ 4 files changed, 28 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/include/qemu/option.h b/include/qemu/option.h index ac69352e0e..f73e0dc7d9 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -119,8 +119,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exists, Error **errp); void qemu_opts_reset(QemuOptsList *list); void qemu_opts_loc_restore(QemuOpts *opts); -bool qemu_opts_set(QemuOptsList *list, const char *id, - const char *name, const char *value, Error **errp); +bool qemu_opts_set(QemuOptsList *list, const char *name, const char *value, Error **errp); const char *qemu_opts_id(QemuOpts *opts); void qemu_opts_set_id(QemuOpts *opts, char *id); void qemu_opts_del(QemuOpts *opts); diff --git a/softmmu/vl.c b/softmmu/vl.c index 85b23d51be..5571f9ff75 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -3388,20 +3388,16 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_kernel: - qemu_opts_set(qemu_find_opts("machine"), NULL, "kernel", optarg, - &error_abort); + qemu_opts_set(qemu_find_opts("machine"), "kernel", optarg, &error_abort); break; case QEMU_OPTION_initrd: - qemu_opts_set(qemu_find_opts("machine"), NULL, "initrd", optarg, - &error_abort); + qemu_opts_set(qemu_find_opts("machine"), "initrd", optarg, &error_abort); break; case QEMU_OPTION_append: - qemu_opts_set(qemu_find_opts("machine"), NULL, "append", optarg, - &error_abort); + qemu_opts_set(qemu_find_opts("machine"), "append", optarg, &error_abort); break; case QEMU_OPTION_dtb: - qemu_opts_set(qemu_find_opts("machine"), NULL, "dtb", optarg, - &error_abort); + qemu_opts_set(qemu_find_opts("machine"), "dtb", optarg, &error_abort); break; case QEMU_OPTION_cdrom: drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); @@ -3511,8 +3507,7 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_bios: - qemu_opts_set(qemu_find_opts("machine"), NULL, "firmware", optarg, - &error_abort); + qemu_opts_set(qemu_find_opts("machine"), "firmware", optarg, &error_abort); break; case QEMU_OPTION_singlestep: singlestep = 1; @@ -4395,9 +4390,9 @@ void qemu_init(int argc, char **argv, char **envp) if (default_net) { QemuOptsList *net = qemu_find_opts("net"); - qemu_opts_set(net, NULL, "type", "nic", &error_abort); + qemu_opts_parse(net, "nic", true, &error_abort); #ifdef CONFIG_SLIRP - qemu_opts_set(net, NULL, "type", "user", &error_abort); + qemu_opts_parse(net, "user", true, &error_abort); #endif } diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c index 297ffe79dd..2aab831d10 100644 --- a/tests/test-qemu-opts.c +++ b/tests/test-qemu-opts.c @@ -84,11 +84,25 @@ static QemuOptsList opts_list_03 = { }, }; +static QemuOptsList opts_list_04 = { + .name = "opts_list_04", + .head = QTAILQ_HEAD_INITIALIZER(opts_list_04.head), + .merge_lists = true, + .desc = { + { + .name = "str3", + .type = QEMU_OPT_STRING, + }, + { /* end of list */ } + }, +}; + static void register_opts(void) { qemu_add_opts(&opts_list_01); qemu_add_opts(&opts_list_02); qemu_add_opts(&opts_list_03); + qemu_add_opts(&opts_list_04); } static void test_find_unknown_opts(void) @@ -402,17 +416,17 @@ static void test_qemu_opts_set(void) QemuOpts *opts; const char *opt; - list = qemu_find_opts("opts_list_01"); + list = qemu_find_opts("opts_list_04"); g_assert(list != NULL); g_assert(QTAILQ_EMPTY(&list->head)); - g_assert_cmpstr(list->name, ==, "opts_list_01"); + g_assert_cmpstr(list->name, ==, "opts_list_04"); /* should not find anything at this point */ opts = qemu_opts_find(list, NULL); g_assert(opts == NULL); /* implicitly create opts and set str3 value */ - qemu_opts_set(list, NULL, "str3", "value", &error_abort); + qemu_opts_set(list, "str3", "value", &error_abort); g_assert(!QTAILQ_EMPTY(&list->head)); /* get the just created opts */ diff --git a/util/qemu-option.c b/util/qemu-option.c index acefbc23fa..25792159ba 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -670,15 +670,12 @@ void qemu_opts_loc_restore(QemuOpts *opts) loc_restore(&opts->loc); } -bool qemu_opts_set(QemuOptsList *list, const char *id, - const char *name, const char *value, Error **errp) +bool qemu_opts_set(QemuOptsList *list, const char *name, const char *value, Error **errp) { QemuOpts *opts; - opts = qemu_opts_create(list, id, 1, errp); - if (!opts) { - return false; - } + assert(list->merge_lists); + opts = qemu_opts_create(list, NULL, 0, &error_abort); return qemu_opt_set(opts, name, value, errp); } -- cgit v1.2.3-55-g7522 From 2c65db5e58d2c74921077f6c064ba4c91ebde16a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 28 Oct 2020 07:36:57 -0400 Subject: vl: extract softmmu/datadir.c Reviewed-by: Igor Mammedov Signed-off-by: Paolo Bonzini --- hw/alpha/dp264.c | 1 + hw/arm/boot.c | 1 + hw/arm/digic_boards.c | 1 + hw/arm/highbank.c | 1 + hw/arm/npcm7xx_boards.c | 1 + hw/arm/sbsa-ref.c | 1 + hw/arm/vexpress.c | 1 + hw/arm/virt.c | 1 + hw/avr/boot.c | 1 + hw/core/loader.c | 1 + hw/display/cg3.c | 1 + hw/display/tcx.c | 1 + hw/hppa/machine.c | 1 + hw/i386/x86.c | 1 + hw/lm32/milkymist.c | 1 + hw/m68k/mcf5208.c | 1 + hw/m68k/q800.c | 1 + hw/microblaze/boot.c | 1 + hw/mips/fuloong2e.c | 1 + hw/mips/jazz.c | 1 + hw/mips/malta.c | 1 + hw/mips/mipssim.c | 1 + hw/nios2/boot.c | 1 + hw/nvram/fw_cfg.c | 1 + hw/pci-host/prep.c | 1 + hw/pci/pci.c | 1 + hw/ppc/e500.c | 1 + hw/ppc/mac_newworld.c | 1 + hw/ppc/mac_oldworld.c | 1 + hw/ppc/pnv.c | 1 + hw/ppc/ppc405_boards.c | 1 + hw/ppc/ppc440_bamboo.c | 1 + hw/ppc/sam460ex.c | 1 + hw/ppc/spapr.c | 1 + hw/ppc/virtex_ml507.c | 1 + hw/riscv/boot.c | 1 + hw/s390x/ipl.c | 1 + hw/sparc/leon3.c | 1 + hw/sparc/sun4m.c | 1 + hw/sparc64/sun4u.c | 1 + include/qemu-common.h | 21 -------- include/qemu/datadir.h | 28 +++++++++++ include/sysemu/sysemu.h | 2 - softmmu/datadir.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++ softmmu/meson.build | 1 + softmmu/vl.c | 95 ++--------------------------------- tests/qtest/fuzz/fuzz.c | 1 + ui/keymaps.c | 1 + 48 files changed, 203 insertions(+), 115 deletions(-) create mode 100644 include/qemu/datadir.h create mode 100644 softmmu/datadir.c (limited to 'tests') diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c index c4d407a9f1..c8e300d93f 100644 --- a/hw/alpha/dp264.c +++ b/hw/alpha/dp264.c @@ -21,6 +21,7 @@ #include "hw/dma/i8257.h" #include "net/net.h" #include "qemu/cutils.h" +#include "qemu/datadir.h" #include "net/net.h" #define MAX_IDE_BUS 2 diff --git a/hw/arm/boot.c b/hw/arm/boot.c index cf97600a91..4d9d47ba1c 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -9,6 +9,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qemu/error-report.h" #include "qapi/error.h" #include diff --git a/hw/arm/digic_boards.c b/hw/arm/digic_boards.c index fd228fa96f..be12873673 100644 --- a/hw/arm/digic_boards.c +++ b/hw/arm/digic_boards.c @@ -26,6 +26,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "cpu.h" #include "hw/boards.h" #include "exec/address-spaces.h" diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c index fd3429720e..bf7b8f4c64 100644 --- a/hw/arm/highbank.c +++ b/hw/arm/highbank.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qapi/error.h" #include "hw/sysbus.h" #include "migration/vmstate.h" diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c index 9821013bc6..306260fa67 100644 --- a/hw/arm/npcm7xx_boards.c +++ b/hw/arm/npcm7xx_boards.c @@ -23,6 +23,7 @@ #include "hw/qdev-properties.h" #include "qapi/error.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qemu/units.h" #include "sysemu/sysemu.h" diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c index 8272983664..9f70735153 100644 --- a/hw/arm/sbsa-ref.c +++ b/hw/arm/sbsa-ref.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/units.h" diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c index 1adb663d77..ac098375c1 100644 --- a/hw/arm/vexpress.c +++ b/hw/arm/vexpress.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "cpu.h" #include "hw/sysbus.h" #include "hw/arm/boot.h" diff --git a/hw/arm/virt.c b/hw/arm/virt.c index d09124832d..556592012e 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -30,6 +30,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qemu/units.h" #include "qemu/option.h" #include "monitor/qdev.h" diff --git a/hw/avr/boot.c b/hw/avr/boot.c index d16bb3dbe1..cbede775ce 100644 --- a/hw/avr/boot.c +++ b/hw/avr/boot.c @@ -10,6 +10,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "hw/loader.h" #include "elf.h" #include "boot.h" diff --git a/hw/core/loader.c b/hw/core/loader.c index 8bbb1797a4..fea22d265c 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -44,6 +44,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qapi/error.h" #include "trace.h" #include "hw/hw.h" diff --git a/hw/display/cg3.c b/hw/display/cg3.c index 42fcf40010..4b7e78d919 100644 --- a/hw/display/cg3.c +++ b/hw/display/cg3.c @@ -25,6 +25,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "ui/console.h" diff --git a/hw/display/tcx.c b/hw/display/tcx.c index 3799d29b75..965f92ff6b 100644 --- a/hw/display/tcx.c +++ b/hw/display/tcx.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qapi/error.h" #include "ui/console.h" #include "ui/pixel_ops.h" diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c index 7e41cb2462..f2b71db9bd 100644 --- a/hw/hppa/machine.c +++ b/hw/hppa/machine.c @@ -5,6 +5,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "cpu.h" #include "elf.h" #include "hw/loader.h" diff --git a/hw/i386/x86.c b/hw/i386/x86.c index f86f6dbbec..49e1d419b2 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -26,6 +26,7 @@ #include "qemu/cutils.h" #include "qemu/units.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" #include "qapi/qapi-visit-common.h" diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c index 93ca8bc2ac..72d1326531 100644 --- a/hw/lm32/milkymist.c +++ b/hw/lm32/milkymist.c @@ -21,6 +21,7 @@ #include "qemu/units.h" #include "qemu/error-report.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "cpu.h" #include "hw/sysbus.h" #include "hw/irq.h" diff --git a/hw/m68k/mcf5208.c b/hw/m68k/mcf5208.c index 2205145ecc..7a03c71059 100644 --- a/hw/m68k/mcf5208.c +++ b/hw/m68k/mcf5208.c @@ -12,6 +12,7 @@ #include "qemu/log.h" #include "qapi/error.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "cpu.h" #include "hw/irq.h" #include "hw/m68k/mcf.h" diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c index 6ebcddcfb2..4db2b9bbc7 100644 --- a/hw/m68k/q800.c +++ b/hw/m68k/q800.c @@ -23,6 +23,7 @@ #include "qemu/osdep.h" #include "qemu/units.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "sysemu/sysemu.h" #include "cpu.h" #include "hw/hw.h" diff --git a/hw/microblaze/boot.c b/hw/microblaze/boot.c index e1f56f83f9..6715ba2ff9 100644 --- a/hw/microblaze/boot.c +++ b/hw/microblaze/boot.c @@ -26,6 +26,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "cpu.h" #include "qemu/option.h" #include "qemu/config-file.h" diff --git a/hw/mips/fuloong2e.c b/hw/mips/fuloong2e.c index 84a2132f85..45c596f4fe 100644 --- a/hw/mips/fuloong2e.c +++ b/hw/mips/fuloong2e.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qemu/units.h" #include "qapi/error.h" #include "cpu.h" diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c index aa95c6a3d3..f9442731dd 100644 --- a/hw/mips/jazz.c +++ b/hw/mips/jazz.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "hw/clock.h" #include "hw/mips/mips.h" #include "hw/mips/cpudevs.h" diff --git a/hw/mips/malta.c b/hw/mips/malta.c index 467b21849e..5c11eecec1 100644 --- a/hw/mips/malta.c +++ b/hw/mips/malta.c @@ -25,6 +25,7 @@ #include "qemu/osdep.h" #include "qemu/units.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "cpu.h" #include "hw/clock.h" #include "hw/southbridge/piix.h" diff --git a/hw/mips/mipssim.c b/hw/mips/mipssim.c index cc9b0934b3..f2e6273525 100644 --- a/hw/mips/mipssim.c +++ b/hw/mips/mipssim.c @@ -28,6 +28,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "cpu.h" #include "hw/clock.h" #include "hw/mips/mips.h" diff --git a/hw/nios2/boot.c b/hw/nios2/boot.c index 3cb864914b..95a8697906 100644 --- a/hw/nios2/boot.c +++ b/hw/nios2/boot.c @@ -31,6 +31,7 @@ #include "qemu/osdep.h" #include "qemu/units.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "cpu.h" #include "qemu/option.h" #include "qemu/config-file.h" diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 282ba93e2e..44cb274a32 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "sysemu/sysemu.h" #include "sysemu/dma.h" #include "sysemu/reset.h" diff --git a/hw/pci-host/prep.c b/hw/pci-host/prep.c index d0323fefb1..0469db8c1d 100644 --- a/hw/pci-host/prep.c +++ b/hw/pci-host/prep.c @@ -25,6 +25,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qemu/units.h" #include "qapi/error.h" #include "hw/pci/pci.h" diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 0131d9d02c..9424231542 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "hw/irq.h" #include "hw/pci/pci.h" #include "hw/pci/pci_bridge.h" diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c index 153a74c98c..6a64eb31ab 100644 --- a/hw/ppc/e500.c +++ b/hw/ppc/e500.c @@ -16,6 +16,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qemu/units.h" #include "qapi/error.h" #include "e500.h" diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c index 61c63819df..c0accda592 100644 --- a/hw/ppc/mac_newworld.c +++ b/hw/ppc/mac_newworld.c @@ -48,6 +48,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qapi/error.h" #include "hw/ppc/ppc.h" #include "hw/qdev-properties.h" diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c index 11623e8e67..04f98a4d81 100644 --- a/hw/ppc/mac_oldworld.c +++ b/hw/ppc/mac_oldworld.c @@ -26,6 +26,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qemu/units.h" #include "qapi/error.h" #include "hw/ppc/ppc.h" diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 53a5121cab..14fc9758a9 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qemu/units.h" #include "qapi/error.h" #include "sysemu/qtest.h" diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c index c867e46330..b7249f21cf 100644 --- a/hw/ppc/ppc405_boards.c +++ b/hw/ppc/ppc405_boards.c @@ -26,6 +26,7 @@ #include "qemu/units.h" #include "qapi/error.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "cpu.h" #include "hw/ppc/ppc.h" #include "hw/qdev-properties.h" diff --git a/hw/ppc/ppc440_bamboo.c b/hw/ppc/ppc440_bamboo.c index 74028dc986..665bc1784e 100644 --- a/hw/ppc/ppc440_bamboo.c +++ b/hw/ppc/ppc440_bamboo.c @@ -15,6 +15,7 @@ #include "qemu/units.h" #include "qemu/error-report.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qemu/error-report.h" #include "net/net.h" #include "hw/pci/pci.h" diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c index 7e59a91981..14e6583eb0 100644 --- a/hw/ppc/sam460ex.c +++ b/hw/ppc/sam460ex.c @@ -14,6 +14,7 @@ #include "qemu/osdep.h" #include "qemu/units.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qemu/error-report.h" #include "qapi/error.h" #include "hw/boards.h" diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index e87a3b8557..3f5b0d0159 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -26,6 +26,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qapi/error.h" #include "qapi/visitor.h" #include "sysemu/sysemu.h" diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c index c790c1113f..7f1bca928c 100644 --- a/hw/ppc/virtex_ml507.c +++ b/hw/ppc/virtex_ml507.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qemu/units.h" #include "cpu.h" #include "hw/sysbus.h" diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c index 70a9bf8f5d..d62f3dc758 100644 --- a/hw/riscv/boot.c +++ b/hw/riscv/boot.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qemu/units.h" #include "qemu/error-report.h" #include "exec/cpu-defs.h" diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c index bddbaffac6..ff6b55e816 100644 --- a/hw/s390x/ipl.c +++ b/hw/s390x/ipl.c @@ -14,6 +14,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qapi/error.h" #include "sysemu/reset.h" #include "sysemu/runstate.h" diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c index 1c50b02f81..4bc4ebea84 100644 --- a/hw/sparc/leon3.c +++ b/hw/sparc/leon3.c @@ -27,6 +27,7 @@ #include "qemu/error-report.h" #include "qapi/error.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "cpu.h" #include "hw/irq.h" #include "qemu/timer.h" diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c index 0f9cd2bf52..8686371318 100644 --- a/hw/sparc/sun4m.c +++ b/hw/sparc/sun4m.c @@ -25,6 +25,7 @@ #include "qemu/osdep.h" #include "qemu/units.h" #include "qapi/error.h" +#include "qemu/datadir.h" #include "qemu-common.h" #include "cpu.h" #include "hw/sysbus.h" diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c index 8bee7dd2f4..0fa13a7330 100644 --- a/hw/sparc64/sun4u.c +++ b/hw/sparc64/sun4u.c @@ -27,6 +27,7 @@ #include "qemu/error-report.h" #include "qapi/error.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "cpu.h" #include "hw/pci/pci.h" #include "hw/pci/pci_bridge.h" diff --git a/include/qemu-common.h b/include/qemu-common.h index fda7dc6ca7..654621444e 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -108,27 +108,6 @@ void qemu_progress_end(void); void qemu_progress_print(float delta, int max); const char *qemu_get_vm_name(void); -#define QEMU_FILE_TYPE_BIOS 0 -#define QEMU_FILE_TYPE_KEYMAP 1 -/** - * qemu_find_file: - * @type: QEMU_FILE_TYPE_BIOS (for BIOS, VGA BIOS) - * or QEMU_FILE_TYPE_KEYMAP (for keymaps). - * @name: Relative or absolute file name - * - * If @name exists on disk as an absolute path, or a path relative - * to the current directory, then returns @name unchanged. - * Otherwise searches for @name file in the data directories, either - * configured at build time (DATADIR) or registered with the -L command - * line option. - * - * The caller must use g_free() to free the returned data when it is - * no longer required. - * - * Returns: a path that can access @name, or NULL if no matching file exists. - */ -char *qemu_find_file(int type, const char *name); - /* OS specific functions */ void os_setup_early_signal_handling(void); int os_parse_cmd_args(int index, const char *optarg); diff --git a/include/qemu/datadir.h b/include/qemu/datadir.h new file mode 100644 index 0000000000..21f9097f58 --- /dev/null +++ b/include/qemu/datadir.h @@ -0,0 +1,28 @@ +#ifndef QEMU_DATADIR_H +#define QEMU_DATADIR_H + +#define QEMU_FILE_TYPE_BIOS 0 +#define QEMU_FILE_TYPE_KEYMAP 1 +/** + * qemu_find_file: + * @type: QEMU_FILE_TYPE_BIOS (for BIOS, VGA BIOS) + * or QEMU_FILE_TYPE_KEYMAP (for keymaps). + * @name: Relative or absolute file name + * + * If @name exists on disk as an absolute path, or a path relative + * to the current directory, then returns @name unchanged. + * Otherwise searches for @name file in the data directories, either + * configured at build time (DATADIR) or registered with the -L command + * line option. + * + * The caller must use g_free() to free the returned data when it is + * no longer required. + * + * Returns: a path that can access @name, or NULL if no matching file exists. + */ +char *qemu_find_file(int type, const char *name); +void qemu_add_default_firmwarepath(void); +void qemu_add_data_dir(char *path); +void qemu_list_data_dirs(void); + +#endif diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 1336b4264a..c94b2e7159 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -13,8 +13,6 @@ extern const char *qemu_name; extern QemuUUID qemu_uuid; extern bool qemu_uuid_set; -void qemu_add_data_dir(char *path); - void qemu_add_exit_notifier(Notifier *notify); void qemu_remove_exit_notifier(Notifier *notify); diff --git a/softmmu/datadir.c b/softmmu/datadir.c new file mode 100644 index 0000000000..504c4665be --- /dev/null +++ b/softmmu/datadir.c @@ -0,0 +1,129 @@ +/* + * QEMU firmware and keymap file search + * + * Copyright (c) 2003-2020 QEMU contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/datadir.h" +#include "qemu/cutils.h" +#include "trace.h" + +static const char *data_dir[16]; +static int data_dir_idx; + +char *qemu_find_file(int type, const char *name) +{ + int i; + const char *subdir; + char *buf; + + /* Try the name as a straight path first */ + if (access(name, R_OK) == 0) { + trace_load_file(name, name); + return g_strdup(name); + } + + switch (type) { + case QEMU_FILE_TYPE_BIOS: + subdir = ""; + break; + case QEMU_FILE_TYPE_KEYMAP: + subdir = "keymaps/"; + break; + default: + abort(); + } + + for (i = 0; i < data_dir_idx; i++) { + buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name); + if (access(buf, R_OK) == 0) { + trace_load_file(name, buf); + return buf; + } + g_free(buf); + } + return NULL; +} + +void qemu_add_data_dir(char *path) +{ + int i; + + if (path == NULL) { + return; + } + if (data_dir_idx == ARRAY_SIZE(data_dir)) { + return; + } + for (i = 0; i < data_dir_idx; i++) { + if (strcmp(data_dir[i], path) == 0) { + g_free(path); /* duplicate */ + return; + } + } + data_dir[data_dir_idx++] = path; +} + +/* + * Find a likely location for support files using the location of the binary. + * When running from the build tree this will be "$bindir/pc-bios". + * Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated). + * + * The caller must use g_free() to free the returned data when it is + * no longer required. + */ +static char *find_datadir(void) +{ + g_autofree char *dir = NULL; + + dir = g_build_filename(qemu_get_exec_dir(), "pc-bios", NULL); + if (g_file_test(dir, G_FILE_TEST_IS_DIR)) { + return g_steal_pointer(&dir); + } + + return get_relocated_path(CONFIG_QEMU_DATADIR); +} + +void qemu_add_default_firmwarepath(void) +{ + char **dirs; + size_t i; + + /* add configured firmware directories */ + dirs = g_strsplit(CONFIG_QEMU_FIRMWAREPATH, G_SEARCHPATH_SEPARATOR_S, 0); + for (i = 0; dirs[i] != NULL; i++) { + qemu_add_data_dir(get_relocated_path(dirs[i])); + } + g_strfreev(dirs); + + /* try to find datadir relative to the executable path */ + qemu_add_data_dir(find_datadir()); +} + +void qemu_list_data_dirs(void) +{ + int i; + for (i = 0; i < data_dir_idx; i++) { + printf("%s\n", data_dir[i]); + } +} diff --git a/softmmu/meson.build b/softmmu/meson.build index 8f7210b4f0..7b52339e7a 100644 --- a/softmmu/meson.build +++ b/softmmu/meson.build @@ -3,6 +3,7 @@ specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files( 'balloon.c', 'cpus.c', 'cpu-throttle.c', + 'datadir.c', 'physmem.c', 'ioport.c', 'memory.c', diff --git a/softmmu/vl.c b/softmmu/vl.c index dc8a47efcb..28aafc1101 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "qemu/units.h" #include "hw/boards.h" #include "hw/qdev-properties.h" @@ -128,8 +129,6 @@ typedef struct BlockdevOptionsQueueEntry { typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry) BlockdevOptionsQueue; static const char *cpu_option; -static const char *data_dir[16]; -static int data_dir_idx; static const char *mem_path; static const char *boot_order; static const char *boot_once; @@ -1994,59 +1993,6 @@ static void parse_display(const char *p) } } -char *qemu_find_file(int type, const char *name) -{ - int i; - const char *subdir; - char *buf; - - /* Try the name as a straight path first */ - if (access(name, R_OK) == 0) { - trace_load_file(name, name); - return g_strdup(name); - } - - switch (type) { - case QEMU_FILE_TYPE_BIOS: - subdir = ""; - break; - case QEMU_FILE_TYPE_KEYMAP: - subdir = "keymaps/"; - break; - default: - abort(); - } - - for (i = 0; i < data_dir_idx; i++) { - buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name); - if (access(buf, R_OK) == 0) { - trace_load_file(name, buf); - return buf; - } - g_free(buf); - } - return NULL; -} - -void qemu_add_data_dir(char *path) -{ - int i; - - if (path == NULL) { - return; - } - if (data_dir_idx == ARRAY_SIZE(data_dir)) { - return; - } - for (i = 0; i < data_dir_idx; i++) { - if (strcmp(data_dir[i], path) == 0) { - g_free(path); /* duplicate */ - return; - } - } - data_dir[data_dir_idx++] = path; -} - static inline bool nonempty_str(const char *str) { return str && *str; @@ -3187,26 +3133,6 @@ static void create_default_memdev(MachineState *ms, const char *path) &error_fatal); } -/* - * Find a likely location for support files using the location of the binary. - * When running from the build tree this will be "$bindir/pc-bios". - * Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated). - * - * The caller must use g_free() to free the returned data when it is - * no longer required. - */ -static char *find_datadir(void) -{ - g_autofree char *dir = NULL; - - dir = g_build_filename(qemu_get_exec_dir(), "pc-bios", NULL); - if (g_file_test(dir, G_FILE_TEST_IS_DIR)) { - return g_steal_pointer(&dir); - } - - return get_relocated_path(CONFIG_QEMU_DATADIR); -} - static void qemu_validate_options(void) { QemuOpts *machine_opts = qemu_get_machine_opts(); @@ -3266,9 +3192,6 @@ static void qemu_process_sugar_options(void) static void qemu_process_early_options(void) { - char **dirs; - int i; - #ifdef CONFIG_SECCOMP QemuOptsList *olist = qemu_find_opts_err("sandbox", NULL); if (olist) { @@ -3306,21 +3229,11 @@ static void qemu_process_early_options(void) qemu_set_log(0); } - /* add configured firmware directories */ - dirs = g_strsplit(CONFIG_QEMU_FIRMWAREPATH, G_SEARCHPATH_SEPARATOR_S, 0); - for (i = 0; dirs[i] != NULL; i++) { - qemu_add_data_dir(get_relocated_path(dirs[i])); - } - g_strfreev(dirs); - - /* try to find datadir relative to the executable path */ - qemu_add_data_dir(find_datadir()); + qemu_add_default_firmwarepath(); } static void qemu_process_help_options(void) { - int i; - /* * Check for -cpu help and -device help before we call select_machine(), * which will return an error if the architecture has no default machine @@ -3339,9 +3252,7 @@ static void qemu_process_help_options(void) /* -L help lists the data directories and exits. */ if (list_data_dirs) { - for (i = 0; i < data_dir_idx; i++) { - printf("%s\n", data_dir[i]); - } + qemu_list_data_dirs(); exit(0); } } diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c index 7be7226bc0..238866a037 100644 --- a/tests/qtest/fuzz/fuzz.c +++ b/tests/qtest/fuzz/fuzz.c @@ -15,6 +15,7 @@ #include +#include "qemu/datadir.h" #include "sysemu/qtest.h" #include "sysemu/runstate.h" #include "sysemu/sysemu.h" diff --git a/ui/keymaps.c b/ui/keymaps.c index 4e5fca57a8..d4a647464b 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/datadir.h" #include "keymaps.h" #include "trace.h" #include "qemu/ctype.h" -- cgit v1.2.3-55-g7522