static inline abi_long target_to_host_cmsg(struct msghdr *msgh,

                                           struct target_msghdr *target_msgh)

{

    struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);

    abi_long msg_controllen;

    abi_ulong target_cmsg_addr;

    struct target_cmsghdr *target_cmsg;

    socklen_t space = 0;

    

    msg_controllen = tswapal(target_msgh->msg_controllen);

    if (msg_controllen < sizeof (struct target_cmsghdr)) 

        goto the_end;

    target_cmsg_addr = tswapal(target_msgh->msg_control);

    target_cmsg = lock_user(VERIFY_READ, target_cmsg_addr, msg_controllen, 1);

    if (!target_cmsg)

        return -TARGET_EFAULT;



    while (cmsg && target_cmsg) {

        void *data = CMSG_DATA(cmsg);

        void *target_data = TARGET_CMSG_DATA(target_cmsg);



        int len = tswapal(target_cmsg->cmsg_len)

                  - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr));



        space += CMSG_SPACE(len);

        if (space > msgh->msg_controllen) {

            space -= CMSG_SPACE(len);

            gemu_log("Host cmsg overflow\n");

            break;

        }



        if (tswap32(target_cmsg->cmsg_level) == TARGET_SOL_SOCKET) {

            cmsg->cmsg_level = SOL_SOCKET;

        } else {

            cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level);

        }

        cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type);

        cmsg->cmsg_len = CMSG_LEN(len);



        if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {

            gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);

            memcpy(data, target_data, len);

        } else {

            int *fd = (int *)data;

            int *target_fd = (int *)target_data;

            int i, numfds = len / sizeof(int);



            for (i = 0; i < numfds; i++)

                fd[i] = tswap32(target_fd[i]);

        }



        cmsg = CMSG_NXTHDR(msgh, cmsg);

        target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg);

    }

    unlock_user(target_cmsg, target_cmsg_addr, 0);

 the_end:

    msgh->msg_controllen = space;

    return 0;

}

static inline abi_long target_to_host_cmsg(struct msghdr *msgh,

                                           struct target_msghdr *target_msgh)

{

    struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);

    abi_long msg_controllen;

    abi_ulong target_cmsg_addr;

    struct target_cmsghdr *target_cmsg;

    socklen_t space = 0;

    

    msg_controllen = tswapal(target_msgh->msg_controllen);

    if (msg_controllen < sizeof (struct target_cmsghdr)) 

        goto the_end;

    target_cmsg_addr = tswapal(target_msgh->msg_control);

    target_cmsg = lock_user(VERIFY_READ, target_cmsg_addr, msg_controllen, 1);

    if (!target_cmsg)

        return -TARGET_EFAULT;



    while (cmsg && target_cmsg) {

        void *data = CMSG_DATA(cmsg);

        void *target_data = TARGET_CMSG_DATA(target_cmsg);



        int len = tswapal(target_cmsg->cmsg_len)

                  - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr));



        space += CMSG_SPACE(len);

        if (space > msgh->msg_controllen) {

            space -= CMSG_SPACE(len);

            gemu_log("Host cmsg overflow\n");

            break;

        }



        if (tswap32(target_cmsg->cmsg_level) == TARGET_SOL_SOCKET) {

            cmsg->cmsg_level = SOL_SOCKET;

        } else {

            cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level);

        }

        cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type);

        cmsg->cmsg_len = CMSG_LEN(len);



        if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {

            gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);

            memcpy(data, target_data, len);

        } else {

            int *fd = (int *)data;

            int *target_fd = (int *)target_data;

            int i, numfds = len / sizeof(int);



            for (i = 0; i < numfds; i++)

                fd[i] = tswap32(target_fd[i]);

        }



        cmsg = CMSG_NXTHDR(msgh, cmsg);

        target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg);

    }

    unlock_user(target_cmsg, target_cmsg_addr, 0);

 the_end:

    msgh->msg_controllen = space;

    return 0;

}

static inline abi_long FUNC_0(struct msghdr *msgh,

                                           struct target_msghdr *target_msgh)

{

    struct cmsghdr *VAR_0 = CMSG_FIRSTHDR(msgh);

    abi_long msg_controllen;

    abi_ulong target_cmsg_addr;

    struct target_cmsghdr *VAR_1;

    socklen_t space = 0;

    

    msg_controllen = tswapal(target_msgh->msg_controllen);

    if (msg_controllen < sizeof (struct target_cmsghdr)) 

        goto the_end;

    target_cmsg_addr = tswapal(target_msgh->msg_control);

