]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb/tdep] Fix selftest scoped_mmap on freebsd
authorTom de Vries <tdevries@suse.de>
Sat, 5 Jul 2025 11:29:53 +0000 (13:29 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 5 Jul 2025 11:29:53 +0000 (13:29 +0200)
commite7dd0a0cf4f439f444f4a15d8ea4e1ab8185acbf
tree854e1e4730be5ec88527ca58840334470f01b79c
parentb930f28b490d2b45049497afa66e1b42aeffbc9b
[gdb/tdep] Fix selftest scoped_mmap on freebsd

On x86_64-freebsd, I run into:
...
$ gdb -q -batch -ex "maint selftest scoped_mmap"
Running selftest scoped_mmap.
Self test failed: self-test failed at scoped_mmap-selftests.c:50

Failures:
  scoped_mmap

Ran 1 unit tests, 1 failed
...

The problem is that this call:
...
    ::scoped_mmap smmap (nullptr, sysconf (_SC_PAGESIZE), PROT_WRITE,
 MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
...
returns MAP_FAILED and sets errno to EINVAL because the argument fd == 0.

If MAP_ANONYMOUS is used, fd == -1 should be used on freebsd.  On linux, fd is
ignored but -1 is recommended for portability.

Fix this by using fd == -1 instead.

Tested x86_64-freebsd and x86_64-linux.
gdb/unittests/scoped_mmap-selftests.c