comp.lang.ada
 help / color / mirror / Atom feed
* Self-modifying code
@ 2015-07-12  1:57 ferrariv65
  2015-07-12  3:24 ` David Botton
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: ferrariv65 @ 2015-07-12  1:57 UTC (permalink / raw)


Is it possible to write self-modifying code in Ada?
More in detail: is it possible compile some code at runtime and inject it into the running program, on the fly? The ability to remove that code after it is no longer needed would also be important, to prevent hogging up the system memory which may result.
Thank you

Serg

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Self-modifying code
  2015-07-12  1:57 Self-modifying code ferrariv65
@ 2015-07-12  3:24 ` David Botton
  2015-07-12  4:38 ` Paul Rubin
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: David Botton @ 2015-07-12  3:24 UTC (permalink / raw)


> More in detail: is it possible compile some code at runtime and inject it into the running program, on the fly? The ability to remove that code after it is no longer needed would also be important, to prevent hogging up the system memory which may result.

Sure. Spawn the compiler to create a shared dynamic library and load it, then unload it when done from memory would be the cleanest way to do it in most cases, aka Plug-ins.

David Botton

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Self-modifying code
  2015-07-12  1:57 Self-modifying code ferrariv65
  2015-07-12  3:24 ` David Botton
@ 2015-07-12  4:38 ` Paul Rubin
  2015-07-12  5:09   ` David Botton
  2015-07-12 11:54 ` anon
  2015-07-27 11:29 ` Jacob Sparre Andersen
  3 siblings, 1 reply; 9+ messages in thread
From: Paul Rubin @ 2015-07-12  4:38 UTC (permalink / raw)


ferrariv65@gmail.com writes:
> Is it possible to write self-modifying code in Ada?
> More in detail: is it possible compile some code at runtime and inject
> it into the running program, on the fly?

You could generate a dynamically linkable module, but this all seems
pretty un-Ada.  What are you trying to do?  Hot upgrade?  JIT compiler
inside your application?  Maybe other approaches are worth looking into.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Self-modifying code
  2015-07-12  4:38 ` Paul Rubin
@ 2015-07-12  5:09   ` David Botton
  2015-07-12  5:53     ` Paul Rubin
  0 siblings, 1 reply; 9+ messages in thread
From: David Botton @ 2015-07-12  5:09 UTC (permalink / raw)


> You could generate a dynamically linkable module, but this all seems
> pretty un-Ada.

I'm not sure the idea is about any particular language. I can think of many ways to make it work, but all depend on the environment the code will run in not really the language.

David Botton

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Self-modifying code
  2015-07-12  5:09   ` David Botton
@ 2015-07-12  5:53     ` Paul Rubin
  2015-07-12  9:10       ` Georg Bauhaus
  0 siblings, 1 reply; 9+ messages in thread
From: Paul Rubin @ 2015-07-12  5:53 UTC (permalink / raw)


David Botton <david@botton.com> writes:
>> You could generate a dynamically linkable module, but this all seems
>> pretty un-Ada.
> I'm not sure the idea is about any particular language. I can think of
> many ways to make it work, but all depend on the environment the code
> will run in not really the language.

Yeah, it's similar at a technical level, but I think philosophically out
of sync with Ada, because of the additional moving parts.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Self-modifying code
  2015-07-12  5:53     ` Paul Rubin
@ 2015-07-12  9:10       ` Georg Bauhaus
  0 siblings, 0 replies; 9+ messages in thread
From: Georg Bauhaus @ 2015-07-12  9:10 UTC (permalink / raw)


On 12.07.15 07:53, Paul Rubin wrote:
> David Botton <david@botton.com> writes:
>>> You could generate a dynamically linkable module, but this all seems
>>> pretty un-Ada.
>> I'm not sure the idea is about any particular language. I can think of
>> many ways to make it work, but all depend on the environment the code
>> will run in not really the language.
>
> Yeah, it's similar at a technical level, but I think philosophically out
> of sync with Ada, because of the additional moving parts.

