Skip to content

Commit 383618c

Browse files
mgeisertchrfranke
authored andcommitted
Cygwin: Fix error return for madvise()
Currently madvise() and posix_madvise() are wired together as one function: the latter. But their error returns should be different. Make madvise a first-class export in cygwin.din. v2: Create madvise_worker() and have madvise() and posix_madvise() call it, then handling their error returns compliant to POSIX. Add a release note for 3.7.0. Reported-by: Christian Franke <Christian.Franke@t-online.de> Addresses: https://cygwin.com/pipermail/cygwin/2026-July/259872.html Signed-off-by: Mark Geisert <mark@maxrnd.com> Fixes: 6152219 (* Merge in cygwin-64bit-branch.) Reviewed-by: Takashi Yano, Christian Franke
1 parent 4e642b1 commit 383618c

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

winsup/cygwin/cygwin.din

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ lseek SIGFE
951951
lsetxattr SIGFE
952952
lstat SIGFE
953953
lutimes SIGFE
954-
madvise = posix_madvise SIGFE
954+
madvise SIGFE
955955
makecontext NOSIGFE
956956
mallinfo SIGFE
957957
malloc SIGFE

winsup/cygwin/mm/mmap.cc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,8 +1422,8 @@ munlock (const void *addr, size_t len)
14221422
return ret;
14231423
}
14241424

1425-
extern "C" int
1426-
posix_madvise (void *addr, size_t len, int advice)
1425+
static int
1426+
madvise_worker (void *addr, size_t len, int advice)
14271427
{
14281428
int ret = 0;
14291429
/* Check parameters. */
@@ -1514,6 +1514,26 @@ posix_madvise (void *addr, size_t len, int advice)
15141514
break;
15151515
}
15161516
out:
1517+
return ret;
1518+
}
1519+
1520+
extern "C" int
1521+
madvise (void *addr, size_t len, int advice)
1522+
{
1523+
int ret = madvise_worker (addr, len, advice);
1524+
if (ret > 0)
1525+
{
1526+
set_errno (ret);
1527+
ret = -1;
1528+
}
1529+
syscall_printf ("%R = madvise(%p, %lu, %d)", ret, addr, len, advice);
1530+
return ret;
1531+
}
1532+
1533+
extern "C" int
1534+
posix_madvise (void *addr, size_t len, int advice)
1535+
{
1536+
int ret = madvise_worker (addr, len, advice);
15171537
syscall_printf ("%d = posix_madvise(%p, %lu, %d)", ret, addr, len, advice);
15181538
return ret;
15191539
}

winsup/cygwin/release/3.7.0

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ What's new:
2525
- Now, a Cygwin process started from a non‑Cygwin process on a pseudo console
2626
runs on a pty rather than on the console device originating from the pseudo
2727
console.
28+
29+
Fixes:
30+
------
31+
32+
- Error return logic for madvise() is now separated from posix_madvise().
33+
If madvise() errors, it returns -1 with errno set. If posix_madvise()
34+
errors, it returns an error number without changing errno.
35+
Addresses: https://cygwin.com/pipermail/cygwin/2026-July/259872.html

0 commit comments

Comments
 (0)