Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #26851

Re: How to name a function to indicate that they require calling from a critical section?

From Stephen Sprunk <stephen@sprunk.org>
Newsgroups comp.lang.c
Subject Re: How to name a function to indicate that they require calling from a critical section?
Date 2012-09-30 00:17 -0500
Organization A noiseless patient Spider
Message-ID <k48klm$fq$1@dont-email.me> (permalink)
References (1 earlier) <GhVUr.1067102$3s1.72445@fx12.am4> <lnr4rfvl3q.fsf@nuthaus.mib.org> <kfnk3w5kfne.fsf@x-alumni2.alumni.caltech.edu> <k2dnbm$rab$1@dont-email.me> <kfna9x1fg5r.fsf@x-alumni2.alumni.caltech.edu>

Show all headers | View raw


On 07-Sep-12 20:37, Tim Rentsch wrote:
> Stephen Sprunk <stephen@sprunk.org> writes:
>> On 07-Sep-12 10:37, Tim Rentsch wrote:
>>> Keith Thompson <kst-u@mib.org> writes:
>>>> (The kernel is arguably part of the implementation, and even if
>>>> it isn't, it's probably ok for the developers to rely on
>>>> certain behaviors that aren't defined by the language
>>>> standard.)
>>> 
>>> The Linux kernel is part of no existing C implementation.
>> 
>> The _running_ kernel is arguably part of the implementation;
> 
> You mean it's arguably part of _an_ implementation.  I will take up
> this question further on.

I was assuming the context of compiling the Linux kernel on a running
Linux system.  Obviously, if you're compiling the Linux kernel with a
cross-compiler running on some other OS, then the Linux kernel would not
be part of the implementation.

My point was that it's not the kernel source that was being claimed to
be part of the implementation.

>> the kernel _source being compiled_ is not.
>> 
>>> And, even if it were, it is not part of implementations running
>>> on other operating systems (eg MS windows or MacOS), yet
>>> presumably it's expected to be compileable some such
>>> environments, so it's still breaking the rules regarding reserved
>>> identifiers.
>> 
>> The Linux kernel is only expected to be compilable by GCC,
> 
> Doesn't change my point, since GCC runs on systems besides Linux.

True, except that it undercuts the justification for your point.  If the
Linux kernel is only expected to be compilable by GCC, then it is free
to take advantage of GCC's implementation-defined behavior--and that is
exactly what started this discussion.

>> and successfully compiling the Linux kernel is a gate in the GCC
>> release process, so the two are intimately tied together.
> 
> That doesn't make Linux part of a gcc implementation, any more than a
> requirement for a successful compilation of 'rogue' would make
> 'rogue' part of gcc implementations.
> 
>> I would expect the same of Windows and MSVC, etc.  Kernels are 
>> special.
> 
> Kernels generally are more dependent on their compilation environment
> than other programs.  From a compiler's point of view though they are
> still just programs.

That depends.  When GCC has flags (eg. -cmodel=kernel) to tell the
compiler to use a special mode only for kernels, that seems to imply
kernels are not "just programs."

Also, a few years ago GCC added an optimization that _only_ broke
kernels: it removed null pointer checks after a pointer had been
dereferenced on the assumption that if the pointer had been null,
execution could not have continued.  That assumption does not hold in
kernel mode, though, which resulted in a security vulnerability in the
Linux kernel.  Kernels _are_ different in practice, not just theory.

>>> Don't get me wrong, it's no big deal that these particular rules
>>> are being broken in this case, but that doesn't mean the rules
>>> aren't being broken.
>> 
>> In such a case, the normal rules are simply not relevant.
> 
> The rules are relevant precisely because the kernel must ensure that
> the rules it chooses to violate won't be messed up by any
> implementation-reserved decisions made by the compiler in question.

... unless the implementation has made an explicit statement that it
will not violate any assumptions the kernel makes, as in the case of GCC
with respect to the Linux kernel.  (Including, for instance, the
assumption that dereferencing a null pointer has well-defined behavior.)

