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: border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!news.mixmin.net!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 09:19:05 +0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: Reply-To: nntp@thorzten.de NNTP-Posting-Host: 2Re8NKytgV911fAPUMdAmQ.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: number.nntp.giganews.com comp.lang.ada:193208 Date: 2015-05-18T09:19:05+00:00 List-Id: Hi, thanks a lot for the fast reply. In comp.lang.ada, you wrote: > On 15-05-18 11:27 , q.kontinuum wrote: > Do you mean a real "driver", either kernel-linked or a loadable module? Yes, I'm aiming for a loadable kernel module. > 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 ... > But GNAT can also translate some C headers into Ada > declarations automatically. I should look into that. Good to know. > 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. Since I know that only one instance of the driver will be used single threaded, and only one buffer is used, I could declare it in the modules declaration section rather than the function. > what you should use. Perhaps you can wrap it up as a user-defined Ada > "storage pool" (see the Ada RM 13.11) which would let you use the "new" > statement This sounds like just what I need - I will definitely have a closer look at it, thanks a bunch! > or you can write an Ada binding in the same way as for your C > wrappers. kmalloc seems to return a C "void *". Assuming that this is > implemented as an address, you should be able to use the predefined Ada > package System.Address_To_Access_Conversions to convert the kmalloc > result to a pointer of any type you want (but beware memory alignment > errors -- the documentation for kmalloc that I found did not promise to > return memory aligned in any particular way). Thanks, sounds like a good starting point to gather some further information myself.