[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

load_region() patch



 Ok, looks like I've got it. Puuuuhhhh... :)

 To describe what's going on: At the beginning of create_base() in mem.c the
maximum available memory size `len' is determined plus the map where to find
it. If this does not fit to the program wanting to be loaded into alternate
ram it is set to core memory immediately.

 Now comes a thing which I don't unterstand: When actually allocating memory
from this map later `normal' programs always allocate `len' bytes, but shared
text programs allocate `len + fh->ftext + KERNEL_MEM'. Don't whow where the
point of making is that difficult is, but normally it works because some
lines earlier `len' is decremented by exactly `fh->ftext + KERNEL_MEM' bytes
for all shared text programs.

 This decrementing is bound to some conditions dealing with alternate memory,
and here comes the crack: None of this condition must necessary be true if
the program is too large to fit into alternate memory and therefore all
lengths and maps are set up to deal with core memory already. Thus this
decrementation will never happen and thus when allocating the memory `fh->
ftext + KERNEL_MEM' will be be added again, resulting in a request bigger
than the largest block and thus fail. :(

 I'm a bit worried why things look so strange and much more difficult than I
would have expected them to be, which is why I don't really want to judge
about all this decrementing and adding and why these conditions dealing with
alternate memory , but here is a fix which *seems* to work for me:

 It should fit to both plain MiNT 1.12 and MH-MiNT 1.12h2.

ciao,
TeSche
--


--- mem.c.orig	Tue Dec 27 14:09:48 1994
+++ mem.c	Tue Dec 27 14:14:12 1994
@@ -1172,8 +1172,20 @@
 		len -= KEEP_MEM;
 	}
 
+/*
+ *	TeSche: the third part of this comparison can cause problems when
+ *	alternate memory is getting low, in this case `len' is already set
+ *	to coresize but won't get decremented here. when actually allocating
+ *	the memory later fh->ftext and KERNEL_MEM are added again resulting
+ *	in a request bigger than coresize -> error... :(
+ */
+
+#if 1
+	if (s && !s->text) {
+#else
 	if (s && !s->text &&
 	    (!(flags & F_ALTLOAD) || map == alt || altsize < fh->ftext)) {
+#endif
 		if (len > fh->ftext + KERNEL_MEM)
 			len -= fh->ftext + KERNEL_MEM;
 		else