From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.unit0.net!news.uni-stuttgart.de!news.enyo.de!.POSTED!not-for-mail From: Florian Weimer Newsgroups: comp.lang.ada Subject: Re: Kernel Syscall from Ada? Date: Sat, 25 Jun 2016 00:23:39 +0200 Message-ID: <87vb0y5iqc.fsf@mid.deneb.enyo.de> References: <2048d6d6-04e2-4e2c-9483-e3769da59781@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain X-Trace: news.enyo.de 1466807019 11414 192.168.18.20 (24 Jun 2016 22:23:39 GMT) X-Complaints-To: news@enyo.de Cancel-Lock: sha1:AfkBi9Eg9+sHm/LP3ktCJ3txqbM= Xref: news.eternal-september.org comp.lang.ada:30902 Date: 2016-06-25T00:23:39+02:00 List-Id: * Diogenes: > Is there a simple way to make a direct (Linux)Kernel syscall from Ada > without using the system C library? i.e. Make a direct call as in > Assembler? glibc implements a lot of system calls as assembler stubs. Some are more complicated because emulation of certain features is desirable, or there is no straight mapping between the application and kernel parameter lists (e.g., the offset parameter to mmap). Calling individual system calls in GNAT using machine code insertion is not that hard (except for 6-argument system calls on i386 with older GCC versions). But designing a way to write such system calls so that you do not have to tweak the sources for each architecture is quite hard. The lax C type system allows you to treat all system calls as taking signed long arguments, returning signed long (*), and you only have to specialize the number of arguments. With the C preprocessor, you can also deal with 64-bit arguments in a portable manner (so that the source code denoting the system call is identical across 32-bit and 64-bit architectures). I doubt something similar is possible in GNAT. You also need to replicate all data types used in the userspace API, which can be rather involved (stat is a bit complicated, and there are many ioctls). (*) Some architectures do not use in-band signaling for errno, and the return convention is different.