static int xenfb_map_fb(struct XenFB *xenfb)

{

    struct xenfb_page *page = xenfb->c.page;

    char *protocol = xenfb->c.xendev.protocol;

    int n_fbdirs;

    xen_pfn_t *pgmfns = NULL;

    xen_pfn_t *fbmfns = NULL;

    void *map, *pd;

    int mode, ret = -1;



    /* default to native */

    pd = page->pd;

    mode = sizeof(unsigned long) * 8;



    if (!protocol) {

	/*

	 * Undefined protocol, some guesswork needed.

	 *

	 * Old frontends which don't set the protocol use

	 * one page directory only, thus pd[1] must be zero.

	 * pd[1] of the 32bit struct layout and the lower

	 * 32 bits of pd[0] of the 64bit struct layout have

	 * the same location, so we can check that ...

	 */

	uint32_t *ptr32 = NULL;

	uint32_t *ptr64 = NULL;

#if defined(__i386__)

	ptr32 = (void*)page->pd;

	ptr64 = ((void*)page->pd) + 4;

#elif defined(__x86_64__)

	ptr32 = ((void*)page->pd) - 4;

	ptr64 = (void*)page->pd;

#endif

	if (ptr32) {

	    if (ptr32[1] == 0) {

		mode = 32;

		pd   = ptr32;

	    } else {

		mode = 64;

		pd   = ptr64;

	    }

	}

#if defined(__x86_64__)

    } else if (strcmp(protocol, XEN_IO_PROTO_ABI_X86_32) == 0) {

	/* 64bit dom0, 32bit domU */

	mode = 32;

	pd   = ((void*)page->pd) - 4;

#elif defined(__i386__)

    } else if (strcmp(protocol, XEN_IO_PROTO_ABI_X86_64) == 0) {

	/* 32bit dom0, 64bit domU */

	mode = 64;

	pd   = ((void*)page->pd) + 4;

#endif

    }



    if (xenfb->pixels) {

        munmap(xenfb->pixels, xenfb->fbpages * XC_PAGE_SIZE);

        xenfb->pixels = NULL;

    }



    xenfb->fbpages = (xenfb->fb_len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;

    n_fbdirs = xenfb->fbpages * mode / 8;

    n_fbdirs = (n_fbdirs + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;



    pgmfns = g_malloc0(sizeof(xen_pfn_t) * n_fbdirs);

    fbmfns = g_malloc0(sizeof(xen_pfn_t) * xenfb->fbpages);



    xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);

    map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,

			       PROT_READ, pgmfns, n_fbdirs);

    if (map == NULL)

	goto out;

    xenfb_copy_mfns(mode, xenfb->fbpages, fbmfns, map);

    munmap(map, n_fbdirs * XC_PAGE_SIZE);



    xenfb->pixels = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,

            PROT_READ, fbmfns, xenfb->fbpages);

    if (xenfb->pixels == NULL)

	goto out;



    ret = 0; /* all is fine */



out:

    g_free(pgmfns);

    g_free(fbmfns);

    return ret;

}

static int xenfb_map_fb(struct XenFB *xenfb)

