Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* More Alpha/AXP I cache flushing questions
@ 1993-10-12 18:17 David Keppel
  1993-10-12 23:39 ` Jim Paradis
  0 siblings, 1 reply; 2+ messages in thread
From: David Keppel @ 1993-10-12 18:17 UTC (permalink / raw)


I asked recently about where to find the constant used in the Alpha's
CALL_PAL assembler used to flush the I cache.  Thanks to those who
responded, the answer is that it's in <alpha/pal.h>.

For my next Alpha question, I get SEGV's (I'm running OSF/1 1.3) when I
try to `malloc' a region and use it for writing and executing code.  For
example:

	h = malloc (...)
	memcpy (h, ...);
	routine_to_imb();
	(*h)();		/* SEGV on first instruction. */

I have experimented and found

	h = malloc (...)
	mprotect (h&pagemask, ..., PROT_READ|PROT_WRITE|PROT_EXEC);
	memcpy (h, ...);
	routine_to_imb();
	(*h)();
	memcpy (h, ...);	/* SEGV on first byte changed. */

(Yes, I'm checking the return value from `mprotect').  If I add another
`mprotect', it all works:

	h = malloc (...)
	mprotect (h&pagemask, ..., PROT_READ|PROT_WRITE|PROT_EXEC);
	memcpy (h, ...);
	routine_to_imb();
	(*h)();
	mprotect (h&pagemask, ..., PROT_READ|PROT_WRITE|PROT_EXEC);
	memcpy (h, ...);
	routine_to_imb();
	(*h)();

I don't have any explanation for why I'm using `mprotect', except that
when it SEGV'd in the first case, I assumed ``oh, the page isn't
executable'' and started adding calls to `mprotect'.  I have since
discovered that although some cases will SEGV reliably on my machine
(without the `mprotect' calls), there are other cases that will work
reliably without the call (but they also omit the IMB, so they execute
both old and new instructions and thus produce incorrect results).

Does anybody have good ideas about what is going on?  It almost feels
like the OS is playing games with the page protections, but the fact
that *some* attempts to muck things don't SEGV tells me this probably
isn't the case.  Thus, I suspect my use of `mprotect' is just a red
herring, but I'm not sure what else to do.

Thanks in advance.

		;-D on  ( Paying my protection )  Pardo


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

end of thread, other threads:[~1993-10-12 23:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1993-10-12 18:17 More Alpha/AXP I cache flushing questions David Keppel
1993-10-12 23:39 ` Jim Paradis

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