Ada System Calls: Genesis

November 19th, 2018

One library that I wanted to implement was an interface to Linux system calls. GNAT hides this functionality behind layers-upon-layers of abstractions, so you can't really get access to raw system calls. Additionally, all interfacing with the OS in GNAT is done via C, which is very unreliable foundation compared to Ada. My plan was to start small with the most basic syscalls: openat, close, mmap, and fstat. These should allow users to create files on file system, and read and write memory mapped files.

How is this different from what ave1 is doing? The scope of the library that I have in mind is a bit different. It is supposed to be used independent of runtime to provide functionality that happens to be missing from Ada standard and its GNAT extensions.

Unfortunately, I did not have enough time to polish it before publishing, so instead I will provide you some information on what work I will do in the future, and what I have done already.

What still needs to be done:

  • Ada packages with system call codes, special values for return codes, flags. Can be done in one evening.
  • Structure definition for struct stat. I expect that this work will take ~weekend, and after this is done, all other structures should take much less time.
  • System call instruction wrappers. I have finished working on this part on x86_64, however it is still not in the state where it is ready for review.
  • Implement same functionality for aarch64.
  • Make a general cleanup (typo checks, comments where they are required, etc.).
  • Why is it still not publishable, and why did such a trivial thing take so much time? I don't particularly like approach of adding an Machine_Code'Asm snippets into every system call wrapper function, so it took some time to make it generic1: I have functions that stuff each of the system call arguments into register-sized type2 in the correct way before passing them to the system call instruction. I have also ensured that these functions inline into single moves in the assembly. These experiments have eaten up most of my time, so I have no choice now but to make an empty genesis. I expect that further work, when I get back to it, will progress much faster.

    curl 'http://bvt-trace.net/vpatches/syscalls_genesis.vpatch' > syscalls_genesis.vpatch
    curl 'http://bvt-trace.net/vpatches/syscalls_genesis.vpatch.bvt.sig' > syscalls_genesis.vpatch.bvt.sig
    curl 'http://wot.deedbot.org/6CF3EFF892A7F23E7E798E5EBA6B8C054B962B68.asc' > bvt.asc
    
    1. Not in Ada sense. I did try using Ada generics, and what I got as a result worked, but it was such an ugly abomination that I declared this approach dead. More on this topic coming in later vpatch. []
    2. In C -- unsigned long. []

    Leave a Reply