static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg,

                               int flags, int send)

{

    abi_long ret, len;

    struct target_msghdr *msgp;

    struct msghdr msg;

    int count;

    struct iovec *vec;

    abi_ulong target_vec;



    /* FIXME */

    if (!lock_user_struct(send ? VERIFY_READ : VERIFY_WRITE,

                          msgp,

                          target_msg,

                          send ? 1 : 0))

        return -TARGET_EFAULT;

    if (msgp->msg_name) {

        msg.msg_namelen = tswap32(msgp->msg_namelen);

        msg.msg_name = alloca(msg.msg_namelen);

        ret = target_to_host_sockaddr(msg.msg_name, tswapal(msgp->msg_name),

                                msg.msg_namelen);

        if (ret) {

            unlock_user_struct(msgp, target_msg, send ? 0 : 1);

            return ret;

        }

    } else {

        msg.msg_name = NULL;

        msg.msg_namelen = 0;

    }

    msg.msg_controllen = 2 * tswapal(msgp->msg_controllen);

    msg.msg_control = alloca(msg.msg_controllen);

    msg.msg_flags = tswap32(msgp->msg_flags);



    count = tswapal(msgp->msg_iovlen);

    vec = alloca(count * sizeof(struct iovec));

    target_vec = tswapal(msgp->msg_iov);

    lock_iovec(send ? VERIFY_READ : VERIFY_WRITE, vec, target_vec, count, send);

    msg.msg_iovlen = count;

    msg.msg_iov = vec;



    if (send) {

        ret = target_to_host_cmsg(&msg, msgp);

        if (ret == 0)

            ret = get_errno(sendmsg(fd, &msg, flags));

    } else {

        ret = get_errno(recvmsg(fd, &msg, flags));

        if (!is_error(ret)) {

            len = ret;

            ret = host_to_target_cmsg(msgp, &msg);

            if (!is_error(ret)) {

                msgp->msg_namelen = tswap32(msg.msg_namelen);

                if (msg.msg_name != NULL) {

                    ret = host_to_target_sockaddr(tswapal(msgp->msg_name),

                                    msg.msg_name, msg.msg_namelen);

                    if (ret) {

                        goto out;

                    }

                }



                ret = len;

            }

        }

    }



out:

    unlock_iovec(vec, target_vec, count, !send);

    unlock_user_struct(msgp, target_msg, send ? 0 : 1);

    return ret;

}

static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg,

                               int flags, int send)

{

    abi_long ret, len;

    struct target_msghdr *msgp;

    struct msghdr msg;

    int count;

    struct iovec *vec;

    abi_ulong target_vec;



    

    if (!lock_user_struct(send ? VERIFY_READ : VERIFY_WRITE,

                          msgp,

                          target_msg,

                          send ? 1 : 0))

        return -TARGET_EFAULT;

    if (msgp->msg_name) {

        msg.msg_namelen = tswap32(msgp->msg_namelen);

        msg.msg_name = alloca(msg.msg_namelen);

        ret = target_to_host_sockaddr(msg.msg_name, tswapal(msgp->msg_name),

                                msg.msg_namelen);

        if (ret) {

            unlock_user_struct(msgp, target_msg, send ? 0 : 1);

            return ret;

        }

    } else {

        msg.msg_name = NULL;

        msg.msg_namelen = 0;

    }

    msg.msg_controllen = 2 * tswapal(msgp->msg_controllen);

    msg.msg_control = alloca(msg.msg_controllen);

    msg.msg_flags = tswap32(msgp->msg_flags);



    count = tswapal(msgp->msg_iovlen);

    vec = alloca(count * sizeof(struct iovec));

    target_vec = tswapal(msgp->msg_iov);

    lock_iovec(send ? VERIFY_READ : VERIFY_WRITE, vec, target_vec, count, send);

    msg.msg_iovlen = count;

    msg.msg_iov = vec;



    if (send) {

        ret = target_to_host_cmsg(&msg, msgp);

        if (ret == 0)

            ret = get_errno(sendmsg(fd, &msg, flags));

    } else {

        ret = get_errno(recvmsg(fd, &msg, flags));

        if (!is_error(ret)) {

            len = ret;

            ret = host_to_target_cmsg(msgp, &msg);

            if (!is_error(ret)) {

                msgp->msg_namelen = tswap32(msg.msg_namelen);

                if (msg.msg_name != NULL) {

                    ret = host_to_target_sockaddr(tswapal(msgp->msg_name),

                                    msg.msg_name, msg.msg_namelen);

                    if (ret) {

                        goto out;

                    }

                }



                ret = len;

            }

        }

    }



out:

    unlock_iovec(vec, target_vec, count, !send);

    unlock_user_struct(msgp, target_msg, send ? 0 : 1);

    return ret;

}

static abi_long FUNC_0(int fd, abi_ulong target_msg,

                               int flags, int send)

