#include <sys/types.h>
#include <sys/param.h>
#include <sys/user.h>
#include <vm/hat.h>
#include <vm/as.h>

#include <rciext/spl.h>
#include <rciext/procx.h>
#include <rciext/ctxlock.h>

ctxlock()
{
	struct ctx *ctx;
	struct procx *px;
	int s;

	s = splhigh();
	if (!u.u_procp->p_as || !(ctx = u.u_procp->p_as->a_hat.hat_ctx))
	 { return (0);
	 }
	if ((px = procx_get()) == NULL)
	 { return (0);
	 }
	ctx->c_lock = 1;
	px->px_flags |= PX_CTXLOCK;
	set_swaplock(px, PX_CTXLOCK);
	return (1);
}

ctxunlock()
{
	struct ctx *ctx;
	struct procx *px;
	int s;

	s = splhigh();
	if (!u.u_procp->p_as || !(ctx = u.u_procp->p_as->a_hat.hat_ctx))
	 { printf ("ctxunlock: no addr\n"); return (0);
	 }
	if ((px = procx_find()) == NULL)
	 { printf ("ctxunlock: cant find\n"); return (0);
	 }
	ctx->c_lock = 0;
	px->px_flags &= ~PX_CTXLOCK;
	clear_swaplock(px, PX_CTXLOCK);
	return (1);
}