{

    struct xenfb_page *page = xenfb->c.page;

    char *protocol = xenfb->c.xendev.protocol;

    int n_fbdirs;

    xen_pfn_t *pgmfns = NULL;

    xen_pfn_t *fbmfns = NULL;

    void *map, *pd;

    int mode, ret = -1;



    

    pd = page->pd;

    mode = sizeof(unsigned long) * 8;



    if (!protocol) {

	

















	uint32_t *ptr32 = NULL;

	uint32_t *ptr64 = NULL;

#if defined(__i386__)

	ptr32 = (void*)page->pd;

	ptr64 = ((void*)page->pd) + 4;

#elif defined(__x86_64__)

	ptr32 = ((void*)page->pd) - 4;

	ptr64 = (void*)page->pd;

#endif

	if (ptr32) {

	    if (ptr32[1] == 0) {

		mode = 32;

		pd   = ptr32;

	    } else {

		mode = 64;

		pd   = ptr64;

	    }

	}

#if defined(__x86_64__)

    } else if (strcmp(protocol, XEN_IO_PROTO_ABI_X86_32) == 0) {

	

	mode = 32;

	pd   = ((void*)page->pd) - 4;

#elif defined(__i386__)

    } else if (strcmp(protocol, XEN_IO_PROTO_ABI_X86_64) == 0) {

	

	mode = 64;

	pd   = ((void*)page->pd) + 4;

#endif

    }



    if (xenfb->pixels) {

        munmap(xenfb->pixels, xenfb->fbpages * XC_PAGE_SIZE);

        xenfb->pixels = NULL;

    }



    xenfb->fbpages = (xenfb->fb_len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;

    n_fbdirs = xenfb->fbpages * mode / 8;

    n_fbdirs = (n_fbdirs + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;



    pgmfns = g_malloc0(sizeof(xen_pfn_t) * n_fbdirs);

    fbmfns = g_malloc0(sizeof(xen_pfn_t) * xenfb->fbpages);



    xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);

    map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,

			       PROT_READ, pgmfns, n_fbdirs);

    if (map == NULL)

	goto out;

    xenfb_copy_mfns(mode, xenfb->fbpages, fbmfns, map);

    munmap(map, n_fbdirs * XC_PAGE_SIZE);



    xenfb->pixels = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,

            PROT_READ, fbmfns, xenfb->fbpages);

    if (xenfb->pixels == NULL)

	goto out;



    ret = 0; 



out:

    g_free(pgmfns);

    g_free(fbmfns);

    return ret;

}

    map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom, 			       PROT_READ, pgmfns, n_fbdirs);     munmap(map, n_fbdirs * XC_PAGE_SIZE);     xenfb->pixels = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,             PROT_READ, fbmfns, xenfb->fbpages);
static int FUNC_0(struct XenFB *VAR_0)

