mirror of
https://github.com/xemu-project/xemu.git
synced 2025-02-15 09:37:48 +00:00
qdev-properties: Add a new macro with bitmask check for uint64_t property
The DEFINE_PROP_UINT64_CHECKMASK maro applies certain mask check agaist user-supplied property value, reject the value if it violates the bitmask. Co-developed-by: Like Xu <like.xu@linux.intel.com> Signed-off-by: Like Xu <like.xu@linux.intel.com> Signed-off-by: Yang Weijiang <weijiang.yang@intel.com> Message-Id: <20220215195258.29149-2-weijiang.yang@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
6df39f5e58
commit
18c22d7112
@ -428,6 +428,25 @@ const PropertyInfo qdev_prop_int64 = {
|
|||||||
.set_default_value = qdev_propinfo_set_default_value_int,
|
.set_default_value = qdev_propinfo_set_default_value_int,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void set_uint64_checkmask(Object *obj, Visitor *v, const char *name,
|
||||||
|
void *opaque, Error **errp)
|
||||||
|
{
|
||||||
|
Property *prop = opaque;
|
||||||
|
uint64_t *ptr = object_field_prop_ptr(obj, prop);
|
||||||
|
|
||||||
|
visit_type_uint64(v, name, ptr, errp);
|
||||||
|
if (*ptr & ~prop->bitmask) {
|
||||||
|
error_setg(errp, "Property value for '%s' has bits outside mask '0x%" PRIx64 "'",
|
||||||
|
name, prop->bitmask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const PropertyInfo qdev_prop_uint64_checkmask = {
|
||||||
|
.name = "uint64",
|
||||||
|
.get = get_uint64,
|
||||||
|
.set = set_uint64_checkmask,
|
||||||
|
};
|
||||||
|
|
||||||
/* --- string --- */
|
/* --- string --- */
|
||||||
|
|
||||||
static void release_string(Object *obj, const char *name, void *opaque)
|
static void release_string(Object *obj, const char *name, void *opaque)
|
||||||
|
@ -17,6 +17,7 @@ struct Property {
|
|||||||
const PropertyInfo *info;
|
const PropertyInfo *info;
|
||||||
ptrdiff_t offset;
|
ptrdiff_t offset;
|
||||||
uint8_t bitnr;
|
uint8_t bitnr;
|
||||||
|
uint64_t bitmask;
|
||||||
bool set_default;
|
bool set_default;
|
||||||
union {
|
union {
|
||||||
int64_t i;
|
int64_t i;
|
||||||
@ -54,6 +55,7 @@ extern const PropertyInfo qdev_prop_uint16;
|
|||||||
extern const PropertyInfo qdev_prop_uint32;
|
extern const PropertyInfo qdev_prop_uint32;
|
||||||
extern const PropertyInfo qdev_prop_int32;
|
extern const PropertyInfo qdev_prop_int32;
|
||||||
extern const PropertyInfo qdev_prop_uint64;
|
extern const PropertyInfo qdev_prop_uint64;
|
||||||
|
extern const PropertyInfo qdev_prop_uint64_checkmask;
|
||||||
extern const PropertyInfo qdev_prop_int64;
|
extern const PropertyInfo qdev_prop_int64;
|
||||||
extern const PropertyInfo qdev_prop_size;
|
extern const PropertyInfo qdev_prop_size;
|
||||||
extern const PropertyInfo qdev_prop_string;
|
extern const PropertyInfo qdev_prop_string;
|
||||||
@ -103,6 +105,16 @@ extern const PropertyInfo qdev_prop_link;
|
|||||||
.set_default = true, \
|
.set_default = true, \
|
||||||
.defval.u = (bool)_defval)
|
.defval.u = (bool)_defval)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DEFINE_PROP_UINT64_CHECKMASK macro checks a user-supplied value
|
||||||
|
* against corresponding bitmask, rejects the value if it violates.
|
||||||
|
* The default value is set in instance_init().
|
||||||
|
*/
|
||||||
|
#define DEFINE_PROP_UINT64_CHECKMASK(_name, _state, _field, _bitmask) \
|
||||||
|
DEFINE_PROP(_name, _state, _field, qdev_prop_uint64_checkmask, uint64_t, \
|
||||||
|
.bitmask = (_bitmask), \
|
||||||
|
.set_default = false)
|
||||||
|
|
||||||
#define PROP_ARRAY_LEN_PREFIX "len-"
|
#define PROP_ARRAY_LEN_PREFIX "len-"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user