[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <nycvar.YFH.7.77.849.2007231725090.11202@n3.vanv.qr>
Date: Thu, 23 Jul 2020 17:40:49 +0200 (CEST)
From: Jan Engelhardt <jengelh@...i.de>
To: Christoph Hellwig <hch@....de>
cc: "David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Alexey Kuznetsov <kuznet@....inr.ac.ru>,
Hideaki YOSHIFUJI <yoshfuji@...ux-ipv6.org>,
Eric Dumazet <edumazet@...gle.com>,
linux-crypto@...r.kernel.org, linux-kernel@...r.kernel.org,
netdev@...r.kernel.org, bpf@...r.kernel.org,
Netfilter Developer Mailing List
<netfilter-devel@...r.kernel.org>, coreteam@...filter.org,
linux-sctp@...r.kernel.org, linux-hams@...r.kernel.org,
linux-bluetooth@...r.kernel.org, bridge@...ts.linux-foundation.org,
linux-can@...r.kernel.org, dccp@...r.kernel.org,
linux-decnet-user@...ts.sourceforge.net,
linux-wpan@...r.kernel.org, linux-s390@...r.kernel.org,
mptcp@...ts.01.org, lvs-devel@...r.kernel.org,
rds-devel@....oracle.com, linux-afs@...ts.infradead.org,
tipc-discussion@...ts.sourceforge.net, linux-x25@...r.kernel.org
Subject: Re: [PATCH 04/26] net: add a new sockptr_t type
On Thursday 2020-07-23 08:08, Christoph Hellwig wrote:
>+typedef struct {
>+ union {
>+ void *kernel;
>+ void __user *user;
>+ };
>+ bool is_kernel : 1;
>+} sockptr_t;
>+
>+static inline bool sockptr_is_null(sockptr_t sockptr)
>+{
>+ return !sockptr.user && !sockptr.kernel;
>+}
"""If the member used to access the contents of a union is not the same as the
member last used to store a value, the object representation of the value that
was stored is reinterpreted as an object representation of the new type (this
is known as type punning). If the size of the new type is larger than the size
of the last-written type, the contents of the excess bytes are unspecified (and
may be a trap representation)"""
As I am not too versed with the consequences of trap representations, I will
just point out that a future revision of the C standard may introduce (proposal
N2362) stronger C++-like requirements; as for union, that would imply a simple:
"""It's undefined behavior to read from the member of the union that wasn't
most recently written.""" [cppreference.com]
So, in the spirit of copy_from/to_sockptr, the is_null function should read
{
return sockptr.is_kernel ? !sockptr.user : !sockptr.kernel;
}
Powered by blists - more mailing lists