⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xc.c

📁 xen虚拟机源代码安装包
💻 C
📖 第 1 页 / 共 5 页
字号:
    unsigned long store_mfn = 0;    unsigned long console_mfn = 0;    PyObject* elfnote_dict;    PyObject* elfnote = NULL;    PyObject* ret;    int i;    static char *kwd_list[] = { "domid", "store_evtchn", "memsize",                                "console_evtchn", "image",                                /* optional */                                "ramdisk", "cmdline", "flags",                                "features", "vhpt", NULL };    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssisi", kwd_list,                                      &domid, &store_evtchn, &mem_mb,                                      &console_evtchn, &image,                                      /* optional */                                      &ramdisk, &cmdline, &flags,                                      &features, &vhpt) )        return NULL;    xc_dom_loginit();    if (!(dom = xc_dom_allocate(cmdline, features)))        return pyxc_error_to_exception();    /* for IA64 */    dom->vhpt_size_log2 = vhpt;    if ( xc_dom_linux_build(self->xc_handle, dom, domid, mem_mb, image,                            ramdisk, flags, store_evtchn, &store_mfn,                            console_evtchn, &console_mfn) != 0 ) {        goto out;    }    if ( !(elfnote_dict = PyDict_New()) )        goto out;        for ( i = 0; i < ARRAY_SIZE(dom->parms.elf_notes); i++ )    {        switch ( dom->parms.elf_notes[i].type )        {        case XEN_ENT_NONE:            continue;        case XEN_ENT_LONG:            elfnote = Py_BuildValue("k", dom->parms.elf_notes[i].data.num);            break;        case XEN_ENT_STR:            elfnote = Py_BuildValue("s", dom->parms.elf_notes[i].data.str);            break;        }        PyDict_SetItemString(elfnote_dict,                             dom->parms.elf_notes[i].name,                             elfnote);        Py_DECREF(elfnote);    }    ret = Py_BuildValue("{s:i,s:i,s:N}",                        "store_mfn", store_mfn,                        "console_mfn", console_mfn,                        "notes", elfnote_dict);    if ( dom->arch_hooks->native_protocol )    {        PyObject *native_protocol =            Py_BuildValue("s", dom->arch_hooks->native_protocol);        PyDict_SetItemString(ret, "native_protocol", native_protocol);        Py_DECREF(native_protocol);    }    xc_dom_release(dom);    return ret;  out:    xc_dom_release(dom);    return pyxc_error_to_exception();}static PyObject *pyxc_get_hvm_param(XcObject *self,                                    PyObject *args,                                    PyObject *kwds){    uint32_t dom;    int param;    unsigned long value;    static char *kwd_list[] = { "domid", "param", NULL };     if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list,                                      &dom, &param) )        return NULL;    if ( xc_get_hvm_param(self->xc_handle, dom, param, &value) != 0 )        return pyxc_error_to_exception();    return PyLong_FromUnsignedLong(value);}static PyObject *pyxc_set_hvm_param(XcObject *self,                                    PyObject *args,                                    PyObject *kwds){    uint32_t dom;    int param;    uint64_t value;    static char *kwd_list[] = { "domid", "param", "value", NULL };     if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiL", kwd_list,                                      &dom, &param, &value) )        return NULL;    if ( xc_set_hvm_param(self->xc_handle, dom, param, value) != 0 )        return pyxc_error_to_exception();    Py_INCREF(zero);    return zero;}static int token_value(char *token){    token = strchr(token, 'x') + 1;    return strtol(token, NULL, 16);}static int next_bdf(char **str, int *seg, int *bus, int *dev, int *func){    char *token;    if ( !(*str) || !strchr(*str, ',') )        return 0;    token = *str;    *seg  = token_value(token);    token = strchr(token, ',') + 1;    *bus  = token_value(token);    token = strchr(token, ',') + 1;    *dev  = token_value(token);    token = strchr(token, ',') + 1;    *func  = token_value(token);    token = strchr(token, ',');    *str = token ? token + 1 : NULL;    return 1;}static PyObject *pyxc_test_assign_device(XcObject *self,                                         PyObject *args,                                         PyObject *kwds){    uint32_t dom;    char *pci_str;    int32_t bdf = 0;    int seg, bus, dev, func;    static char *kwd_list[] = { "domid", "pci", NULL };    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is", kwd_list,                                      &dom, &pci_str) )        return NULL;    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func) )    {        bdf |= (bus & 0xff) << 16;        bdf |= (dev & 0x1f) << 11;        bdf |= (func & 0x7) << 8;        if ( xc_test_assign_device(self->xc_handle, dom, bdf) != 0 )        {            if (errno == ENOSYS)                bdf = -1;            break;        }        bdf = 0;    }    return Py_BuildValue("i", bdf);}static PyObject *pyxc_assign_device(XcObject *self,                                    PyObject *args,                                    PyObject *kwds){    uint32_t dom;    char *pci_str;    int32_t bdf = 0;    int seg, bus, dev, func;    static char *kwd_list[] = { "domid", "pci", NULL };    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is", kwd_list,                                      &dom, &pci_str) )        return NULL;    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func) )    {        bdf |= (bus & 0xff) << 16;        bdf |= (dev & 0x1f) << 11;        bdf |= (func & 0x7) << 8;        if ( xc_assign_device(self->xc_handle, dom, bdf) != 0 )        {            if (errno == ENOSYS)                bdf = -1;            break;        }        bdf = 0;    }    return Py_BuildValue("i", bdf);}static PyObject *pyxc_deassign_device(XcObject *self,                                      PyObject *args,                                      PyObject *kwds){    uint32_t dom;    char *pci_str;    int32_t bdf = 0;    int seg, bus, dev, func;    static char *kwd_list[] = { "domid", "pci", NULL };    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is", kwd_list,                                      &dom, &pci_str) )        return NULL;    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func) )    {        bdf |= (bus & 0xff) << 16;        bdf |= (dev & 0x1f) << 11;        bdf |= (func & 0x7) << 8;        if ( xc_deassign_device(self->xc_handle, dom, bdf) != 0 )        {            if (errno == ENOSYS)                bdf = -1;            break;        }        bdf = 0;    }    return Py_BuildValue("i", bdf);}static PyObject *pyxc_get_device_group(XcObject *self,                                         PyObject *args){    domid_t domid;    uint32_t bdf = 0;    uint32_t max_sdevs, num_sdevs;    int seg, bus, dev, func, rc, i;    PyObject *Pystr;    char *group_str;    char dev_str[9];    uint32_t *sdev_array;    if ( !PyArg_ParseTuple(args, "iiiii", &domid, &seg, &bus, &dev, &func) )        return NULL;    /* Maximum allowed siblings device number per group */    max_sdevs = 1024;    sdev_array = calloc(max_sdevs, sizeof(*sdev_array));    if (sdev_array == NULL)        return PyErr_NoMemory();    bdf |= (bus & 0xff) << 16;    bdf |= (dev & 0x1f) << 11;    bdf |= (func & 0x7) << 8;    rc = xc_get_device_group(self->xc_handle,        domid, bdf, max_sdevs, &num_sdevs, sdev_array);    if ( rc < 0 )    {      free(sdev_array);       return pyxc_error_to_exception();    }    if ( !num_sdevs )    {       free(sdev_array);       return Py_BuildValue("s", "");    }    group_str = calloc(num_sdevs, sizeof(dev_str));    if (group_str == NULL)        return PyErr_NoMemory();    for ( i = 0; i < num_sdevs; i++ )    {        bus = (sdev_array[i] >> 16) & 0xff;        dev = (sdev_array[i] >> 11) & 0x1f;        func = (sdev_array[i] >> 8) & 0x7;        snprintf(dev_str, sizeof(dev_str), "%02x:%02x.%x,", bus, dev, func);        strcat(group_str, dev_str);    }    Pystr = Py_BuildValue("s", group_str);    free(sdev_array);    free(group_str);    return Pystr;}#ifdef __ia64__static PyObject *pyxc_nvram_init(XcObject *self,                                 PyObject *args){    char *dom_name;    uint32_t dom;    if ( !PyArg_ParseTuple(args, "si", &dom_name, &dom) )        return NULL;    xc_ia64_nvram_init(self->xc_handle, dom_name, dom);    Py_INCREF(zero);    return zero;}static PyObject *pyxc_set_os_type(XcObject *self,                                  PyObject *args){    char *os_type;    uint32_t dom;    if ( !PyArg_ParseTuple(args, "si", &os_type, &dom) )        return NULL;    xc_ia64_set_os_type(self->xc_handle, os_type, dom);    Py_INCREF(zero);    return zero;}#endif /* __ia64__ */#if defined(__i386__) || defined(__x86_64__)static void pyxc_dom_extract_cpuid(PyObject *config,                                  char **regs){    const char *regs_extract[4] = { "eax", "ebx", "ecx", "edx" };    PyObject *obj;    int i;    memset(regs, 0, 4*sizeof(*regs));    if ( !PyDict_Check(config) )        return;    for ( i = 0; i < 4; i++ )        if ( (obj = PyDict_GetItemString(config, regs_extract[i])) != NULL )            regs[i] = PyString_AS_STRING(obj);}static PyObject *pyxc_create_cpuid_dict(char **regs){   const char *regs_extract[4] = { "eax", "ebx", "ecx", "edx" };   PyObject *dict;   int i;   dict = PyDict_New();   for ( i = 0; i < 4; i++ )   {       if ( regs[i] == NULL )           continue;       PyDict_SetItemString(dict, regs_extract[i],                            PyString_FromString(regs[i]));       free(regs[i]);       regs[i] = NULL;   }   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();    return pyxc_create_cpuid_dict(regs_transform);}static PyObject *pyxc_dom_set_policy_cpuid(XcObject *self,                                           PyObject *args){    domid_t domid;    if ( !PyArg_ParseTuple(args, "i", &domid) )        return NULL;    if ( xc_cpuid_apply_policy(self->xc_handle, domid) )        return pyxc_error_to_exception();    Py_INCREF(zero);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -