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

📄 xc.c

📁 xen 3.2.2 源码
💻 C
📖 第 1 页 / 共 4 页
字号:
                                      &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;    uint32_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 )            break;        bdf = 0;    }    return Py_BuildValue("i", bdf);}#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__ */static PyObject *pyxc_hvm_build(XcObject *self,                                PyObject *args,                                PyObject *kwds){    uint32_t dom;#if !defined(__ia64__)    struct hvm_info_table *va_hvm;    uint8_t *va_map, sum;    int i;#endif    char *image;    int memsize, vcpus = 1, acpi = 0, apic = 1;    static char *kwd_list[] = { "domid",				"memsize", "image", "vcpus", "acpi",				"apic", NULL };    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iis|iii", kwd_list,                                      &dom, &memsize,                                      &image, &vcpus, &acpi, &apic) )        return NULL;    if ( xc_hvm_build(self->xc_handle, dom, memsize, image) != 0 )        return pyxc_error_to_exception();#if !defined(__ia64__)    /* Set up the HVM info table. */    va_map = xc_map_foreign_range(self->xc_handle, dom, XC_PAGE_SIZE,                                  PROT_READ | PROT_WRITE,                                  HVM_INFO_PFN);    if ( va_map == NULL )        return PyErr_SetFromErrno(xc_error_obj);    va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);    memset(va_hvm, 0, sizeof(*va_hvm));    strncpy(va_hvm->signature, "HVM INFO", 8);    va_hvm->length       = sizeof(struct hvm_info_table);    va_hvm->acpi_enabled = acpi;    va_hvm->apic_mode    = apic;    va_hvm->nr_vcpus     = vcpus;    for ( i = 0, sum = 0; i < va_hvm->length; i++ )        sum += ((uint8_t *)va_hvm)[i];    va_hvm->checksum = -sum;    munmap(va_map, XC_PAGE_SIZE);#endif    return Py_BuildValue("{}");}static PyObject *pyxc_evtchn_alloc_unbound(XcObject *self,                                           PyObject *args,                                           PyObject *kwds){    uint32_t dom, remote_dom;    int port;    static char *kwd_list[] = { "domid", "remote_dom", NULL };    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list,                                      &dom, &remote_dom) )        return NULL;    if ( (port = xc_evtchn_alloc_unbound(self->xc_handle, dom, remote_dom)) < 0 )        return pyxc_error_to_exception();    return PyInt_FromLong(port);}static PyObject *pyxc_evtchn_reset(XcObject *self,				   PyObject *args,				   PyObject *kwds){    uint32_t dom;    static char *kwd_list[] = { "dom", NULL };    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &dom) )        return NULL;    if ( xc_evtchn_reset(self->xc_handle, dom) < 0 )        return pyxc_error_to_exception();    Py_INCREF(zero);    return zero;}static PyObject *pyxc_physdev_pci_access_modify(XcObject *self,                                                PyObject *args,                                                PyObject *kwds){    uint32_t dom;    int bus, dev, func, enable, ret;    static char *kwd_list[] = { "domid", "bus", "dev", "func", "enable", NULL };    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiii", kwd_list,                                       &dom, &bus, &dev, &func, &enable) )        return NULL;    ret = xc_physdev_pci_access_modify(        self->xc_handle, dom, bus, dev, func, enable);    if ( ret != 0 )        return pyxc_error_to_exception();    Py_INCREF(zero);    return zero;}static PyObject *pyxc_readconsolering(XcObject *self,                                      PyObject *args,                                      PyObject *kwds){    unsigned int clear = 0, index = 0, incremental = 0;    char         _str[32768], *str = _str;    unsigned int count = 32768;    int          ret;    static char *kwd_list[] = { "clear", "index", "incremental", NULL };    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iii", kwd_list,                                      &clear, &index, &incremental) )        return NULL;    ret = xc_readconsolering(self->xc_handle, &str, &count, clear,                             incremental, &index);    if ( ret < 0 )        return pyxc_error_to_exception();    return PyString_FromStringAndSize(str, count);}static unsigned long pages_to_kib(unsigned long pages){    return pages * (XC_PAGE_SIZE / 1024);}static PyObject *pyxc_pages_to_kib(XcObject *self, PyObject *args){    unsigned long pages;    if (!PyArg_ParseTuple(args, "l", &pages))        return NULL;    return PyLong_FromUnsignedLong(pages_to_kib(pages));}static PyObject *pyxc_physinfo(XcObject *self){#define MAX_CPU_ID 255    xc_physinfo_t info;    char cpu_cap[128], *p=cpu_cap, *q=cpu_cap;    int i, j, max_cpu_id;    PyObject *ret_obj, *node_to_cpu_obj;    xc_cpu_to_node_t map[MAX_CPU_ID + 1];    set_xen_guest_handle(info.cpu_to_node, map);    info.max_cpu_id = MAX_CPU_ID;    if ( xc_physinfo(self->xc_handle, &info) != 0 )        return pyxc_error_to_exception();    *q = 0;    for ( i = 0; i < sizeof(info.hw_cap)/4; i++ )    {        p += sprintf(p, "%08x:", info.hw_cap[i]);        if ( info.hw_cap[i] )            q = p;    }    if ( q > cpu_cap )        *(q-1) = 0;    ret_obj = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:l,s:l,s:l,s:i,s:s}",                            "nr_nodes",         info.nr_nodes,                            "max_cpu_id",       info.max_cpu_id,                            "threads_per_core", info.threads_per_core,                            "cores_per_socket", info.cores_per_socket,                            "nr_cpus",          info.nr_cpus,                             "total_memory",     pages_to_kib(info.total_pages),                            "free_memory",      pages_to_kib(info.free_pages),                            "scrub_memory",     pages_to_kib(info.scrub_pages),                            "cpu_khz",          info.cpu_khz,                            "hw_caps",          cpu_cap);    max_cpu_id = info.max_cpu_id;    if ( max_cpu_id > MAX_CPU_ID )        max_cpu_id = MAX_CPU_ID;    /* Construct node-to-cpu lists. */    node_to_cpu_obj = PyList_New(0);    /* Make a list for each node. */    for ( i = 0; i < info.nr_nodes; i++ )    {        PyObject *cpus = PyList_New(0);        for ( j = 0; j <= max_cpu_id; j++ )            if ( i == map[j])                PyList_Append(cpus, PyInt_FromLong(j));        PyList_Append(node_to_cpu_obj, cpus);     }    PyDict_SetItemString(ret_obj, "node_to_cpu", node_to_cpu_obj);     return ret_obj;#undef MAX_CPU_ID}static PyObject *pyxc_xeninfo(XcObject *self){    xen_extraversion_t xen_extra;    xen_compile_info_t xen_cc;    xen_changeset_info_t xen_chgset;    xen_capabilities_info_t xen_caps;    xen_platform_parameters_t p_parms;    long xen_version;    long xen_pagesize;    char str[128];    xen_version = xc_version(self->xc_handle, XENVER_version, NULL);    if ( xc_version(self->xc_handle, XENVER_extraversion, &xen_extra) != 0 )        return pyxc_error_to_exception();    if ( xc_version(self->xc_handle, XENVER_compile_info, &xen_cc) != 0 )        return pyxc_error_to_exception();    if ( xc_version(self->xc_handle, XENVER_changeset, &xen_chgset) != 0 )        return pyxc_error_to_exception();    if ( xc_version(self->xc_handle, XENVER_capabilities, &xen_caps) != 0 )        return pyxc_error_to_exception();    if ( xc_version(self->xc_handle, XENVER_platform_parameters, &p_parms) != 0 )        return pyxc_error_to_exception();    sprintf(str, "virt_start=0x%lx", p_parms.virt_start);    xen_pagesize = xc_version(self->xc_handle, XENVER_pagesize, NULL);    if (xen_pagesize < 0 )        return pyxc_error_to_exception();    return Py_BuildValue("{s:i,s:i,s:s,s:s,s:i,s:s,s:s,s:s,s:s,s:s,s:s}",                         "xen_major", xen_version >> 16,                         "xen_minor", (xen_version & 0xffff),                         "xen_extra", xen_extra,                         "xen_caps",  xen_caps,                         "xen_pagesize", xen_pagesize,                         "platform_params", str,                         "xen_changeset", xen_chgset,                         "cc_compiler", xen_cc.compiler,                         "cc_compile_by", xen_cc.compile_by,                         "cc_compile_domain", xen_cc.compile_domain,                         "cc_compile_date", xen_cc.compile_date);}

⌨️ 快捷键说明

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