In WASIX, eventfd created with EFD_SEMAPHORE does not follow Linux semantics: each read should return 1 and decrement the counter by one. Our implementation decrements the counter correctly, but instead of returning 1 it returns the current counter value, which breaks counting‑semaphore expectations and can cause incorrect behaviour in runtimes that rely on that.
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/eventfd.h>
#include <unistd.h>
int main(void) {
// Semaphore with 4 permits
int fd = eventfd(0, EFD_SEMAPHORE | EFD_NONBLOCK);
uint64_t four = 4;
write(fd, &four, sizeof(four));
uint64_t out = 0;
for (int i = 0; i < 4; i++) {
assert(read(fd, &out, sizeof(out)) == 8);
// Expected: semaphore mode returns 1 per read.
if (out != 1) {
printf("BUG: expected 1, got %" PRIu64 "\n", out);
return 1;
}
}
}
In WASIX, eventfd created with
EFD_SEMAPHOREdoes not follow Linux semantics: each read should return1and decrement the counter by one. Our implementation decrements the counter correctly, but instead of returning1it returns the current counter value, which breaks counting‑semaphore expectations and can cause incorrect behaviour in runtimes that rely on that.