    VAR_1 = lock_user(VERIFY_READ, target_cmsg_addr, msg_controllen, 1);

    if (!VAR_1)

        return -TARGET_EFAULT;



    while (VAR_0 && VAR_1) {

        void *VAR_2 = CMSG_DATA(VAR_0);

        void *VAR_3 = TARGET_CMSG_DATA(VAR_1);



        int VAR_4 = tswapal(VAR_1->cmsg_len)

                  - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr));



        space += CMSG_SPACE(VAR_4);

        if (space > msgh->msg_controllen) {

            space -= CMSG_SPACE(VAR_4);

            gemu_log("Host VAR_0 overflow\n");

            break;

        }



        if (tswap32(VAR_1->cmsg_level) == TARGET_SOL_SOCKET) {

            VAR_0->cmsg_level = SOL_SOCKET;

        } else {

            VAR_0->cmsg_level = tswap32(VAR_1->cmsg_level);

        }

        VAR_0->cmsg_type = tswap32(VAR_1->cmsg_type);

        VAR_0->cmsg_len = CMSG_LEN(VAR_4);



        if (VAR_0->cmsg_level != SOL_SOCKET || VAR_0->cmsg_type != SCM_RIGHTS) {

            gemu_log("Unsupported ancillary VAR_2: %d/%d\n", VAR_0->cmsg_level, VAR_0->cmsg_type);

            memcpy(VAR_2, VAR_3, VAR_4);

        } else {

            int *VAR_5 = (int *)VAR_2;

            int *VAR_6 = (int *)VAR_3;

            int VAR_7, VAR_8 = VAR_4 / sizeof(int);



            for (VAR_7 = 0; VAR_7 < VAR_8; VAR_7++)

                VAR_5[VAR_7] = tswap32(VAR_6[VAR_7]);

        }



        VAR_0 = CMSG_NXTHDR(msgh, VAR_0);

        VAR_1 = TARGET_CMSG_NXTHDR(target_msgh, VAR_1);

    }

    unlock_user(VAR_1, target_cmsg_addr, 0);

 the_end:

    msgh->msg_controllen = space;

    return 0;

}

static inline abi_long FUNC_0(struct msghdr *msgh,
struct target_msghdr *target_msgh)
{ struct cmsghdr *VAR_0 = CMSG_FIRSTHDR(msgh); abi_long msg_controllen; abi_ulong target_cmsg_addr; struct target_cmsghdr *VAR_1; socklen_t space = 0; msg_controllen = tswapal(target_msgh->msg_controllen); if (msg_controllen < sizeof (struct target_cmsghdr))
goto the_end; target_cmsg_addr = tswapal(target_msgh->msg_control); VAR_1 = lock_user(VERIFY_READ, target_cmsg_addr, msg_controllen, 1); if (!VAR_1)
return -TARGET_EFAULT; while (VAR_0 && VAR_1) { void *VAR_2 = CMSG_DATA(VAR_0); void *VAR_3 = TARGET_CMSG_DATA(VAR_1); int VAR_4 = tswapal(VAR_1->cmsg_len)
- TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr)); space += CMSG_SPACE(VAR_4); if (space > msgh->msg_controllen) { space -= CMSG_SPACE(VAR_4); gemu_log("Host VAR_0 overflow\n"); break; } if (tswap32(VAR_1->cmsg_level) == TARGET_SOL_SOCKET) { VAR_0->cmsg_level = SOL_SOCKET; } else { VAR_0->cmsg_level = tswap32(VAR_1->cmsg_level); } VAR_0->cmsg_type = tswap32(VAR_1->cmsg_type); VAR_0->cmsg_len = CMSG_LEN(VAR_4); if (VAR_0->cmsg_level != SOL_SOCKET || VAR_0->cmsg_type != SCM_RIGHTS) { gemu_log("Unsupported ancillary VAR_2: %d/%d\n", VAR_0->cmsg_level, VAR_0->cmsg_type); memcpy(VAR_2, VAR_3, VAR_4); } else { int *VAR_5 = (int *)VAR_2; int *VAR_6 = (int *)VAR_3; int VAR_7, VAR_8 = VAR_4 / sizeof(int); for (VAR_7 = 0; VAR_7 < VAR_8; VAR_7++) VAR_5[VAR_7] = tswap32(VAR_6[VAR_7]); } VAR_0 = CMSG_NXTHDR(msgh, VAR_0); VAR_1 = TARGET_CMSG_NXTHDR(target_msgh, VAR_1); } unlock_user(VAR_1, target_cmsg_addr, 0); the_end:
msgh->msg_controllen = space; return 0; }