Exemplo n.º 1
0
static void
pyxa_instance_dealloc(PyObject *self) {
    //printf("About to destroy PyXa instance at %p\n", &(pyxai(self)));
    xa_destroy(&(pyxai(self)));
    if(pyxamem(self)) {
        //printf("About to unmap memory at %p\n", pyxamem(self));
        munmap(pyxamem(self), PAGE_SIZE);
    }
    //printf("About to call PyObject_DEL on self at %p\n", self);
    PyObject_DEL(self);
}
Exemplo n.º 2
0
int main (int argc, char **argv)
{
    xa_instance_t xai;
    char *filename = NULL;
    FILE *f = NULL;
    unsigned char *memory = NULL;
    uint32_t offset = 0;
    uint32_t address = 0;

    /* this is the domain ID that we are looking at */
    uint32_t dom = atoi(argv[1]);

    /* this is the file name to write the memory image to */
    filename = strndup(argv[2], 50);

    /* initialize the xen access library */
    if (xa_init_vm_id_lax(dom, &xai) == XA_FAILURE){
        perror("failed to init XenAccess library");
        goto error_exit;
    }

    /* open the file for writing */
    if ((f = fopen(filename, "w+")) == NULL){
        perror("failed to open file for writing");
        goto error_exit;
    }

    /* assuming that we are looking at xen domain, and not image file */
    while (address < xai.m.xen.size){

        /* access the memory */
        memory = xa_access_pa(&xai, address, &offset, PROT_READ);

        /* write memory to file */
        if (memory){
            /* memory mapped, just write to file */
            size_t written = fwrite(memory, 1, xai.page_size, f);
            if (written != xai.page_size){
                perror("failed to write memory to file");
                goto error_exit;
            }
            munmap(memory, xai.page_size);
        }
        else{
            /* memory not mapped, write zeros to maintain offset */
            unsigned char *zeros = malloc(xai.page_size);
            memset(zeros, 0, xai.page_size);
            size_t written = fwrite(zeros, 1, xai.page_size, f);
            if (written != xai.page_size){
                perror("failed to write zeros to file");
                goto error_exit;
            }
            free(zeros);
        }

        /* move on to the next page */
        address += xai.page_size;
    }

error_exit:
    if (memory){ munmap(memory, xai.page_size); }
    if (f){ fclose(f); }

    /* cleanup any memory associated with the XenAccess instance */
    xa_destroy(&xai);

    return 0;
}
Exemplo n.º 3
0
int cleanup(xa_instance_t *xai){
  xa_destroy(xai);
}