Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ada implementation of an X Window System Server (1989) (sci-hub.se)
108 points by kickitover on Nov 2, 2021 | hide | past | favorite | 38 comments


This server appears to have been closed source, and I assume the source is lost.

My bet is that OpenBSD's X server has a far better security design, as the server itself no longer runs as root. The aggressive free() also exposed use-after-free bugs never before seen, and OpenBSD has superior mitigations for rop gadget abuse, aslr everywhere, and other exploits beyond the imagination of 1989.

The paper documents problems of Ada, particularly in linking to C (where the use of void * pointer casts was particularly difficult for Ada's type system), and that the Ada implementation had nearly double the lines of code as the C reference.

In the days of 1989, the fastest CPUs were under 100MHz. It is unlikely that any of this code could be salvaged for a modern server, but the accomplishment is interesting.


>the Ada implementation had nearly double the lines of code as the C reference

I'll point out to others in the audience: this is largely an artifact of Ada syntax being more verbose, and Ada programming practice favouring longer and more explanatory identifiers compared to C (where a lot of code looks like line noise). For example, see this post and compare the size of the C code vs. the equivalent Ada code:

https://borretti.me/article/signed-integers-asymmetrical


A lot of the Ada limitations pointed out in the paper were fixed in Ada95.


> A lot of the Ada limitations pointed out in the paper were fixed in Ada95.

I was going to say that as well. I only more recently hopped on the train, but I didn't see anything which would be problematic for Ada 2012. I've had no problems in my projects doing bit manipulation, using function pointers, dynamic dispatch, or interfacing with C code which uses `void*`.

> this is largely an artifact of Ada syntax being more verbose

There's a very negative connotation of "verbose" like it's the worst thing in the world. The better way of describing this is the language is explicit and focuses on describing intent. This means it doesn't take long to learn to read and understand standard library code or code from other projects.


>There's a very negative connotation of "verbose" like it's the worst thing in the world. The better way of describing this is the language is explicit and focuses on describing intent. This means it doesn't take long to learn to read and understand standard library code or code from other projects.

I agree that it's good. But it's objectively longer, which is what I meant.


Source code is there for people; the question becomes, does it become more understandable?


> this is largely an artifact of Ada syntax being more verbose

If you think Ada is actually verbose check out the Ada++ comparisons with other major languages like C++ and Java.

http://www.adapplang.com/tutorial.html


Stop posting an April Fool’s joke as if it were serious, please.


Just had a look at the linked page out of piqued curiosity. The "get started" link on the homepage points to a GitHub release page (https://github.com/AdaPlusPlus/gcc/releases/tag/0-2-0) with a 908MB "adapp-for-linux.gz".

I'm presuming this is real (908MB would take a tad too long to download today), but if it isn't, that's definitely up there in terms of execution. I completely believe it.

Edit: Oh.


It's a very well-executed April Fool's Joke in that regard. But it's still a joke. And 0xDEEPFAC is apparently very committed to the idea that it's a real thing and not a joke. Just look at the commit dates if you have any doubt (and the fact that there haven't been any since then).


The Windows binary works, but the Linux one was rushed out. Sorry : /


its a working compiler, so why not?


It’s a glorified sed script with a forked version of GCC from April 1st. It’s a joke.


It is not? As the creator I can tell you that the parser and analyzer of GCC/GNAT were modified.

For example, supporting implicit "use" clauses for packages was a difficult problem to solve - not to mention allowing for abbreviated type names in the Standard package.


The thing about this would be that it likely still compile with zero changes, if the source were available.

The code could easily be converted to later Ada versions and use C.Pointers where necessary (triple pointers), but void * are easy enough to handle now with an access to null record with convention => C.


The X server on a modern Linux system hasn't run as root since around 2013 or so.


Unfortunately, that didn't make it into CentOS 7.

    # cat /etc/redhat-release; ps aux | grep X\ :0 | grep -v grep
    Red Hat Enterprise Linux Server release 7.9 (Maipo)
    root      2114  0.0  0.1 380804 33900 tty1     Ssl+ Aug03   0:51 /usr/bin/X :0 -background none
CentOS 8 does appear to run without root. Maybe someday I can use it in production.

    # cat /etc/redhat-release; ps aux | grep Xorg | grep -v grep
    Red Hat Enterprise Linux release 8.4 (Ootpa)
    gdm         1967  0.0  0.0 1586600 21436 tty1    Sl+  Jan13   2:38 /usr/libexec/Xorg vt1
I was not aware that this had happened.


> The aggressive free() also exposed use-after-free bugs never before seen

What do you mean by that? Is there an overview somewhere about "aggressive free()" that I can read?



Thanks for the links.


I'll look it up for you a little later.

OpenBSD altered malloc/free to use mmap instead of sbrk.

This allowed free to remove larger allocations from the address space, which caught a lot of programs that were using memory after free.


Yeah old academic papers never published their source. Maybe it's stored somewhere at the originating university's library, but I doubt it...


> This server appears to have been closed source, and I assume the source is lost.

The author is @Java4First on Twitter. Give it a shot.


It's interesting how the X11 server is the only major category of infrastructure where we have one and only one open source implementation.

With browsers -- which are massively complex nowadays -- at least we have both WebKit and Gecko.

C++ compilers are at a similar level of complexity and there is GCC and Clang.

Linux, FreeBSD, OpenBSD etc. are all separate kernels.

But for X11 there is only the the X.Org server, the reference implementation. How much work would it be to implement a practical X11 server in a safe language like Ada or Rust, which supports the widely-used extensions?


> With browsers -- which are massively complex nowadays -- at least we have both WebKit and Gecko.

Isn't that a bit of a historical accident? Almost all alternative browsers are now based on Chromium, and if Firefox dies or drops Gecko, I doubt anyone would go through the trouble to create a new one. I mean Microsoft tried and gave up on it, and they're one of the few organizations with the resources to actually succeed.


http://www.jcraft.com/weirdx/ - Pure Java X Window System Server under GPL

They also had closed version http://www.jcraft.com/wiredx/ that supports antialiasing for core protocol (something X.org/XFree86 claimed to be impossible)


I assume there's only one implementation because for decades people have been saying that X is an antiquated design, and they want a different way. Thus we got Wayland.


There are quite a few open-source X11 implementations, but they are either much more basic, or targeting historical platforms.


The KDrive X11 server was separate to the original one even though it was bundled with the rest of the X.Org software.


What was the provenance of/motivation behind (writing) KDrive? I always wondered.


From memory, it was that Keith Packard felt that the bits of the original server that run on the CPU (mfb, cfb) were optimized for CPUs without caches, they unroll the various bit operations and generate C functions for each one which increases code size.

One of the first targets for KDrive was the Compaq iPaq with a StrongARM CPU and no GPU.

I think the ideas behind KDrive have now been folded into the main X.Org server.


Once upon a time there was XFree86.


That is just an earlier distribution of the same server.


I posted this earlier about John Steinhart's XTool (here it is with updated links):

https://news.ycombinator.com/item?id=17056516

Hasn't somebody reimplemented X11 in JavaScript/canvas/websockets yet?

There was an X11 server for Lisp Machines! Not sure who wrote it, but it was probably written inside or at least nearby the X Consortium, and I remember Robert Scheifler used it regularly.

https://news.ycombinator.com/item?id=6864364

"For example the TI Explorer Lisp Machine came with an X11 server written in Lisp. On my Symbolics Lisp Machine I used the usual MIT X11 server written in C - this was possible because the Symbolics Lisp machine had a C compiler." -lispm

John Steinhart wrote XTool, a nice snappy reimplementation of X11 on top of SunView! ;)

https://web.archive.org/web/20171105150953/https://minnie.tu...

https://news.ycombinator.com/item?id=15325226

>XTool was very small and fast compared to the X sample server because I wrote the server from scratch. I think that I'm the only person to write an X server outside of the X Consortium. One of the things that I learned by doing it was that the X Consortium folks were wrong when they said that the documentation was the standard, not the sample server. There were significant differences between the two.

>The only really worthwhile thing about X was the distributed extension registration mechanism. All of the input, graphics and other crap should be moved to extension #1. That way, it won't be mandatory in conforming implementations once that stuff was obsolete. As you probably know, that's where we are today; nobody uses that stuff but it's like the corner of an Intel chip that implements the original instruction set. As an aside, I upset many when working on OpenDoc for Apple and saying the same thing there.

>The atom/property mechanism allows clients to allocate memory in the server that can never be freed. Some way to free memory needs to be added.

>The bit encodings should be part of a separate language binding, not part of the functional description.

>Had he done some real design work and looked at what others were doing he might have realized that at its core, X was a distributed database system in which operations on some of the databases have visual side-effects. I forget the exact number, but X includes around 20 different databases: atoms, properties, contexts, selections, keymaps, etc. each with their own set of API calls. As a result, the X API is wide and shallow like the Mac, and full of interesting race conditions to boot. The whole thing could have been done with less than a dozen API calls.


The TI Explorer X11 server looks to have been written from scratch.


In Ada you write

    type Score = 0 .. 192   -- enough for a game of American football
instead of choosing to use a signed or unsigned byte, short, triplebyte, etc..

The compiler figures out what kind of number to use. That article points out that bit twiddling and other operations you want to do in embedded systems is awkward in Ada because Ada hides the binary nature of math in ordinary computers.

It's strange because, by 1980 when Ada was released, 8-bit bytes had won conclusively. The last straggler, Digital's 36-bit PDP-10 was discontinued in 1983.


Ada had to target lots of (relatively) bespoke systems, especially DOD systems. Even in 1980, while new systems had 8-bit bytes, that wasn't guaranteed on the existing systems where JOVIAL and other languages Ada was meant to replace were used.

For the bit twiddling stuff, it does work with the modular types, at least now. I have no clue when it was added.


Oh gosh I remember having to code for 36 bit systems. Wow that brings back memeories.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: