Duncan Coutts pushed to branch wip/dcoutts/io-manager-tidy at Glasgow Haskell Compiler / GHC
Commits:
-
0cd74e31
by Duncan Coutts at 2026-07-16T21:21:04+01:00
-
95d7e7e5
by Duncan Coutts at 2026-07-16T21:23:33+01:00
3 changed files:
Changes:
| ... | ... | @@ -319,7 +319,7 @@ void scavengeTSOIOManager(StgTSO *tso); |
| 319 | 319 | /* Several code paths are almost identical between read and write paths. In
|
| 320 | 320 | * such cases we use a shared code path with an enum to say which we're doing.
|
| 321 | 321 | */
|
| 322 | -typedef enum { IORead, IOWrite } IOReadOrWrite;
|
|
| 322 | +typedef enum { IORead = 0, IOWrite = 1 } IOReadOrWrite;
|
|
| 323 | 323 | |
| 324 | 324 | /* Synchronous operations: I/O and delays. As synchronous operations they
|
| 325 | 325 | * necessarily operate on threads. The thread is suspended until the operation
|
| ... | ... | @@ -2269,7 +2269,7 @@ stg_waitReadzh ( W_ fd ) |
| 2269 | 2269 | |
| 2270 | 2270 | (ok) = ccall syncIOWaitReady(Capability_iomgr(MyCapability()) "ptr",
|
| 2271 | 2271 | CurrentTSO "ptr",
|
| 2272 | - /* IORead */ 0::I32, fd);
|
|
| 2272 | + /* IORead */ 0::CInt, fd);
|
|
| 2273 | 2273 | if (ok != 0::CBool) (likely: True) {
|
| 2274 | 2274 | jump stg_block_noregs();
|
| 2275 | 2275 | } else {
|
| ... | ... | @@ -63,6 +63,14 @@ void initCapabilityIOManagerSelect(CapIOManager *iomgr) |
| 63 | 63 | |
| 64 | 64 | #if defined(HAVE_PREEMPTION)
|
| 65 | 65 | newFdWakeup(&iomgr->interrupt_fd_r, &iomgr->interrupt_fd_w);
|
| 66 | + |
|
| 67 | + /* Would never happen in a standalone process, but could plausibly happen
|
|
| 68 | + * if the RTS is used within another process that already has many open fds.
|
|
| 69 | + */
|
|
| 70 | + if (iomgr->interrupt_fd_r < 0 || iomgr->interrupt_fd_r >= (int)FD_SETSIZE ||
|
|
| 71 | + iomgr->interrupt_fd_w < 0 || iomgr->interrupt_fd_w >= (int)FD_SETSIZE) {
|
|
| 72 | + barf("initCapabilityIOManagerSelect: fds out of select range");
|
|
| 73 | + }
|
|
| 66 | 74 | #endif
|
| 67 | 75 | }
|
| 68 | 76 | |
| ... | ... | @@ -284,6 +292,7 @@ awaitCompletedTimeoutsOrIOSelect(CapIOManager *iomgr, bool wait) |
| 284 | 292 | {
|
| 285 | 293 | int fd = iomgr->interrupt_fd_r;
|
| 286 | 294 | maxfd = (fd > maxfd) ? fd : maxfd;
|
| 295 | + ASSERT(fd >= 0 && fd < (int)FD_SETSIZE); // checked during init
|
|
| 287 | 296 | FD_SET(fd, &rfd);
|
| 288 | 297 | }
|
| 289 | 298 | #endif
|