Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: pardo@cs.washington.edu (David Keppel)
Subject: More Alpha/AXP I cache flushing questions
Date: Tue, 12 Oct 93 18:17:43 GMT	[thread overview]
Message-ID: <1993Oct12.181743.10010@beaver.cs.washington.edu> (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


             reply	other threads:[~1993-10-12 18:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-10-12 18:17 David Keppel [this message]
1993-10-12 23:39 ` More Alpha/AXP I cache flushing questions Jim Paradis
read-only archive

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