Skip to content

Commit 3c7a8e1

Browse files
committed
uapi: introduce uapi-friendly macros for GENMASK
Move __GENMASK and __GENMASK_ULL from include/ to include/uapi/ so that they can be used to define masks in userspace API headers. Compared to what is already in include/linux/bits.h, the definitions need to use the uglified versions of UL(), ULL(), BITS_PER_LONG and BITS_PER_LONG_LONG (which did not even exist), but otherwise expand to the same content. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 0473719 commit 3c7a8e1

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

include/linux/bits.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <linux/const.h>
66
#include <vdso/bits.h>
7+
#include <uapi/linux/bits.h>
78
#include <asm/bitsperlong.h>
89

910
#define BIT_MASK(nr) (UL(1) << ((nr) % BITS_PER_LONG))
@@ -30,15 +31,8 @@
3031
#define GENMASK_INPUT_CHECK(h, l) 0
3132
#endif
3233

33-
#define __GENMASK(h, l) \
34-
(((~UL(0)) - (UL(1) << (l)) + 1) & \
35-
(~UL(0) >> (BITS_PER_LONG - 1 - (h))))
3634
#define GENMASK(h, l) \
3735
(GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
38-
39-
#define __GENMASK_ULL(h, l) \
40-
(((~ULL(0)) - (ULL(1) << (l)) + 1) & \
41-
(~ULL(0) >> (BITS_PER_LONG_LONG - 1 - (h))))
4236
#define GENMASK_ULL(h, l) \
4337
(GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l))
4438

include/uapi/asm-generic/bitsperlong.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@
2424
#endif
2525
#endif
2626

27+
#ifndef __BITS_PER_LONG_LONG
28+
#define __BITS_PER_LONG_LONG 64
29+
#endif
30+
2731
#endif /* _UAPI__ASM_GENERIC_BITS_PER_LONG */

include/uapi/linux/bits.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+
/* bits.h: Macros for dealing with bitmasks. */
3+
4+
#ifndef _UAPI_LINUX_BITS_H
5+
#define _UAPI_LINUX_BITS_H
6+
7+
#define __GENMASK(h, l) \
8+
(((~_UL(0)) - (_UL(1) << (l)) + 1) & \
9+
(~_UL(0) >> (__BITS_PER_LONG - 1 - (h))))
10+
11+
#define __GENMASK_ULL(h, l) \
12+
(((~_ULL(0)) - (_ULL(1) << (l)) + 1) & \
13+
(~_ULL(0) >> (__BITS_PER_LONG_LONG - 1 - (h))))
14+
15+
#endif /* _UAPI_LINUX_BITS_H */

0 commit comments

Comments
 (0)