Note that this does _not_ apply to other kernels that may be compiled
with GCC, in which case your point would be valid.

> If the kernel didn't break any rules, then it wouldn't matter which
> compiler is used to compile it;  it's because the kernel _does_
> break rules that it needs to be choosy about which compilers it uses.

True, but nobody seems to care about that.

Well, Intel seems to have cared, to the point that being able to compile
the Linux kernel was considered a "must have" for ICC to be viable in
the Linux market.  That wouldn't have been such a big deal if the kernel
didn't take advantage of--or dictate--GCC's peculiarities.

> What I think you mean is that, because the kernel is compiled with a
> compiler that doesn't exhibit destructive interference over the rules
> the kernel does break, breaking those rules does not have any
> negative effects;  and certainly that is true (by definition it would
> have to be).

I'm not sure what you mean here.

>> OTOH, that also means that one should always be careful before 
>> using kernel source as an example of how to write non-kernel 
>> source.
> 
> I agree with that, but I think that's more an artifact of expecting
> certain definitions of implementation-defined and 
> implementation-dependent behavior than it is of being a kernel. 
> Kernels are more prone to rely on those things than most programs;
> but so also are many or most programs that run on bare hardware, and
> certainly not all of those are kernels.

That leads to debating what we're really referring to by the term
"kernel", since I doubt we're really restricting it to just OS kernels
but rather any software that runs directly on the hardware without any
intermediary.

> My argument is that a running Linux kernel supplies an execution 
> environment (and perhaps also a translation environment), which under
> the descriptions in sections 1 and 5 is a data-processing system, and
> as such these /support/ conforming implementations but are not
> themselves /part of/ conforming implementations.

Fair enough.

S

-- 
Stephen Sprunk         "God does not play dice."  --Albert Einstein
CCIE #3723         "God is an inveterate gambler, and He throws the
K5SSS        dice at every possible opportunity." --Stephen Hawking

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to name a function to indicate that they require calling from a critical section? celephicus@gmail.com - 2012-08-08 18:55 -0700
  Re: How to name a function to indicate that they require calling from a critical section? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-09 08:31 -0400
  Re: How to name a function to indicate that they require calling from a critical section? "China Blue [Tor], Meersburg" <chine.bleu@yahoo.com> - 2012-08-09 12:24 -0700
    Re: How to name a function to indicate that they require calling from a critical section? Keith Thompson <kst-u@mib.org> - 2012-08-09 13:59 -0700
  Re: How to name a function to indicate that they require calling from a critical section? Andrew Cooper <amc96@cam.ac.uk> - 2012-08-09 21:43 +0100
    Re: How to name a function to indicate that they require calling from a critical section? Keith Thompson <kst-u@mib.org> - 2012-08-09 13:58 -0700
      Re: How to name a function to indicate that they require calling from a critical section? Andrew Cooper <amc96@cam.ac.uk> - 2012-08-09 23:11 +0100
        Re: How to name a function to indicate that they require calling from a critical section? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-09 18:22 -0400
      Re: How to name a function to indicate that they require calling from a critical section? Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 08:37 -0700
        Re: How to name a function to indicate that they require calling from a critical section? Stephen Sprunk <stephen@sprunk.org> - 2012-09-07 16:01 -0500
          Re: How to name a function to indicate that they require calling from a critical section? Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 18:37 -0700
            Re: How to name a function to indicate that they require calling from a critical section? Stephen Sprunk <stephen@sprunk.org> - 2012-09-30 00:17 -0500
              Re: How to name a function to indicate that they require calling from a critical section? Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-17 14:24 -0800
          Re: How to name a function to indicate that they require calling   from a critical section? Ian Collins <ian-news@hotmail.com> - 2012-09-08 13:56 +1200
            Re: How to name a function to indicate that they require calling   from a critical section? Stephen Sprunk <stephen@sprunk.org> - 2012-09-30 13:45 -0500

csiph-web