ESP32 crashes when polling STDIN

johannesbehr
Posts: 2
Joined: Sat Apr 29, 2023 5:44 pm

ESP32 crashes when polling STDIN

Postby johannesbehr » Wed May 03, 2023 7:14 pm

Hello!

I want to use the poll-function from <sys/poll.h> to poll the STDIN (default FD 0).
(I'm using the ArduinoIDE and want to port https://midish.org/ to ESP32)
But this provokes always a crash with abort()...

Unfortunately I can't debug, but it seems that the crash occurs in the select-method.

Does anyone knows what this could be?

Here is my test code:

pstdio.c:

Code: Select all

#include <sys/poll.h>
#include <unistd.h>

struct pollfd pfds[1];

void poll_stdio(){
  // Every value from 0 to 2 (STDIN.., STDOUT.. and STDERR_FILENO) makes it crash with "abort()"
  // pfds[0].fd = 3; //... works
  pfds[0].fd = STDIN_FILENO;
  pfds[0].events = POLLIN;
  nfds_t nfds = 1;
  int res = poll(&pfds, nfds, 1); 
}

pstdio.h:

Code: Select all

#ifdef __cplusplus
extern "C" {
#endif
void poll_stdio();
#ifdef __cplusplus
}
#endif

Code: Select all

#include "pstdio.h"

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  poll_stdio();  	
}

void loop() {
  // put your main code here, to run repeatedly:
}
The crash is the following:

Code: Select all

ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4
abort() was called at PC 0x400832e5 on core 1

ELF file SHA256: 0000000000000000

Backtrace: 0x40084ea0:0x3ffb19e0 0x40085115:0x3ffb1a00 0x400832e5:0x3ffb1a20 0x40083411:0x3ffb1a50 0x400dd7e6:0x3ffb1a70 0x400d96b9:0x3ffb1d80 0x40081305:0x3ffb1db0 0x400d39d9:0x3ffb1de0 0x400e97c3:0x3ffb1e30 0x400e7434:0x3ffb1e60 0x400e8a93:0x3ffb1ea0 0x400e8d79:0x3ffb1f00 0x400e3515:0x3ffb1f40 0x400d0c92:0x3ffb1f60 0x400d0c60:0x3ffb1f80 0x400d1ea2:0x3ffb1fb0 0x40086125:0x3ffb1fd0

Rebooting...

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 crashes when polling STDIN

Postby lbernstone » Thu May 04, 2023 5:06 am

Debug the backtrace with https://github.com/me-no-dev/EspExceptionDecoder
STDIN != serial input. If you want to read from the uart/serial use the Serial object.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 41 guests