OTOH, since Ada has improved its "contractual features",
linking dynamically seems more predictable now than ever
if these features are being used. More so if the linked
part is written in Ada, too.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Self-modifying code
  2015-07-12  1:57 Self-modifying code ferrariv65
  2015-07-12  3:24 ` David Botton
  2015-07-12  4:38 ` Paul Rubin
@ 2015-07-12 11:54 ` anon
  2015-07-12 15:40   ` David Botton
  2015-07-27 11:29 ` Jacob Sparre Andersen
  3 siblings, 1 reply; 9+ messages in thread
From: anon @ 2015-07-12 11:54 UTC (permalink / raw)


ferrariv65@gmail.com wrote in
news:eb2440ca-06d4-4192-bdca-0444c2953eb9@googlegroups.com: 

> Is it possible to write self-modifying code in Ada?
> More in detail: is it possible compile some code at runtime and inject
> it into the running program, on the fly? The ability to remove that
> code after it is no longer needed would also be important, to prevent
> hogging up the system memory which may result. Thank you
> 
> Serg
> 

This question comes up once or twice a year, and with USA network cable 
channel showing "Mr. Robot" this question is on every hackers mind. How 
to hide code and build a "Rootkit" or "Virus" during run-time.

Ada was designed with a number of overriding concerns, One being 
program reliability and maintenance. That means it was designed to 
prevent "Erroneous Execution" such as self-modifying code, So the RM 
by its definition of "Erroneous Execution" means that self-modifying 
code is illegal in Ada.

So, except for shared (loaded at runtime) or dynamic (loaded on demand) 
libraries, the answer is NO!

And, I hope that the maintainers of Ada never wants Ada to be associated 
with "Rootkits" or "Viruses" type of code. So, the answer should always 
be NO!


Note: Dynamic libraries are normally a complete sub-system of routines 
not just a simple single function type plug-in.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Self-modifying code
  2015-07-12 11:54 ` anon
@ 2015-07-12 15:40   ` David Botton
  0 siblings, 0 replies; 9+ messages in thread
From: David Botton @ 2015-07-12 15:40 UTC (permalink / raw)


> So, except for shared (loaded at runtime) or dynamic (loaded on demand) 
> libraries, the answer is NO!

So not true... I've done it and I am sure many others have here too. In the old days it was a much more common technique when space was tight. Almost any language can do it, and no language in and of itself can really prevent it.

Ada prevents you from shooting yourself in the foot by mistake, but anyone can do it on purpose.

> Note: Dynamic libraries are normally a complete sub-system of routines 
> not just a simple single function type plug-in.

Not true, I'd almost say the majority of dynamic libraries I've used (outside basic std libs) are components. You would be surprised how often those dynalibs have no more than one function, say a factory to an IUknown interface etc.

Also tons of plugin APIs, etc. I've used in the past with one function access, etc.

Dynamic libs are a very solid way to swap code around at runtime.

David Botton


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Self-modifying code
  2015-07-12  1:57 Self-modifying code ferrariv65
                   ` (2 preceding siblings ...)
  2015-07-12 11:54 ` anon
@ 2015-07-27 11:29 ` Jacob Sparre Andersen
  3 siblings, 0 replies; 9+ messages in thread
From: Jacob Sparre Andersen @ 2015-07-27 11:29 UTC (permalink / raw)


ferrariv65@gmail.com writes:

> More in detail: is it possible compile some code at runtime and inject
> it into the running program, on the fly? The ability to remove that
> code after it is no longer needed would also be important, to prevent
> hogging up the system memory which may result.

Yes.  AdaCore has a detailed example of how you can do it with GNAT in
their Ada Gems series.

Greetings,

Jacob
-- 
»Great minds discuss ideas,
 Average minds discuss events,
 Small minds discuss people.«


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-07-27 11:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-12  1:57 Self-modifying code ferrariv65
2015-07-12  3:24 ` David Botton
2015-07-12  4:38 ` Paul Rubin
2015-07-12  5:09   ` David Botton
2015-07-12  5:53     ` Paul Rubin
2015-07-12  9:10       ` Georg Bauhaus
2015-07-12 11:54 ` anon
2015-07-12 15:40   ` David Botton
2015-07-27 11:29 ` Jacob Sparre Andersen

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