The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: Bakul Shah <bakul@bitblocks.com>
To: TUHS <tuhs@minnie.tuhs.org>
Subject: Re: [TUHS] C++ / Kernel
Date: Thu, 23 Aug 2018 13:21:39 -0700	[thread overview]
Message-ID: <ACE5F352-8FCF-4C3C-B60B-7CD1C6094939@bitblocks.com> (raw)
In-Reply-To: <10c401d43aef$8be34870$a3a9d950$@ronnatalie.com>

On Aug 23, 2018, at 7:42 AM, ron@ronnatalie.com wrote:
> 
> The biggest issue we had was BSD didn't use void* at all.   Had they
> converted pointers to void*, which is in implementation necessarily the same
> as char*,
> C would have done the right thing.   The problem is they did what I call
> "Conversion by union."    They would store a char* into one element of a
> union and read it out of another typed pointer.

I haven't done much BSD kernel programming in last 15 years
but this is not my recollection. BSD used caddr_t, typedefed
to char*, sort of as void *. IIRC void* came in common use
after BSD unix first came about. Why use a union when a cast
will do? :-) The union trick is more likely to be used for
esoteric things (like getting at fl.pt. bytes) or for more
complex types or probably by people with lots of programming
experience in pascal and not so much in C (in Pascal you *had*
to use untagged variant records if you wanted to cheat!). In C,
all that void* does is allow you to avoid casts in some cases.

> This works fine for a VAX where all pointers are the same format, but fails
> on word address machines (notably in our case the HEP where the target size
> is encoded in the low order bits of the pointer).
> Still, running around and fixing those was only a few hours work.
> 
> The DevSwitch is the beginnings of an object oriented philosophy.   Alas,
> the original UNIX used it only for mapping major dev numbers to functions.
> It got some later use for other things like multi filesystemsupport.

{b,c}devsw are closer to an interface (or in C++ terminology 
an abstract class that contains nothing but pure virtual
functions). Go got it right.  I had to build something like
devsw for some IOT devices in Go and it worked very well. And
you don't need to manually stuff relevant functions in a
struct so that {bdev,cdev,line}sw can be properly initialized
as in C.
 
Not having this feature in C meant dev switches got a bit 
impure (in 4.xBSD there was only a buf ptr for bdevsw and a
tty ptr in cdesw).  In modern BSD the cdev struct contains all
sorts of cruft.
 
So in this sense C++ got it wrong, at least initially. Code 
for each disk or network device would be device specific but
in so far as possible we want to access devices of a specific
class the same way. Classical OO would not help here.

[Aside: What I would really like is if Go interfaces can be
somehow turned into abstract data types by adding an algebraic
specification. For example, at the source level you should
be able to say don't allow read/write once  device is closed.
Adding this sort of assertions/axioms at the interface level
can make your code less cluttered (no need to check at every
point if the device is still open) and safer (in case you forget
to check).]


> The scary supportability thing in the kernel, isn't so much typing, but the
> failuer to "hide" implementation details of one part of the kernel from the
> other.

Lack of modularity or more fine grained trust boundaries.
Apropos this point:

https://threatpost.com/researchers-blame-monolithic-linux-code-base-for-critical-vulnerabilities/136785/

  In an exhaustive study of critical Linux vulnerabilities, a 
  team of academic and government-backed researchers claim to
  have proven that almost all flaws could be mitigated to less
  than critical severity - and that 40 percent could be
  completely eliminated - with an OS design based on a
  verified microkernel. Though I tend to think the "verified"
  part doesn't play as strong a role as the modularization
  forced by microkernels.

[Ties in with the formal methods thread in here and in COFF!]




  parent reply	other threads:[~2018-08-23 20:22 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-23 14:42 ron
2018-08-23 17:24 ` Clem Cole
2018-08-23 20:21 ` Bakul Shah [this message]
2018-08-23 22:17   ` ron
2018-08-23 22:28     ` Nevin Liber
2018-08-23 22:48       ` Clem Cole
2018-08-23 23:14     ` Steffen Nurpmeso
2018-08-24 14:13       ` Steffen Nurpmeso
2018-08-24 14:32         ` ron
2018-08-24 18:15           ` Steffen Nurpmeso
2018-08-26 16:34             ` Paul Winalski
2018-08-27 16:31               ` Steffen Nurpmeso
2018-08-24  1:41     ` Bakul Shah
2018-08-24 10:41       ` Pete Turnbull
2018-08-24 12:17       ` ron
2018-08-24 18:36         ` Bakul Shah
2018-08-24 18:38           ` ron
2018-08-24  1:58     ` Dan Cross
2018-08-24  3:04       ` Clem cole
2018-08-24 14:01         ` Dan Cross
2018-08-24 13:22 ` Derek Fawcus
2018-08-24 16:59   ` Steffen Nurpmeso
2018-08-23 23:29 Noel Chiappa
2018-08-23 23:42 ` ron
2018-08-24  0:30   ` Clem Cole
2018-08-24  2:05     ` Bakul Shah
2018-08-24 12:21     ` ron
2018-08-24  1:27 Noel Chiappa
2018-08-24  2:52 ` Clem cole
2018-08-24  7:30 Paul Ruizendaal

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=ACE5F352-8FCF-4C3C-B60B-7CD1C6094939@bitblocks.com \
    --to=bakul@bitblocks.com \
    --cc=tuhs@minnie.tuhs.org \
    /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;
as well as URLs for NNTP newsgroup(s).