Re: [RESEND PATCH 1/1] bitops.h: move out get_count_order[_long]() from __KERNEL__ scope

From: zijun_hu
Date: Wed Aug 17 2016 - 20:11:10 EST


On 2016/8/18 7:59, Al Viro wrote:
> On Thu, Aug 18, 2016 at 07:51:19AM +0800, zijun_hu wrote:
>>> What the hell is anything without __KERNEL__ doing with linux/bitops.h in
>>> the first place? IOW, why do we have those ifdefs at all?
>>>
>>
>> __KERNEL__ is used to indicate the relevant sections within kernel
>> headers can't be exported to or used by user space
>
> ITYM "used to be used". These days it's "everything outside of */uapi/*.h
> can't be exported"...
>
i conclude one purpose of __KERNEL__ from the following kernel files

scripts/headers_install.sh:
echo "Usage: headers_install.sh OUTDIR SRCDIR [FILES...]"
echo
echo "Prepares kernel header files for use by user space, by removing"
echo "all compiler.h definitions and #includes, removing any"
echo "#ifdef __KERNEL__ sections, and putting __underscores__ around"
echo "asm/inline/volatile keywords."
echo
......
scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__ "$OUTDIR/$FILE.sed"

Documentation/kbuild/makefiles.txtï
The kernel includes a set of headers that is exported to userspace.
Many headers can be exported as-is but other headers require a
minimal pre-processing before they are ready for user-space.
The pre-processing does:
- drop kernel-specific annotations
- drop include of compiler.h
- drop all sections that are kernel internal (guarded by ifdef __KERNEL__)

scripts/Makefile.headersinst:
# ==========================================================================
# Installing headers
#
# header-y - list files to be installed. They are preprocessed
# to remove __KERNEL__ section of the file
# genhdr-y - Same as header-y but in a generated/ directory
#
# ==========================================================================