{

    abi_long ret, len;

    struct target_msghdr *VAR_0;

    struct msghdr VAR_1;

    int VAR_2;

    struct iovec *VAR_3;

    abi_ulong target_vec;



    

    if (!lock_user_struct(send ? VERIFY_READ : VERIFY_WRITE,

                          VAR_0,

                          target_msg,

                          send ? 1 : 0))

        return -TARGET_EFAULT;

    if (VAR_0->msg_name) {

        VAR_1.msg_namelen = tswap32(VAR_0->msg_namelen);

        VAR_1.msg_name = alloca(VAR_1.msg_namelen);

        ret = target_to_host_sockaddr(VAR_1.msg_name, tswapal(VAR_0->msg_name),

                                VAR_1.msg_namelen);

        if (ret) {

            unlock_user_struct(VAR_0, target_msg, send ? 0 : 1);

            return ret;

        }

    } else {

        VAR_1.msg_name = NULL;

        VAR_1.msg_namelen = 0;

    }

    VAR_1.msg_controllen = 2 * tswapal(VAR_0->msg_controllen);

    VAR_1.msg_control = alloca(VAR_1.msg_controllen);

    VAR_1.msg_flags = tswap32(VAR_0->msg_flags);



    VAR_2 = tswapal(VAR_0->msg_iovlen);

    VAR_3 = alloca(VAR_2 * sizeof(struct iovec));

    target_vec = tswapal(VAR_0->msg_iov);

    lock_iovec(send ? VERIFY_READ : VERIFY_WRITE, VAR_3, target_vec, VAR_2, send);

    VAR_1.msg_iovlen = VAR_2;

    VAR_1.msg_iov = VAR_3;



    if (send) {

        ret = target_to_host_cmsg(&VAR_1, VAR_0);

        if (ret == 0)

            ret = get_errno(sendmsg(fd, &VAR_1, flags));

    } else {

        ret = get_errno(recvmsg(fd, &VAR_1, flags));

        if (!is_error(ret)) {

            len = ret;

            ret = host_to_target_cmsg(VAR_0, &VAR_1);

            if (!is_error(ret)) {

                VAR_0->msg_namelen = tswap32(VAR_1.msg_namelen);

                if (VAR_1.msg_name != NULL) {

                    ret = host_to_target_sockaddr(tswapal(VAR_0->msg_name),

                                    VAR_1.msg_name, VAR_1.msg_namelen);

                    if (ret) {

                        goto out;

                    }

                }



                ret = len;

            }

        }

    }



out:

    unlock_iovec(VAR_3, target_vec, VAR_2, !send);

    unlock_user_struct(VAR_0, target_msg, send ? 0 : 1);

    return ret;

}

static abi_long FUNC_0(int fd, abi_ulong target_msg,
int flags, int send)
{ abi_long ret, len; struct target_msghdr *VAR_0; struct msghdr VAR_1; int VAR_2; struct iovec *VAR_3; abi_ulong target_vec; if (!lock_user_struct(send ? VERIFY_READ : VERIFY_WRITE,
VAR_0,
target_msg,
send ? 1 : 0))
return -TARGET_EFAULT; if (VAR_0->msg_name) { VAR_1.msg_namelen = tswap32(VAR_0->msg_namelen); VAR_1.msg_name = alloca(VAR_1.msg_namelen); ret = target_to_host_sockaddr(VAR_1.msg_name, tswapal(VAR_0->msg_name),
VAR_1.msg_namelen); if (ret) { unlock_user_struct(VAR_0, target_msg, send ? 0 : 1); return ret; } } else { VAR_1.msg_name = NULL; VAR_1.msg_namelen = 0; } VAR_1.msg_controllen = 2 * tswapal(VAR_0->msg_controllen); VAR_1.msg_control = alloca(VAR_1.msg_controllen); VAR_1.msg_flags = tswap32(VAR_0->msg_flags); VAR_2 = tswapal(VAR_0->msg_iovlen); VAR_3 = alloca(VAR_2 * sizeof(struct iovec)); target_vec = tswapal(VAR_0->msg_iov); lock_iovec(send ? VERIFY_READ : VERIFY_WRITE, VAR_3, target_vec, VAR_2, send); VAR_1.msg_iovlen = VAR_2; VAR_1.msg_iov = VAR_3; if (send) { ret = target_to_host_cmsg(&VAR_1, VAR_0); if (ret == 0)
ret = get_errno(sendmsg(fd, &VAR_1, flags)); } else { ret = get_errno(recvmsg(fd, &VAR_1, flags)); if (!is_error(ret)) { len = ret; ret = host_to_target_cmsg(VAR_0, &VAR_1); if (!is_error(ret)) { VAR_0->msg_namelen = tswap32(VAR_1.msg_namelen); if (VAR_1.msg_name != NULL) { ret = host_to_target_sockaddr(tswapal(VAR_0->msg_name),
VAR_1.msg_name, VAR_1.msg_namelen); if (ret) { goto out; } } ret = len; } } } out:
unlock_iovec(VAR_3, target_vec, VAR_2, !send); unlock_user_struct(VAR_0, target_msg, send ? 0 : 1); return ret; }