From: Aric.Caley@ofa123.fidonet.org
Newsgroups: comp.sys.amiga.programmer
Subject: Re: physical memory prot
X-Sender: newtout 0.02 Nov  5 1992
Date: 15 Nov 92  11:15:04

> Organization: University of California; Santa Cruz
> From: davids@cats.ucsc.edu (Dave Schreiber)
> Message-ID: 1duvk4INN65q@darkstar.ucsc.edu
> Newsgroups: comp.sys.amiga.programmer
>
> Who says you need an eight byte page size, i.e. why does every memory
> allocation need to be treated as a separate page?  You could implement
> something like this:
> When a task starts, create two lists of memory:  memory allocated by the
>  task and memory in the task's address space ("owned" by the task) but not
>  allocated.
> When the task wants to allocate a memory block of size n, do the following:
>    1. Search the owned-but-not-allocated memory list for a block of size n.
>    2. If no large enough block exists, allocate the necessary memory
>       (rounded up to a multiple of the page size, of course) from the
>       system heap, change its protection so that it is owned by the task,
>       allocate the amount of memory required by the task, and put the
>       remaining memory in the owned-but-not-allocated list.
> When the task frees a block of memory, check to see if this free results
>  in an entire page of memory being freed.  If so, remove that page from
>  the owned-but-not-allocated list, change its protections back to "unowned,"
>  and return it to the system heap.  Note that this can be done occasionally
>  instead of on every FreeMem() if it turns out to be too expensive an
>  operation to run frequently.
>
> Using this technique will let you keep the 8-byte minimum allocation size
> yet work with large (>=4K on the '040) page sizes.

Sounds great.

> The real problem with memory protection on the Amiga is that it is
> possible for one task to share its memory with another without explicitly
> telling the OS that the shared memory is in fact shared.  This is a big
> nono under a protected OS.  However, it is an exaggeration to say that
> 99.9% of Amiga programs do this.  Out of the dozens or so I've written
> (some PD, most for my own use), I doubt more than one or two share data
> with other tasks (aside from those that have ARexx ports;  I sure hope
> MinRexx doesn't break under a protected OS :-)).  Also, I suspect that most
> of those programs that do share data with other tasks share data with
> child tasks that are created by the original program using CreateTask(),
> CreateNewProc();  I'd bet that if, under a version of AmigaDOS with
> protected memory, CreateTask() etc. created threads (i.e. tasks
> that exist in the same address space with their creators, and thus which
> can share their creators' data), a lot of compatibility issues could be
> minimized.  This would require new system calls that the system program
> loader could use to create new address spaces, but that wouldn't affect
> user programs.

Well, how about two memory lists?  Each task has its own private, protected
memory  list  (as  you  described), and then there would be "shared" memory
list.  Memory that was intended to be passed around would be allocated from
the  public memory list (or basicly, the way all memory is alloceted now!).
Now, this would require simply using the right memory flags in AllocMem() -
which  probably most applications do not.  So there's still a compatibility
problem, even though it should be easily fixed by correcting the AllocMem's
in your application and recompiling.

-so-

Why  not  have  a little controler program that the user runs.  This little
program  would  allow  you choose memory protection by default (which would
cause  most programs to break until they got fixed), or set it on a program
by  program basis (you'd have, I suppose, a small database of program names
and flags indicateing what level [if any] of MP could be done).

Furthermore,  you  could add a library of MP/VM and related functions - any
application  accessing  it could tell the system directly that it supported
MP/VM.

All the code in AmigaOS should be changed to support MP (everything - prefs
editors,   workbench,   libraries,  etc).   Even  if  NO  applications  can
immediately  use  MP,  at  least AmigaOS would!  And that would make things
more stable.

Now  perhaps  I  am  completely  off  here...   but it seems like this is a
reasonable  solution.   What don't I understand, if this idea is completely
unfeasable?   Third parties have developed VM that uses a similar system to
what  I described (from what I understand, I dont have an MMU to see how it
works).

> Dave Schreiber  "Look.  Don't touch."  davids@cats.ucsc.edu (until 6/20/93)

 - Dances With Coyotes - World's slowest programer -Given that the universe-
 --- AKA Dances V2.0, Coyote, Magnet, Major, etc ---is infinate, and god is-
 --- Former Net-Lurker - YES, an AMIGA godammit! ---all powerful, would you-
 - If it says SEX and FREE BEER I'll mess with it! -like some toast?       -


--- Maximus 2.00
Xref: sparky comp.sys.amiga.programmer:16144 comp.sys.amiga.hardware:20009