[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 06/21] cpuid: Replace strtok with get_opt_name
From: |
Andre Przywara |
Subject: |
[Qemu-devel] [PATCH v2 06/21] cpuid: Replace strtok with get_opt_name |
Date: |
Fri, 18 Sep 2009 13:47:59 +0200 |
From: Andre Przywara <address@hidden>
To avoid the non-reentrant capable strtok() use the QEMU defined
get_opt_name() to parse the -cpu parameter list. Since there is a
name clash between linux-user/mmap.c:qemu_malloc() and
qemu-malloc.c:qemu_malloc() I copied the small function from
qemu-option.c into cpuid.c. Not the best solution, bit IMO the
least intrusive and smallest one.
Signed-off-by: Andre Przywara <address@hidden>
---
target-i386/cpuid.c | 34 ++++++++++++++++++++++++----------
1 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index fca4ba6..ec88e20 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -26,6 +26,23 @@
//#define DEBUG_MMU
+static const char *get_opt_name(char *buf, int buf_size,
+ const char *p, char delim)
+{
+ char *q;
+
+ q = buf;
+ while (*p != '\0' && *p != delim) {
+ if (q && (q - buf) < buf_size - 1)
+ *q++ = *p;
+ p++;
+ }
+ if (q)
+ *q = '\0';
+
+ return p;
+}
+
/* feature flags taken from "Intel Processor Identification and the CPUID
* Instruction" and AMD's "CPUID Specification". In cases of disagreement
* about feature names, the Linux name is used. */
@@ -403,22 +420,23 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def,
const char *cpu_model)
unsigned int i;
x86_def_t *def;
- char *s = strdup(cpu_model);
- char *featurestr, *name = strtok(s, ",");
+ const char* s;
+ char featurestr[64];
uint32_t plus_features = 0, plus_ext_features = 0;
uint32_t plus_ext2_features = 0, plus_ext3_features = 0;
uint32_t minus_features = 0, minus_ext_features = 0;
uint32_t minus_ext2_features = 0, minus_ext3_features = 0;
uint32_t numvalue;
+ s = get_opt_name(featurestr, 64, cpu_model, ',');
def = NULL;
for (i = 0; i < ARRAY_SIZE(x86_defs); i++) {
- if (strcmp(name, x86_defs[i].name) == 0) {
+ if (strcmp(featurestr, x86_defs[i].name) == 0) {
def = &x86_defs[i];
break;
}
}
- if (kvm_enabled() && strcmp(name, "host") == 0) {
+ if (kvm_enabled() && strcmp(featurestr, "host") == 0) {
cpu_x86_fill_host(x86_cpu_def);
} else if (!def) {
goto error;
@@ -429,10 +447,9 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def,
const char *cpu_model)
add_flagname_to_bitmaps("hypervisor", &plus_features,
&plus_ext_features, &plus_ext2_features, &plus_ext3_features);
- featurestr = strtok(NULL, ",");
-
- while (featurestr) {
+ while (*s != 0) {
char *val;
+ s = get_opt_name(featurestr, 64, s + 1, ',');
if (featurestr[0] == '+') {
add_flagname_to_bitmaps(featurestr + 1, &plus_features,
&plus_ext_features, &plus_ext2_features, &plus_ext3_features);
@@ -511,7 +528,6 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def,
const char *cpu_model)
"(+feature|-feature|feature=xyz)\n", featurestr);
goto error;
}
- featurestr = strtok(NULL, ",");
}
x86_cpu_def->features |= plus_features;
x86_cpu_def->ext_features |= plus_ext_features;
@@ -521,11 +537,9 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def,
const char *cpu_model)
x86_cpu_def->ext_features &= ~minus_ext_features;
x86_cpu_def->ext2_features &= ~minus_ext2_features;
x86_cpu_def->ext3_features &= ~minus_ext3_features;
- free(s);
return 0;
error:
- free(s);
return -1;
}
--
1.6.1.3
- [Qemu-devel] [PATCH v2 00/21] cpuid: cleanup, fixes and some enhancements, Andre Przywara, 2009/09/18
- [Qemu-devel] [PATCH v2 04/21] cpuid: fix comments, Andre Przywara, 2009/09/18
- [Qemu-devel] [PATCH v2 06/21] cpuid: Replace strtok with get_opt_name,
Andre Przywara <=
- [Qemu-devel] [PATCH v2 02/21] cpuid: fix over-long lines, Andre Przywara, 2009/09/18
- [Qemu-devel] [PATCH v2 07/21] cpuid: add missing CPUID feature flag names, Andre Przywara, 2009/09/18
- [Qemu-devel] [PATCH v2 10/21] cpuid: simplify CPUID flag search function, Andre Przywara, 2009/09/18
- [Qemu-devel] [PATCH v2 09/21] cpuid: remove unnecessary kvm_trim function, Andre Przywara, 2009/09/18
- [Qemu-devel] [PATCH v2 13/21] cpuid: add TCG feature bit trimming, Andre Przywara, 2009/09/18
- [Qemu-devel] [PATCH v2 08/21] cpuid: list all known x86 CPUID feature flags, Andre Przywara, 2009/09/18
- [Qemu-devel] [PATCH v2 15/21] cpuid: Adjust feature bit constants, Andre Przywara, 2009/09/18
- [Qemu-devel] [PATCH v2 16/21] cpuid: Update qemu64/32 CPU models, Andre Przywara, 2009/09/18
- [Qemu-devel] [PATCH v2 14/21] cpuid: decrease L2 cache for Intel and add comments, Andre Przywara, 2009/09/18
- [Qemu-devel] [PATCH v2 01/21] cpuid: move CPUID functions into separate file, Andre Przywara, 2009/09/18