uint32_t vcpu);
#if defined(__i386__) || defined(__x86_64__)
-int xc_cpuid_check(xc_interface *xch,
- const unsigned int *input,
- const char **config,
- char **config_transformed);
int xc_cpuid_set(xc_interface *xch,
domid_t domid,
const unsigned int *input,
return rc;
}
-/*
- * Check whether a VM is allowed to launch on this host's processor type.
- *
- * @config format is similar to that of xc_cpuid_set():
- * '1' -> the bit must be set to 1
- * '0' -> must be 0
- * 'x' -> we don't care
- * 's' -> (same) must be the same
- */
-int xc_cpuid_check(
- xc_interface *xch, const unsigned int *input,
- const char **config,
- char **config_transformed)
-{
- int i, j, rc;
- unsigned int regs[4];
-
- memset(config_transformed, 0, 4 * sizeof(*config_transformed));
-
- cpuid(input, regs);
-
- for ( i = 0; i < 4; i++ )
- {
- if ( config[i] == NULL )
- continue;
- config_transformed[i] = alloc_str();
- if ( config_transformed[i] == NULL )
- {
- rc = -ENOMEM;
- goto fail_rc;
- }
- for ( j = 0; j < 32; j++ )
- {
- unsigned char val = !!((regs[i] & (1U << (31 - j))));
- if ( !strchr("10xs", config[i][j]) ||
- ((config[i][j] == '1') && !val) ||
- ((config[i][j] == '0') && val) )
- goto fail;
- config_transformed[i][j] = config[i][j];
- if ( config[i][j] == 's' )
- config_transformed[i][j] = '0' + val;
- }
- }
-
- return 0;
-
- fail:
- rc = -EPERM;
- fail_rc:
- for ( i = 0; i < 4; i++ )
- {
- free(config_transformed[i]);
- config_transformed[i] = NULL;
- }
- return rc;
-}
-
/*
* Configure a single input with the informatiom from config.
*
= "stub_xc_domain_cpuid_set"
external domain_cpuid_apply_policy: handle -> domid -> unit
= "stub_xc_domain_cpuid_apply_policy"
-external cpuid_check: handle -> (int64 * (int64 option)) -> string option array -> (bool * string option array)
- = "stub_xc_cpuid_check"
external map_foreign_range: handle -> domid -> int
-> nativeint -> Xenmmap.mmap_interface
= "stub_xc_domain_cpuid_set"
external domain_cpuid_apply_policy: handle -> domid -> unit
= "stub_xc_domain_cpuid_apply_policy"
-external cpuid_check: handle -> (int64 * (int64 option)) -> string option array -> (bool * string option array)
- = "stub_xc_cpuid_check"
-
CAMLreturn(Val_unit);
}
-CAMLprim value stub_xc_cpuid_check(value xch, value input, value config)
-{
- CAMLparam3(xch, input, config);
- CAMLlocal3(ret, array, tmp);
-#if defined(__i386__) || defined(__x86_64__)
- int r;
- unsigned int c_input[2];
- char *c_config[4], *out_config[4];
-
- c_config[0] = string_of_option_array(config, 0);
- c_config[1] = string_of_option_array(config, 1);
- c_config[2] = string_of_option_array(config, 2);
- c_config[3] = string_of_option_array(config, 3);
-
- cpuid_input_of_val(c_input[0], c_input[1], input);
-
- array = caml_alloc(4, 0);
- for (r = 0; r < 4; r++) {
- tmp = Val_none;
- if (c_config[r]) {
- tmp = caml_alloc_small(1, 0);
- Field(tmp, 0) = caml_alloc_string(32);
- }
- Store_field(array, r, tmp);
- }
-
- for (r = 0; r < 4; r++)
- out_config[r] = (c_config[r]) ? String_val(Field(Field(array, r), 0)) : NULL;
-
- r = xc_cpuid_check(_H(xch), c_input, (const char **)c_config, out_config);
- if (r < 0)
- failwith_xc(_H(xch));
-
- ret = caml_alloc_tuple(2);
- Store_field(ret, 0, Val_bool(r));
- Store_field(ret, 1, array);
-
-#else
- caml_failwith("xc_domain_cpuid_check: not implemented");
-#endif
- CAMLreturn(ret);
-}
-
CAMLprim value stub_xc_version_version(value xch)
{
CAMLparam1(xch);
return dict;
}
-static PyObject *pyxc_dom_check_cpuid(XcObject *self,
- PyObject *args)
-{
- PyObject *sub_input, *config;
- unsigned int input[2];
- char *regs[4], *regs_transform[4];
-
- if ( !PyArg_ParseTuple(args, "iOO", &input[0], &sub_input, &config) )
- return NULL;
-
- pyxc_dom_extract_cpuid(config, regs);
-
- input[1] = XEN_CPUID_INPUT_UNUSED;
- if ( PyLong_Check(sub_input) )
- input[1] = PyLong_AsUnsignedLong(sub_input);
-
- if ( xc_cpuid_check(self->xc_handle, input,
- (const char **)regs, regs_transform) )
- return pyxc_error_to_exception(self->xc_handle);
-
- return pyxc_create_cpuid_dict(regs_transform);
-}
-
static PyObject *pyxc_dom_set_policy_cpuid(XcObject *self,
PyObject *args)
{
" keys [str]: String of keys to inject.\n" },
#if defined(__i386__) || defined(__x86_64__)
- { "domain_check_cpuid",
- (PyCFunction)pyxc_dom_check_cpuid,
- METH_VARARGS, "\n"
- "Apply checks to host CPUID.\n"
- " input [long]: Input for cpuid instruction (eax)\n"
- " sub_input [long]: Second input (optional, may be None) for cpuid "
- " instruction (ecx)\n"
- " config [dict]: Dictionary of register\n"
- " config [dict]: Dictionary of register, use for checking\n\n"
- "Returns: [int] 0 on success; exception on error.\n" },
-
{ "domain_set_cpuid",
(PyCFunction)pyxc_dom_set_cpuid,
METH_VARARGS, "\n"