Skip to content

Conversation

@tonycoz
Copy link
Contributor

@tonycoz tonycoz commented May 29, 2025

…(nonsocket)

And since it never succeeds on Win32, just skip.

Fixes #23335


  • This set of changes does not require a perldelta entry.

…(nonsocket)

And since it never succeeds on Win32, just skip.

Fixes Perl#23335
@bulk88
Copy link
Contributor

bulk88 commented May 29, 2025

sub blocking {
    my $sock = shift;
    return $sock->SUPER::blocking(@_)
        if $^O ne 'MSWin32' && $^O ne 'VMS';
# CUT comments
    my $orig= !${*$sock}{io_sock_nonblocking};
    return $orig unless @_;
    my $block = shift;
    if ( !$block != !$orig ) {
        ${*$sock}{io_sock_nonblocking} = $block ? 0 : 1;
        ioctl($sock, 0x8004667e, pack("L!",${*$sock}{io_sock_nonblocking})) #### <<<<< HERE
            or return undef;
    }
    return $orig;
}

Is there a COW/PADTMP problem with returned SVPV* of pp_pack() here? or a CPerlHost() vs win32_*() problem? win32.c has both a confusing win32_ioctl() and win32_ioctlsocket(), both goto winsock.dll in the end, but they have different func bodies.

@bulk88
Copy link
Contributor

bulk88 commented May 29, 2025

And Perl_pp_ioctl() needs a major CPP #if cleanup, it calls all the GV* IO* SVIV* SVUV* SVPV* and SvGROW() getters, allocers, and vivifiers, before calling Perl_die("fcntl is not implemented"); Perl_die("ioctl is not implemented");

@bulk88
Copy link
Contributor

bulk88 commented May 29, 2025

Git blame doesn't really explain the winsock char*/DWORD * "alignment" issue, but unresearched hypothesis, some frontend ware, middle ware, backend ware, or kernel ware (afd.sys) is stealing the lowest 2 or 3 bits for tagging, or afd.sys is SEGVing in Ring 0 attempting to read or write to that pointer. A SEH try/catch block in afd.sys silences/resumes/recovers from the bad CPU mem read or a bad NIC DMA memory read (bulk88 thinks # 2 isn't real, a PCIe NIC can't see or pull IP flow control/buffering logic on its own, its pushed to the NIC if it even participates in that).

/* XXX Why are APIs like sleep(), times() etc. inside a block
 * XXX guarded by "#ifndef WIN32IO_IS_STDIO"? */
#define ioctl			win32_ioctl
/////////CUT
#ifndef WIN32SCK_IS_STDSCK
/* direct to our version */
#define ioctlsocket	win32_ioctlsocket
/////////CUT
#  define PerlLIO_ioctl(fd, u, buf)     ioctl((fd), (u), (buf))
/////////CUT
#  define PerlLIO_ioctl(fd, u, buf)                                     \
        ((*(PL_LIO))->pIOCtl)(PL_LIO, (fd), (u), (buf))
/////////CUT
PP_wrapped(pp_ioctl, 3, 0) {
.............................
    if (optype == OP_IOCTL)
#ifdef HAS_IOCTL
        retval = PerlLIO_ioctl(PerlIO_fileno(IoIFP(io)), func, s);
#else
        DIE(aTHX_ "ioctl is not implemented");
#endif
/////////CUT
int win32_ioctlsocket(SOCKET s, long cmd, u_long *argp) {
    int r;
    SOCKET_TEST_ERROR(r = ioctlsocket(TO_SOCKET(s), cmd, argp));
    return r;
}
int win32_ioctl(int i, unsigned int u, char *data) {
    u_long u_long_arg; 
    int retval;
    /* mauke says using memcpy avoids alignment issues */
    memcpy(&u_long_arg, data, sizeof u_long_arg); 
    retval = ioctlsocket(TO_SOCKET(i), (long)u, &u_long_arg);
    memcpy(data, &u_long_arg, sizeof u_long_arg);
    if (retval == SOCKET_ERROR) {
        int wsaerr = WSAGetLastError();
        int err = convert_wsa_error_to_errno(wsaerr);
        if (err == ENOTSOCK) {
            Perl_croak_nocontext("ioctl implemented only on sockets");
            /* NOTREACHED */
        }
        errno = err;
        SetLastError(wsaerr);
    }
    return retval;
}
int
PerlSockIoctlsocket(const struct IPerlSock** piPerl, SOCKET s, long cmd, u_long *argp)
{
    PERL_UNUSED_ARG(piPerl);
    return win32_ioctlsocket(s, cmd, argp);
}
int PerlLIOIOCtl(const struct IPerlLIO** piPerl, int i, unsigned int u, char *data) {
    u_long u_long_arg;
    int retval;
    PERL_UNUSED_ARG(piPerl);
    /* mauke says using memcpy avoids alignment issues */
    memcpy(&u_long_arg, data, sizeof u_long_arg); 
    retval = win32_ioctlsocket((SOCKET)i, (long)u, &u_long_arg);
    memcpy(data, &u_long_arg, sizeof u_long_arg);
    return retval;
}

@haarg haarg merged commit 74ec8b8 into Perl:blead May 29, 2025
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perl-5.41.13 fails t/op/readline_nb.t on unthreaded builds

3 participants