lkml.org 
[lkml]   [2013]   [Feb]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [tip:x86/mm] x86, mm: Use a bitfield to mask nuisance get_user() warnings
On 02/12/2013 09:00 AM, Linus Torvalds wrote:
> On Tue, Feb 12, 2013 at 8:38 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>
>> Can you do something similar to what we did in glibc:
>
> No. Because we use macros to be type-independent (i e"get_user()"
> works *regardless* of type), so casting to "uintptr_t" doesn't work.
> It throws away the type information, and truncates 64-bit values on
> 32-bit architectures.
>
> The whole point of the bitmask thing is that it doesn't have that
> issue, and gets the size correct automatically. It's not pretty, but
> it allows the rest of the sources to be readable.
>

No, I think what he is talking about it this bit:

/* 1 if 'type' is a pointer type, 0 otherwise. */
# define __pointer_type(type) (__builtin_classify_type ((type) 0) == 5)

/* __intptr_t if P is true, or T if P is false. */
# define __integer_if_pointer_type_sub(T, P) \
__typeof__ (*(0 ? (__typeof__ (0 ? (T *) 0 : (void *) (P))) 0 \
: (__typeof__ (0 ? (__intptr_t *) 0 : (void *)(!(P)))) 0))

/* __intptr_t if EXPR has a pointer type, or the type of EXPR otherwise. */
# define __integer_if_pointer_type(expr) \
__integer_if_pointer_type_sub(__typeof__ ((__typeof__ (expr)) 0), \
__pointer_type (__typeof__ (expr)))

/* Cast an integer or a pointer VAL to integer with proper type. */
# define cast_to_integer(val) ((__integer_if_pointer_type (val)) (val))

Good grief, this makes the bitfield look like Mona Lisa. On the other
hand, it relies on the *entirely* undocumented __builtin_classify_type()
-- there appears to be absolutely no reference to it in gcc documentation.

H.J., do you know what the bounds on the __builtin_classify_type() are
(gcc versions available and so on)? Sadly I don't think one can use
__builtin_types_compatible_p() instead.

-hpa



\
 
 \ /
  Last update: 2013-02-12 19:01    [W:0.081 / U:0.244 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site