comp.lang.ada
 help / color / mirror / Atom feed
From: Lutz Donnerhacke <lutz@iks-jena.de>
Subject: Re: [Spark] Arrays of Strings
Date: Wed, 9 Apr 2003 09:23:50 +0000 (UTC)
Date: 2003-04-09T09:23:50+00:00	[thread overview]
Message-ID: <slrnb97pl4.or.lutz@taranis.iks-jena.de> (raw)
In-Reply-To: pan.2003.04.08.18.08.55.205947@T-Online.de

* Martin Krischik wrote:
> On Tue, 08 Apr 2003 12:02:09 +0000, Lutz Donnerhacke wrote:
>> In order to implement thin an execve binding, I wonder how to emulate the
>> C-Type "char const * const x []". Any bright ideas?
>
> Depends if you need a 1 to 1 emulation or you want a more high level OO
> aproach.

The emulation should be native Spark and to be used in an inlined syscall.
The syscall interface is so thin, that the inlined code prepare the
registers and switch directly to the kernel.

Example:
pragma No_Run_Time;

with Kernel.Processes, Kernel.IO, Kernel.Linux_i86, Addon;
use type Kernel.IO.long;
--# inherit Kernel, Kernel.Processes, Kernel.IO;

--# main_program;
procedure test_kernel
  --# global in out Kernel.State;
  --# derives Kernel.State from Kernel.State;
  is
   pragma Suppress(All_Checks);

   subtype Buffer_Index is Positive range 1 .. 10;
   subtype Buffer is String(Buffer_Index);
   outbuf : Buffer;
   outlast : Natural;
   outwritten : Natural;
   exitcode : Kernel.Processes.exit_code_t;
   
   child : Kernel.Processes.child_data_t;
   res : Kernel.Linux_i86.syscall_result;
begin
   Kernel.Processes.fork(child, res);
   if res.ok then
      if child.child then
	 outbuf := Buffer'(
	   1 => 'C', 2 => 'h', 3 => 'i', 4 => 'l', 5 => 'd',
	   others => ' ');
	 outlast := 5;
      else
	 outbuf := Buffer'(
	   1 => 'M', 2 => 'a', 3 => 's', 4 => 't', 5 => 'e', 6 => 'r',
	   others => ' ');
	 outlast := 6;
      end if;
   else
      outbuf := Buffer'(
	1 => 'E', 2 => 'r', 3 => 'r', 4 => 'o', 5 => 'r',
	others => ' ');
      outlast := 5;
   end if;
   
   outlast := outlast + 1;
   outbuf(outlast) := ASCII.LF;

   Kernel.IO.write(Kernel.IO.stdout, outbuf, outlast, outwritten, res);
   if not res.ok or else outwritten /= outlast then
      exitcode := 1;
   else
      exitcode := 0;
   end if;
   
   Kernel.Processes.sysexit(exitcode);
end test_kernel;

00000000 <_ada_test_kernel>:
   0:	55                   	push   %ebp
   1:	b8 02 00 00 00       	mov    $0x2,%eax    <= the fork call.
   6:	57                   	push   %edi
   7:	56                   	push   %esi
   8:	53                   	push   %ebx
   9:	83 ec 54             	sub    $0x54,%esp
   c:	cd 80                	int    $0x80        <= the fork call.
   e:	31 db                	xor    %ebx,%ebx
  10:	89 c1                	mov    %eax,%ecx    <= return code for fork
  12:	83 c0 7c             	add    $0x7c,%eax
  15:	89 4c 24 28          	mov    %ecx,0x28(%esp,1)
  19:	83 f8 7b             	cmp    $0x7b,%eax
  1c:	89 d0                	mov    %edx,%eax
  1e:	0f 96 c3             	setbe  %bl          <= set the error bit
  21:	31 f6                	xor    %esi,%esi    <= the if construct
  23:	30 c0                	xor    %al,%al
  25:	89 c2                	mov    %eax,%edx
  27:	09 da                	or     %ebx,%edx
  29:	31 db                	xor    %ebx,%ebx
  2b:	89 54 24 24          	mov    %edx,0x24(%esp,1)
  2f:	84 d2                	test   %dl,%dl
  31:	74 10                	je     43 <_ada_test_kernel+0x43>
 ...



  reply	other threads:[~2003-04-09  9:23 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-08 12:02 [Spark] Arrays of Strings Lutz Donnerhacke
2003-04-08 18:08 ` Martin Krischik
2003-04-09  9:23   ` Lutz Donnerhacke [this message]
2003-04-09 12:38     ` Hyman Rosen
2003-04-09 12:47       ` Vinzent Hoefler
2003-04-09 14:27         ` Hyman Rosen
2003-04-09 15:13           ` Vinzent Hoefler
2003-04-09 17:21         ` Hyman Rosen
2003-04-09 18:41           ` Vinzent Hoefler
2003-04-09 21:04           ` Randy Brukardt
2003-04-10 23:21           ` John R. Strohm
2003-04-11 12:19             ` Hyman Rosen
2003-04-11 13:14               ` John R. Strohm
2003-04-09  7:50 ` Eric G. Miller
2003-04-09  8:10   ` Lutz Donnerhacke
2003-04-09 18:23   ` Matthew Heaney
2003-04-09 17:42 ` Matthew Heaney
2003-04-09 21:06   ` Randy Brukardt
2003-04-10  8:23   ` Lutz Donnerhacke
2003-04-10 14:09     ` Matthew Heaney
2003-04-10 14:48       ` Hyman Rosen
2003-04-11  6:20         ` Chad R. Meiners
2003-04-11 12:31           ` Hyman Rosen
2003-04-11 18:27             ` Chad R. Meiners
2003-04-11  7:35         ` Phil Thornley
2003-04-11 12:05           ` Marin David Condic
2003-04-11 13:19             ` John R. Strohm
2003-04-12 23:09               ` Robert A Duff
2003-04-11 18:47             ` Chad R. Meiners
2003-04-12 23:51         ` Robert A Duff
2003-04-13  5:47           ` Hyman Rosen
2003-04-14  8:05             ` Lutz Donnerhacke
2003-04-10 15:02       ` Lutz Donnerhacke
2003-04-10 15:50         ` Hyman Rosen
2003-04-10 18:32           ` Randy Brukardt
2003-04-11  6:28         ` Chad R. Meiners
2003-04-11  8:11           ` Lutz Donnerhacke
2003-04-11 12:32 ` Rod Chapman
2003-04-11 14:50   ` Peter Amey
2003-04-11 18:41   ` Matthew Heaney
2003-04-11 21:25     ` Chad R. Meiners
2003-04-12 10:08     ` Peter Amey
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox