mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Satyam Sharma <satyam@infradead.org>
To: David Brownell <david-b@pacbell.net>
Cc: Anton Altaparmakov <aia21@cam.ac.uk>,
	Al Viro <viro@ftp.linux.org.uk>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ptrdiff_t is not uintptr_t, damnit
Date: Mon, 20 Aug 2007 08:31:47 +0530 (IST)	[thread overview]
Message-ID: <alpine.LFD.0.999.0708200806380.2774@enigma.security.iitk.ac.in> (raw)
In-Reply-To: <200708191757.56520.david-b@pacbell.net>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: TEXT/PLAIN; charset=us-ascii, Size: 2062 bytes --]



On Sun, 19 Aug 2007, David Brownell wrote:

> On Sunday 19 August 2007, Anton Altaparmakov wrote:
> > >
> > > ISTR we don't *have* a uintptr_t on all architectures, or that would
> > > be the appropriate thing to use in these 32/64 bit ABI scenarios.
> > >
> > >
> > >> Use unsigned long or uintptr_t instead.
> > >
> > > I suspect you mean "unsigned long long"...
> > 
> > No he doesn't.  "unsigned long" is guaranteed to be large enough to  
> > hold a pointer (at least on Linux anyway).

Yup, sizeof(long) >= sizeof(void *) should always be true in Linux C.
I bet a lot of code out there depends on this.

BTW, just curious to know, but which (if any) are the platforms that have
sizeof(long) > sizeof(void *)? [i.e. greater-than but not equal?]

The reason I ask is that gcc will also complain (understandably so) with
"warning: cast from pointer to integer of different size" i.e. even if
it's a conversion from smaller size to greater size, and not really a
case of truncation. Therefore, I wonder if the stricter assertion:
sizeof(long) == sizeof(void *) holds true for Linux C, actually.


> And yet when I used that, I got compiler warnings on some systems.
> 
> ISTR that was the first solution I tried, but GCC really wanted to
> issue warnings.  Either about casting 64-bit to pointer, or about
> casting it to "unsigned long", either way lost precision.

Hmm, if you could fish out those testcases ...


> > On a 32-bit arch "unsigned long" is 32-bit and pointers are 32-bit.
> > 
> > On a 64-bit archi "unsigned long" is 64-bit and pointers are 64-bit.
> 
> So with 32 bit userspace "unsigned long long" is the type to use
> when talking to a 64-bit kernel; and with pure 64-bit code, it's
> enough to write "unsigned long".
> 
> I'm fairly sure that's the root cause of the pain I recall here;
> but I'd have to run experiments again to verify that.  

I suspect the root cause of the pain was that you used "int" or "long"
to talk between kernel and userspace in the first place. You shouldn't,
we have __u32 / __u64 / etc for that.


Satyam

  reply	other threads:[~2007-08-20  2:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-19 22:55 Al Viro
2007-08-20  0:19 ` David Brownell
2007-08-20  0:29   ` Anton Altaparmakov
2007-08-20  0:57     ` Al Viro
2007-08-20  0:57     ` David Brownell
2007-08-20  3:01       ` Satyam Sharma [this message]
2007-08-20  3:26         ` David Brownell
2007-08-20  3:40           ` Al Viro
2007-08-20  4:17             ` David Brownell
2007-08-20  0:27 ` Anton Altaparmakov
2007-08-20  0:52   ` Al Viro
2007-08-20  1:12     ` David Brownell
2007-08-21 18:53 ` David Brownell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.0.999.0708200806380.2774@enigma.security.iitk.ac.in \
    --to=satyam@infradead.org \
    --cc=aia21@cam.ac.uk \
    --cc=david-b@pacbell.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@ftp.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®