How to leave resident code in memory?

9 posts / 0 new
Last post
hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
How to leave resident code in memory?

Hello.

I'm wondering if there was any standard way of leaving code resident in memory and being able to find it by name? You could say a TSR.

Years ago when writing patch programs I needed to leave code in memory. I recall modifying the segment list in the assembler days so code could be left in memory. But one main problem was adding memory reachable by name.

I first used a MsgPort added to the public list. But using a port just for the sake of reaching it later wasn't the best idea. Later when I used AmigaE I made them into commodities so avoided the problem of leaving code resident and patches could also be disabled from Exchange.

However. This method was still a work around really. So I'm wondering if there is an Amiga way of leaving code resident?

I've been looking into the NamedObject functions of utility.base but can't find much info about it. Still, they look useful. But has there ever been a proper way of leaving code resident in memory?

thellier
thellier's picture
Offline
Last seen: 5 years 3 months ago
Joined: 2014-03-04 12:43
Re: How to leave resident code in memory?

Hello

Certainly the more standard way is to create a .Library
See her for an exemple source code
http://aminet.net/package/util/libs/SimpleDT

Alain Thellier

Alain Thellier - Wazp3D

hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
Re: How to leave resident code in memory?

Thanks for replying. I hadn't considered using a library for the purpose. Most likely because it would require some set-up and more so on OS4. But I can understand your point. Another way would be to add an actual task.

xenic
xenic's picture
Offline
Last seen: 1 year 11 months ago
Joined: 2011-05-07 04:52
Re: How to leave resident code in memory?

Not sure what you want to do but there is DOS AddSegment(). I think the code needs to be reentrant and could be callable by a user.

X1000 - OS 4.1FE

hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
Re: How to leave resident code in memory?

Yes it looks like Segment functions could help as well. The only thing is that the API says not to create them your self yet provides no function do it. Well apart from some slightly more complicated function you can pass a file handle. So that makes it hard to create a segment from memory. Which is then hacked together anyway or another executable used for the code.

xenic
xenic's picture
Offline
Last seen: 1 year 11 months ago
Joined: 2011-05-07 04:52
Re: How to leave resident code in memory?

@hypex
When you mentioned a TSR in your original post, I thought you wanted to make a program resident like C:Resident does. Since I don't really understand what you want to do, I would agree with the library suggestion.

X1000 - OS 4.1FE

hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
Re: How to leave resident code in memory?

@xenic

I had TSR in mind as someone said it at an Amiga meeting, month ago last year, and it stuck in my head. But, with what I was talking about, it would be lesser leaving a program in memory and more so leaving code in memory.

Perhaps an example would help. A popular pastime for Amiga programs back in the day was to patch into the OS. In this case a program would load up, leave code "resident" in memory it could locate later, patch a library and exit.

Now I wrote stuff like that, but it was possible to "cheat" by leaving an ID before function code, so you didn't need to register any code or data with the OS.

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
Re: How to leave resident code in memory?

Sounds like IExec->AllocNamedMemory() might be what you want.

xenic
xenic's picture
Offline
Last seen: 1 year 11 months ago
Joined: 2011-05-07 04:52
Re: How to leave resident code in memory?

@hypex

Perhaps an example would help. A popular pastime for Amiga programs back in the day was to patch into the OS. In this case a program would load up, leave code "resident" in memory it could locate later, patch a library and exit.

O.K. It seems you want to perform run-time patching. There are exec functions to patch libraries (SetFunction() for OS3 & SetMethod() for OS4) and I would assume that those exec functions would take care of clearing the instruction caches to prevent problems. See the exec autodoc for CacheClearE() with regard to run-time patches and caches.

I'm not sure if run-time patching is advisable for OS4. I've never heard of any OS4 system friendly ways to do anything but library patching.

If you allocate named memory as salass00 suggested, maybe it should AVT_Type MEMF_EXECUTABLE & AVT_Lock to be sure it can't be paged out or moved.

X1000 - OS 4.1FE

Log in or register to post comments