{

    struct xenfb_page *VAR_1 = VAR_0->c.VAR_1;

    char *VAR_2 = VAR_0->c.xendev.VAR_2;

    int VAR_3;

    xen_pfn_t *pgmfns = NULL;

    xen_pfn_t *fbmfns = NULL;

    void *VAR_4, *VAR_5;

    int VAR_6, VAR_7 = -1;



    

    VAR_5 = VAR_1->VAR_5;

    VAR_6 = sizeof(unsigned long) * 8;



    if (!VAR_2) {

	

















	uint32_t *ptr32 = NULL;

	uint32_t *ptr64 = NULL;

#if defined(__i386__)

	ptr32 = (void*)VAR_1->VAR_5;

	ptr64 = ((void*)VAR_1->VAR_5) + 4;

#elif defined(__x86_64__)

	ptr32 = ((void*)VAR_1->VAR_5) - 4;

	ptr64 = (void*)VAR_1->VAR_5;

#endif

	if (ptr32) {

	    if (ptr32[1] == 0) {

		VAR_6 = 32;

		VAR_5   = ptr32;

	    } else {

		VAR_6 = 64;

		VAR_5   = ptr64;

	    }

	}

#if defined(__x86_64__)

    } else if (strcmp(VAR_2, XEN_IO_PROTO_ABI_X86_32) == 0) {

	

	VAR_6 = 32;

	VAR_5   = ((void*)VAR_1->VAR_5) - 4;

#elif defined(__i386__)

    } else if (strcmp(VAR_2, XEN_IO_PROTO_ABI_X86_64) == 0) {

	

	VAR_6 = 64;

	VAR_5   = ((void*)VAR_1->VAR_5) + 4;

#endif

    }



    if (VAR_0->pixels) {

        munmap(VAR_0->pixels, VAR_0->fbpages * XC_PAGE_SIZE);

        VAR_0->pixels = NULL;

    }



    VAR_0->fbpages = (VAR_0->fb_len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;

    VAR_3 = VAR_0->fbpages * VAR_6 / 8;

    VAR_3 = (VAR_3 + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;



    pgmfns = g_malloc0(sizeof(xen_pfn_t) * VAR_3);

    fbmfns = g_malloc0(sizeof(xen_pfn_t) * VAR_0->fbpages);



    xenfb_copy_mfns(VAR_6, VAR_3, pgmfns, VAR_5);

    VAR_4 = xc_map_foreign_pages(xen_xc, VAR_0->c.xendev.dom,

			       PROT_READ, pgmfns, VAR_3);

    if (VAR_4 == NULL)

	goto out;

    xenfb_copy_mfns(VAR_6, VAR_0->fbpages, fbmfns, VAR_4);

    munmap(VAR_4, VAR_3 * XC_PAGE_SIZE);



    VAR_0->pixels = xc_map_foreign_pages(xen_xc, VAR_0->c.xendev.dom,

            PROT_READ, fbmfns, VAR_0->fbpages);

    if (VAR_0->pixels == NULL)

	goto out;



    VAR_7 = 0; 



out:

    g_free(pgmfns);

    g_free(fbmfns);

    return VAR_7;

}

static int FUNC_0(struct XenFB *VAR_0)
{ struct xenfb_page *VAR_1 = VAR_0->c.VAR_1; char *VAR_2 = VAR_0->c.xendev.VAR_2; int VAR_3; xen_pfn_t *pgmfns = NULL; xen_pfn_t *fbmfns = NULL; void *VAR_4, *VAR_5; int VAR_6, VAR_7 = -1; VAR_5 = VAR_1->VAR_5; VAR_6 = sizeof(unsigned long) * 8; if (!VAR_2) { uint32_t *ptr32 = NULL; uint32_t *ptr64 = NULL; #if defined(__i386__)
ptr32 = (void*)VAR_1->VAR_5; ptr64 = ((void*)VAR_1->VAR_5) + 4; #elif defined(__x86_64__)
ptr32 = ((void*)VAR_1->VAR_5) - 4; ptr64 = (void*)VAR_1->VAR_5; #endif
if (ptr32) { if (ptr32[1] == 0) { VAR_6 = 32; VAR_5   = ptr32; } else { VAR_6 = 64; VAR_5   = ptr64; } } #if defined(__x86_64__)
} else if (strcmp(VAR_2, XEN_IO_PROTO_ABI_X86_32) == 0) { VAR_6 = 32; VAR_5   = ((void*)VAR_1->VAR_5) - 4; #elif defined(__i386__)
} else if (strcmp(VAR_2, XEN_IO_PROTO_ABI_X86_64) == 0) { VAR_6 = 64; VAR_5   = ((void*)VAR_1->VAR_5) + 4; #endif
} if (VAR_0->pixels) { munmap(VAR_0->pixels, VAR_0->fbpages * XC_PAGE_SIZE); VAR_0->pixels = NULL; } VAR_0->fbpages = (VAR_0->fb_len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE; VAR_3 = VAR_0->fbpages * VAR_6 / 8; VAR_3 = (VAR_3 + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE; pgmfns = g_malloc0(sizeof(xen_pfn_t) * VAR_3); fbmfns = g_malloc0(sizeof(xen_pfn_t) * VAR_0->fbpages); xenfb_copy_mfns(VAR_6, VAR_3, pgmfns, VAR_5); VAR_4 = xc_map_foreign_pages(xen_xc, VAR_0->c.xendev.dom,
PROT_READ, pgmfns, VAR_3); if (VAR_4 == NULL)
goto out; xenfb_copy_mfns(VAR_6, VAR_0->fbpages, fbmfns, VAR_4); munmap(VAR_4, VAR_3 * XC_PAGE_SIZE); VAR_0->pixels = xc_map_foreign_pages(xen_xc, VAR_0->c.xendev.dom,
PROT_READ, fbmfns, VAR_0->fbpages); if (VAR_0->pixels == NULL)
goto out; VAR_7 = 0; out:
g_free(pgmfns); g_free(fbmfns); return VAR_7; }