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=-0.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no 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!aioe.org!.POSTED!not-for-mail From: "q.kontinuum" Newsgroups: comp.lang.ada Subject: Re: Linux kernel module - memory allocation Date: Mon, 18 May 2015 19:35:23 +0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: Reply-To: nntp@thorzten.de NNTP-Posting-Host: 35IKgXl2aoGTS/cf41LhKA.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org User-Agent: slrn/1.0.1 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:25909 Date: 2015-05-18T19:35:23+00:00 List-Id: On 2015-05-18, Niklas Holsti wrote: > On 15-05-18 12:19 , q.kontinuum wrote: >> Yes, I'm aiming for a loadable kernel module. > > Ok. I don't think many people have tried this with GNAT or Ada -- I > don't know of any others. Do you know anyone who has done it? Not really. I found some initial information, although it looked quite outdated: http://www.pegasoft.ca/resources/boblap/16.html (latest update 2009) > I you haven't already done so, you should find out what "elaboration" > means in Ada (= initializations before the main subprogram starts), and > either ensure that your driver somehow does it, although it has no main > subprogram -- perhaps some part of the driver should call "adainit" > explicitly -- or perhaps by ensuring that your Ada code needs no > elaboration. Look into the pragmas Preelaborate and No_Elaboration_Code > (the latter is GNAT-specific). That's why I use the C-wrapper. The wrapper implements int init_module(void) and void cleanup_module(void) which calls the correspondent function/procedure in the Ada module. I found two ways to do this, one is to re-implement the behaviour of the kernel MODULE_LICENSE macro, the other is to write a C-wrapper using this macro and calling the Ada-entry points from there. The second approach seemed to be the easier one. BTW: My current attempts are on github: https://github.com/thors/ada > The Gnat User Guide section > http://docs.adacore.com/gnat_ugn-docs/html/gnat_ugn/gnat_ugn/building_executable_programs_with_gnat.html#binding-with-non-ada-main-programs > may be useful. Thanks, I will have a look. >>> Which Ada compiler are you using? Do you use some specific compiler >>> switches to adapt it to the driver environment? >> >> I'm using gnat. Command line to compile a >> gnatmake -a -s -mcmodel=kernel ... > > I couldn't find any AdaCore documentation about -mcmodel=kernel with > GNAT. Hmm... GNAT is gcc-based. -mcmodel=kernel is required by gcc to generate code for kernel-space. https://gcc.gnu.org/onlinedocs/gcc-4.5.3/gcc/i386-and-x86_002d64-Options.html >>> You could try with a constrained string subtype, say String(1 .. 10), >> >> I assume if I use that within a function, I'd run into the same problem >> because the function might be called more often, thus still requiring >> dynamic allocation. > > I don't follow. if you say > > subtype String10 is String(1 .. 10); > > then every object of type String10 has a static size. Local variables of > that type will be allocated on the (primary, standard) stack, but that > does not count as dynamic allocation. Ok, I still have a lot to learn how the different ways of allocation work in Ada... Br, Thorsten