static int _epoll_dup(oe_fd_t* epoll_, oe_fd_t** new_epoll_out)
{
    int ret = -1;
    epoll_t* epoll = _cast_epoll(epoll_);
    epoll_t* new_epoll = NULL;
    oe_host_fd_t retval;

    oe_errno = 0;

    /* Check parameters. */
    if (!new_epoll_out)
        OE_RAISE_ERRNO(OE_EINVAL);

    if (!epoll)
        OE_RAISE_ERRNO(OE_EINVAL);

    /* Call host: */
    {
        if (oe_syscall_dup_ocall(&retval, epoll->host_fd) != OE_OK)
            OE_RAISE_ERRNO(OE_EINVAL);

        if (retval == -1)
            OE_RAISE_ERRNO(oe_errno);
    }

    /* Create the new epoll object. */
    {
        if (!(new_epoll = oe_calloc(1, sizeof(epoll_t))))
            OE_RAISE_ERRNO(oe_errno);

        new_epoll->base.type = OE_FD_TYPE_EPOLL;
        new_epoll->base.ops.epoll = _get_epoll_ops();
        new_epoll->magic = EPOLL_MAGIC;
        new_epoll->host_fd = retval;

        if (epoll->map && epoll->map_size)
        {
            mapping_t* map;

            if (!(map = oe_calloc(epoll->map_size, sizeof(mapping_t))))
                OE_RAISE_ERRNO(OE_ENOMEM);

            memcpy(map, epoll->map, epoll->map_size * sizeof(mapping_t));
            new_epoll->map = map;
            new_epoll->map_size = epoll->map_size;
        }

        *new_epoll_out = &new_epoll->base;
        new_epoll = NULL;
    }

    ret = 0;

done:

    if (new_epoll)
        oe_free(new_epoll);

    return ret;
}
static int _epoll_dup(oe_fd_t* epoll_, oe_fd_t** new_epoll_out)
{
    int ret = -1;
    epoll_t* epoll = _cast_epoll(epoll_);
    epoll_t* new_epoll = NULL;
    oe_host_fd_t retval;

    oe_errno = 0;

     
    if (!new_epoll_out)
        OE_RAISE_ERRNO(OE_EINVAL);

    if (!epoll)
        OE_RAISE_ERRNO(OE_EINVAL);

     
    {
        if (oe_syscall_dup_ocall(&retval, epoll->host_fd) != OE_OK)
            OE_RAISE_ERRNO(OE_EINVAL);

        if (retval == -1)
            OE_RAISE_ERRNO(oe_errno);
    }

     
    {
        if (!(new_epoll = oe_calloc(1, sizeof(epoll_t))))
            OE_RAISE_ERRNO(oe_errno);

        new_epoll->base.type = OE_FD_TYPE_EPOLL;
        new_epoll->base.ops.epoll = _get_epoll_ops();
        new_epoll->magic = EPOLL_MAGIC;
        new_epoll->host_fd = retval;

        if (epoll->map && epoll->map_size)
        {
            mapping_t* map;

            if (!(map = oe_calloc(epoll->map_size, sizeof(mapping_t))))
                OE_RAISE_ERRNO(OE_ENOMEM);

            memcpy(map, epoll->map, epoll->map_size * sizeof(mapping_t));
            new_epoll->map = map;
            new_epoll->map_size = epoll->map_size;
        }

        *new_epoll_out = &new_epoll->base;
        new_epoll = NULL;
    }

    ret = 0;

done:

    if (new_epoll)
        oe_free(new_epoll);

    return ret;
}