Bug 254120 - Linuxulator: getcwd returns ENOMEM instead of ERANGE
Summary: Linuxulator: getcwd returns ENOMEM instead of ERANGE
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Only Me
Assignee: Edward Tomasz Napierala
URL:
Keywords:
Depends on:
Blocks: 247219
  Show dependency treegraph
 
Reported: 2021-03-08 03:06 UTC by Alex S
Modified: 2021-03-17 10:10 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex S 2021-03-08 03:06:44 UTC
% cat getcwd.c 
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>

int main() {

  char buf[3];
  assert(getcwd(buf, sizeof(buf)) == NULL);
  if (errno != ERANGE) {    
    perror("getcwd");
  }

  return 0;
}
% pwd | wc -c
      29
% /compat/linux/bin/cc getcwd.c -o getcwd
% ./getcwd 
getcwd: Cannot allocate memory

On the Linux side getcwd is clearly documented to return ERANGE and
at least Mono actually expects it:
https://github.com/mono/mono/blob/da11592cbea4269971f4b1f9624769a85cc10660/mono/eglib/gfile-posix.c#L175.

This is mostly relevant for FNA/MonoGame applications.
Comment 1 Edward Tomasz Napierala freebsd_committer 2021-03-11 12:21:35 UTC
https://reviews.freebsd.org/D29217
Comment 2 commit-hook freebsd_committer 2021-03-12 15:34:53 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=0dfbdd9fc269f0438ffcc31632d35234a90584ad

commit 0dfbdd9fc269f0438ffcc31632d35234a90584ad
Author:     Edward Tomasz Napierala <trasz@FreeBSD.org>
AuthorDate: 2021-03-12 15:31:37 +0000
Commit:     Edward Tomasz Napierala <trasz@FreeBSD.org>
CommitDate: 2021-03-12 15:31:45 +0000

    linux(4): make getcwd(2) return ERANGE instead of ENOMEM

    For native FreeBSD binaries, the return value from __getcwd(2)
    doesn't really matter, as the libc wrapper takes over and returns
    the proper errno.

    PR:             kern/254120
    Reported By:    Alex S <iwtcex@gmail.com>
    Reviewed By:    kib
    Sponsored By:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D29217

 sys/compat/linux/linux_getcwd.c | 2 ++
 1 file changed, 2 insertions(+)
Comment 3 commit-hook freebsd_committer 2021-03-15 13:40:55 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ab1a91d95872e59db3d476be4fefb0b58df3afc4

commit ab1a91d95872e59db3d476be4fefb0b58df3afc4
Author:     Edward Tomasz Napierala <trasz@FreeBSD.org>
AuthorDate: 2021-03-12 15:31:37 +0000
Commit:     Edward Tomasz Napierala <trasz@FreeBSD.org>
CommitDate: 2021-03-15 13:00:17 +0000

    linux(4): make getcwd(2) return ERANGE instead of ENOMEM

    For native FreeBSD binaries, the return value from __getcwd(2)
    doesn't really matter, as the libc wrapper takes over and returns
    the proper errno.

    PR:             kern/254120
    Reported By:    Alex S <iwtcex@gmail.com>
    Reviewed By:    kib
    Sponsored By:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D29217

    (cherry picked from commit 0dfbdd9fc269f0438ffcc31632d35234a90584ad)

 sys/compat/linux/linux_getcwd.c | 2 ++
 1 file changed, 2 insertions(+)
Comment 4 commit-hook freebsd_committer 2021-03-16 18:39:10 UTC
A commit in branch releng/13.0 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=56dd03e0f2b17e703ba8daad8bc9ab21a761a461

commit 56dd03e0f2b17e703ba8daad8bc9ab21a761a461
Author:     Edward Tomasz Napierala <trasz@FreeBSD.org>
AuthorDate: 2021-03-12 15:31:37 +0000
Commit:     Edward Tomasz Napierala <trasz@FreeBSD.org>
CommitDate: 2021-03-16 18:37:57 +0000

    linux(4): make getcwd(2) return ERANGE instead of ENOMEM

    For native FreeBSD binaries, the return value from __getcwd(2)
    doesn't really matter, as the libc wrapper takes over and returns
    the proper errno.

    Approved by:    re (gjb)
    PR:             kern/254120
    Reported By:    Alex S <iwtcex@gmail.com>
    Reviewed By:    kib
    Sponsored By:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D29217

    (cherry picked from commit 0dfbdd9fc269f0438ffcc31632d35234a90584ad)
    (cherry picked from commit ab1a91d95872e59db3d476be4fefb0b58df3afc4)

 sys/compat/linux/linux_getcwd.c | 2 ++
 1 file changed, 2 insertions(+)