From 198cee939d3e4b4dd99ca5ada89b8b3d4740f3c8 Mon Sep 17 00:00:00 2001 From: deraadt Date: Thu, 30 Nov 1995 18:40:21 +0000 Subject: [PATCH] integrate 040 MDP_UNCACHE_WX cache changes by niklas & deraadt --- sys/arch/mac68k/include/proc.h | 2 ++ sys/arch/mac68k/mac68k/machdep.c | 17 +++++++++++++++++ sys/arch/mac68k/mac68k/pmap.c | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/sys/arch/mac68k/include/proc.h b/sys/arch/mac68k/include/proc.h index c343f3a496c..7707df4d577 100644 --- a/sys/arch/mac68k/include/proc.h +++ b/sys/arch/mac68k/include/proc.h @@ -48,3 +48,5 @@ struct mdproc { #define MDP_STACKADJ 0x0002 /* Frame SP adjusted, might have to undo when system call returns ERESTART. */ +#define MDP_UNCACHE_WX 0x0004 /* The process might modify code, so + don't cache writeable executable pages. */ diff --git a/sys/arch/mac68k/mac68k/machdep.c b/sys/arch/mac68k/mac68k/machdep.c index 20f1b8ec68c..d410a95d648 100644 --- a/sys/arch/mac68k/mac68k/machdep.c +++ b/sys/arch/mac68k/mac68k/machdep.c @@ -123,6 +123,11 @@ #include +#ifdef COMPAT_SUNOS +#include +extern struct emul emul_sunos; +#endif + #include "via.h" #include "macrom.h" #include "ether.h" @@ -478,6 +483,18 @@ setregs(p, pack, sp, retval) if (fpu_type) { m68881_restore(&p->p_addr->u_pcb.pcb_fpregs); } + +#ifdef COMPAT_SUNOS + /* + * SunOS' ld.so does self-modifying code without knowing + * about the 040's cache purging needs. So we need to uncache + * writeable executable pages. + */ + if (p->p_emul == &emul_sunos) + p->p_md.md_flags |= MDP_UNCACHE_WX; + else + p->p_md.md_flags &= ~MDP_UNCACHE_WX; +#endif } #define SS_RTEFRAME 1 diff --git a/sys/arch/mac68k/mac68k/pmap.c b/sys/arch/mac68k/mac68k/pmap.c index 8d504e68e82..d9f3b1cc551 100644 --- a/sys/arch/mac68k/mac68k/pmap.c +++ b/sys/arch/mac68k/mac68k/pmap.c @@ -1381,6 +1381,13 @@ validate: npte = pa | pte_prot(pmap, prot) | (*pte & (PG_M|PG_U)) | PG_V; if (wired) npte |= PG_W; + + /* Don't cache if process can't take it, like SunOS ones. */ + if (mmutype == MMU_68040 && pmap != pmap_kernel() && + (curproc->p_md.md_flags & MDP_UNCACHE_WX) && + (prot & VM_PROT_EXECUTE) && (prot & VM_PROT_WRITE)) + checkpv = cacheable = FALSE; + if (!checkpv && !cacheable) npte |= PG_CI; #if defined(M68040) -- 2.20.1