]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/tst-mman-consts.py
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / tst-mman-consts.py
CommitLineData
df648905
JM
1#!/usr/bin/python3
2# Test that glibc's sys/mman.h constants match the kernel's.
04277e02 3# Copyright (C) 2018-2019 Free Software Foundation, Inc.
df648905
JM
4# This file is part of the GNU C Library.
5#
6# The GNU C Library is free software; you can redistribute it and/or
7# modify it under the terms of the GNU Lesser General Public
8# License as published by the Free Software Foundation; either
9# version 2.1 of the License, or (at your option) any later version.
10#
11# The GNU C Library is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# Lesser General Public License for more details.
15#
16# You should have received a copy of the GNU Lesser General Public
17# License along with the GNU C Library; if not, see
18# <http://www.gnu.org/licenses/>.
19
20import argparse
21import sys
22
23import glibcextract
24
25
26def linux_kernel_version(cc):
27 """Return the (major, minor) version of the Linux kernel headers."""
28 sym_data = ['#include <linux/version.h>', 'START',
29 ('LINUX_VERSION_CODE', 'LINUX_VERSION_CODE')]
30 val = glibcextract.compute_c_consts(sym_data, cc)['LINUX_VERSION_CODE']
31 val = int(val)
32 return ((val & 0xff0000) >> 16, (val & 0xff00) >> 8)
33
34
35def main():
36 """The main entry point."""
37 parser = argparse.ArgumentParser(
38 description="Test that glibc's sys/mman.h constants "
39 "match the kernel's.")
40 parser.add_argument('--cc', metavar='CC',
41 help='C compiler (including options) to use')
42 args = parser.parse_args()
43 linux_version_headers = linux_kernel_version(args.cc)
44 linux_version_glibc = (4, 19)
45 sys.exit(glibcextract.compare_macro_consts(
46 '#define _GNU_SOURCE 1\n'
47 '#include <sys/mman.h>\n',
48 '#define _GNU_SOURCE 1\n'
49 '#include <linux/mman.h>\n',
50 args.cc,
51 'MAP_.*',
52 # A series of MAP_HUGE_<size> macros are defined by the kernel
53 # but not by glibc. MAP_UNINITIALIZED is kernel-only.
54 # MAP_FAILED is not a MAP_* flag and is glibc-only, as is the
55 # MAP_ANON alias for MAP_ANONYMOUS. MAP_RENAME, MAP_AUTOGROW,
56 # MAP_LOCAL and MAP_AUTORSRV are in the kernel header for
57 # MIPS, marked as "not used by linux"; SPARC has MAP_INHERIT
58 # in the kernel header, but does not use it.
59 'MAP_HUGE_[0-9].*|MAP_UNINITIALIZED|MAP_FAILED|MAP_ANON'
60 '|MAP_RENAME|MAP_AUTOGROW|MAP_LOCAL|MAP_AUTORSRV|MAP_INHERIT',
61 linux_version_glibc > linux_version_headers,
62 linux_version_headers > linux_version_glibc))
63
64if __name__ == '__main__':
65 main()