blink
blink copied to clipboard
assertion failed errno == EINTR (EBADF) running blinkenlights -rt sectorlisp.bin on WSL
I built blinkenlights from source using the default Ubuntu that WSL installed (which is focal). I built sectorlisp's friendly branch. When I run blinkenlights -rt sectorlisp.bin I see:
assertion failed
blink/blinkenlights.c:2351:1539 assertion failed: errno == EINTR (EBADF)
PC 7ca3 mov $14,%ah b4 0e 55 cd 10 5d 3c 0d
AX 0000000000000000 CX 0000000000008000 DX 0000000000000000 BX 0000000000000002
SP 0000000000007ffa BP 0000000000000000 SI 000000000000ffff DI 0000000000008000
R8 0000000000000000 R9 0000000000000000 R10 0000000000000000 R11 0000000000000000
R12 0000000000000000 R13 0000000000000000 R14 0000000000000000 R15 0000000000000000
FS 0000000000000000 GS 0000000000000000 OPS 26 FLG ..Z...
sectorlisp.bin
000000007c00 0000000000a3 PutChar
<blink backtrace unavailable>
instructions_cached = 26
instructions_decoded = 26
jit_callocs = 130
jit_frees = 1
instructions_cached = 26
instructions_decoded = 26
jit_callocs = 130
jit_frees = 1
fish: '~/bin/blinkenlights -rt sectorl…' terminated by signal SIGABRT (Abort)
brainf**k.bin fails similarly but not on the same line:
assertion failed
blink/blinkenlights.c:2351:1588 assertion failed: errno == EINTR (EBADF)
PC 7c08 stosb %al,(%di) aa 3c 5b 74 52 3c 5d 74
AX 0000000000000000 CX 0000000000000000 DX 0000000000000080 BX 0000000000000000
SP 0000000000006efe BP 0000000000000000 SI 0000000000000000 DI 0000000000007e00
R8 0000000000000000 R9 0000000000000000 R10 0000000000000000 R11 0000000000000000
R12 0000000000000000 R13 0000000000000000 R14 0000000000000000 R15 0000000000000000
FS 0000000000000000 GS 0000000000000000 OPS 5 FLG ..Z...
brainfuck.bin
000000000000 000000007c08 UNKNOWN
<blink backtrace unavailable>
instructions_cached = 5
instructions_decoded = 5
jit_callocs = 130
jit_frees = 1
instructions_cached = 5
instructions_decoded = 5
jit_callocs = 130
jit_frees = 1
fish: '~/bin/blinkenlights -rt brainfu…' terminated by signal SIGABRT (Abort)
Were you typing something when this happened, or does this happen without any keyboard input? The case below describes a known problem with EAGAIN sometimes being returned for a non-error case, which would need to be handled in addition to EINTR. If EGAIN is not being returned, perhaps just comment out the unassert on line 2351.
I see you're running on WSL but there are cases where Linux will return -1 and errno == EGAIN when a function/arrow key has been pressed and only a portion of its ANSI multi-character sequence is read, or has yet been processed by the kernel. So you might try something like the following just before line 2331 of blink/blinkenlights.c:
if (rc == -1 && errno == EAGAIN) { /* Linux may return EAGAIN on fn key seq */
struct pollfd pfd[1];
pfd[0].fd = fd;
pfd[0].events = POLLIN;
poll(pfd, 1, 0);
continue;
}
I have had to add this in the library readansi routine called by ReadAnsi (for a different project) but adding it here may solve your problem. I suspect that the poll call isn't strictly necessary - without it blink might busy loop returning EAGAIN for a small while waiting for the remainder of the ANSI sequence to be processed.
Wasn't typing anything. Just immediately crashes
Can you comment out the unassert on line 2351 and try again? I don't have WSL with which to test. A real solution needs more than that, but removing the assert should allow the program to continue being emulated even though errno != EINTR.
doesn't crash if I comment out the unassert.
Thanks for the continued testing @swolchok. I'm glad to hear this change allows blink to run sectorlisp. I'll fix this, but would like to learn what the errno is that's not EINTR. I'm guessing EAGAIN, but will try to confirm first.