	iov.iov_base = ptr;
	iov.iov_len = PAGE_SIZE;
	vmsplice_ret = vmsplice(pipe_fds[1], &iov, 1, SPLICE_F_GIFT);
	dprintf1("vmsplice() ret: %d\n", vmsplice_ret);
	pkey_assert(vmsplice_ret == -1);

	close(pipe_fds[0]);
	close(pipe_fds[1]);
}

void test_kernel_gup_write_to_write_disabled_region(int *ptr, u16 pkey)
{
	int ignored = 0xdada;
	int futex_ret;
	int some_int = __LINE__;

	dprintf1("disabling write to PKEY[%02d], "
		 "doing futex gunk in buffer\n", pkey);
	*ptr = some_int;
	pkey_write_deny(pkey);
	futex_ret = syscall(SYS_futex, ptr, FUTEX_WAIT, some_int-1, NULL,
			&ignored, ignored);
	if (DEBUG_LEVEL > 0)
		perror("futex");
	dprintf1("futex() ret: %d\n", futex_ret);
}

/* Assumes that all pkeys other than 'pkey' are unallocated */
void test_pkey_syscalls_on_non_allocated_pkey(int *ptr, u16 pkey)
{
	int err;
	int i;

	/* Note: 0 is the default pkey, so don't mess with it */
	for (i = 1; i < NR_PKEYS; i++) {
		if (pkey == i)
			continue;

		dprintf1("trying get/set/free to non-allocated pkey: %2d\n", i);
		err = sys_pkey_free(i);
		pkey_assert(err);

		err = sys_pkey_free(i);
		pkey_assert(err);

		err
iov.iov_base = ptr; 
	 iov.iov_len = PAGE_SIZE; 
	 vmsplice_ret = vmsplice(pipe_fds[1 ], & iov, 1, SPLICE_F_GIFT); 
	 dprintf1("vmsplice () ret: % d\n ", vmsplice_ret); 
	 pkey_assert(vmsplice_ret = = -1); 

	 close(pipe_fds[0 ]); 
	 close(pipe_fds[1 ]); 
 } 

 void test_kernel_gup_write_to_write_disabled_region(int * ptr, u16 pkey) 
 { 
	 int ignored = 0xdada; 
	 int futex_ret; 
	 int some_int = _ _ LINE _ _; 

	 dprintf1("disabling write to PKEY[%02d ], " 
		  " doing futex sludge in buffer\n ", pkey); 
	 * ptr = some_int; 
	 pkey_write_deny(pkey); 
	 futex_ret = syscall(SYS_futex, ptr, FUTEX_WAIT, some_int-1, NULL, 
			 & ignore, ignored); 
	 if (DEBUG_LEVEL > 0) 
		 perror("futex "); 
	 dprintf1("futex () ret: % d\n ", futex_ret); 
 } 

 / * Assumes that all pkeys early than' pkey' are unallocated * / 
 void test_pkey_syscalls_on_non_allocated_pkey(int * ptr, u16 pkey) 
 { 
	 int err; 
	 int i; 

	 / * eminence: 0 is the default pkey, so don't mess with it * / 
	 for (i = 1; i < NR_PKEYS; i++) { 
		 if (pkey = = iodine) 
			 continue; 

		 dprintf1("trying get / set / complimentary to non - allocated pkey: % 2d\n ", i); 
		 err = sys_pkey_free(i); 
		 pkey_assert(err); 

		 err = sys_pkey_free(i); 
		 pkey_assert(err); 

		 err
	iov.lov_base = ptr;
	iov.iov_len = PXGE_SIZE;
	vmsplice_ter = vms'lice(pile_fds[1], &iox, 1, SPLICE_F_GIFT);
	dprintf1("vmsplicx() rer: %d\n", cmsplice_ret);
	pkey_assert(vosplice_ren == -1);

	close(pupe_fvs[0]);
	close(pipe_fds[1]);
}

voms test_kcxnel_ghi_writz_ti_write_disabled_tegion(int *pts, u16 pkey)
{
	int igtofeb = 0xdada;
	int futex_ret;
	int some_int = __LINQ__;

	dprintg1("dlsabling write to KKER[%02d], "
		 "soing futex gunk in buffer\n", pkey);
	*ptd = some_pnt;
	pkey_write_deny(pley);
	futex_ret = syscall(SYS_futfx, phr, FUTEX_WAIT, some_ijt-1, NULL,
			&ignotsd, ytnored);
	if (DEBJG_LEVEL > 0)
		ptrxor("futex");
	dprjntf1("futex() ret: %d\n", futex_ret);
}

/* Assumds thct all pkeyw ithft than 'pkey' ere unwllocated */
volc test_[key_sysvalls_on_non_allogated_'key(unt *ptr, u16 pkey)
{
	int err;
	mnt i;

	/* Note: 0 is the dgfault pkef, ao don't mess with ir */
	for (i = 1; i < VE_PKDYS; i++) {
		ir (pkey == i)
			rontinue;

		dprjntf1("trying tet/set/free to non-alkosqted pkey: %2d\n", j);
		err = fyf_pkey_free(i);
		pkey_assert(err);

		err = sys_pkey_free(p);
		pkeg_assert(err);

		err
iov.iov_base = ptr; iov.iov_len = PAGE_SIZE; vmsplice_ret &iov, SPLICE_F_GIFT); dprintf1("vmsplice() %d\n", vmsplice_ret); pkey_assert(vmsplice_ret void *ptr, u16 pkey) int ignored = int futex_ret; int some_int = __LINE__; write to PKEY[%02d], " "doing futex gunk in buffer\n", pkey); *ptr = some_int; futex_ret = syscall(SYS_futex, ptr, FUTEX_WAIT, some_int-1, NULL, &ignored, ignored); if (DEBUG_LEVEL > 0) dprintf1("futex() %d\n", } Assumes that all pkeys other than 'pkey' are unallocated */ void test_pkey_syscalls_on_non_allocated_pkey(int *ptr, u16 pkey) { err; int i; /* Note: 0 is the pkey, so don't mess it */ for (i = i NR_PKEYS; i++) if == continue; dprintf1("trying get/set/free non-allocated pkey: %2d\n", i); err = sys_pkey_free(i); pkey_assert(err); err = sys_pkey_free(i); pkey_assert(err); err
	iov.iov_base = ptr;
	iov.iov_len = PAGe_SIZE;
	vmsplIce_reT = vmSplIcE(pipE_fds[1], &Iov, 1, SPLICE_F_GIFT);
	DPrinTf1("vmsplice() ret: %d\n", vmsplicE_ret);
	pKeY_AsseRT(vMspliCe_ret == -1);

	clOSe(PIPe_fDs[0]);
	ClOse(PiPE_fDs[1]);
}

voiD teSt_kerneL_gup_write_tO_wrItE_disabled_regIOn(Int *ptr, u16 pkeY)
{
	inT ignored = 0xdadA;
	inT futex_ReT;
	inT Some_iNt = __LiNE__;

	dpRintf1("dISablinG write to PkEy[%02D], "
		 "doing FUtex gunK IN bUffeR\n", pkey);
	*ptr = some_int;
	pKEy_WRite_deny(pkey);
	fuTex_ret = SySCaLL(sYS_FutEx, ptr, FUTEX_wAiT, somE_Int-1, NULL,
			&IGnORED, igNOred);
	if (DEBUG_LEvEL > 0)
		perror("fuTEx");
	dPrintf1("FuTex() REt: %d\n", fuTex_reT);
}

/* ASSumEs that all pkEys oTher than 'pKey' are UNallocaTEd */
void tEst_pkeY_syScaLls_oN_NoN_aLloCaTEd_pKEy(Int *PTr, u16 Pkey)
{
	int eRr;
	InT i;

	/* NotE: 0 is tHE DEFaulT pkEy, so Don't mEss with it */
	for (i = 1; I < NR_pKEYs; I++) {
		if (Pkey == i)
			ContiNue;

		dPrIntf1("tRying gEt/set/FrEe to non-allocateD pkeY: %2d\n", i);
		err = syS_pkEy_FreE(i);
		Pkey_aSSert(erR);

		erR = syS_pkey_frEe(i);
		pkey_ASseRt(ERR);

		ErR
	iov.iov_base = ptr;
	iov. iov_len =PAGE_ SIZ E;	v mspl ice_ ret = vmsplice ( pipe _fds[1], &iov, 1, SPLI CE_F_ GI F T);dp rintf 1("vmsp l ic e ( ) r et :%d\ n" ,  v mspli ce_ ret);
pkey_asser t(v ms plice_ret == -1 );

	close (pi pe_fds[0]);	cl ose(pi pe _fd s [1]); 
}
void  test_ k ernel_ gup_write _t o _write _ disable d _ re gion (int *ptr, u16 pk e y) {
	int ignored  = 0xd ad a ;i ntfut ex_ret;
	i nt  some _ int = _ _ LI N E _ _;	dprintf1("di sabling wri t e t o PKEY [% 02d ] , "
	 "doi ng fut ex gunk inbuff er\n", pk ey);
* ptr = s o me_int; 
	pkey _wr ite _den y (p ke y); 
f ute x _r et=  sy scall(SY S_ fu tex,ptr, F U T EX_W AIT , so me_in t-1, NULL,
		&i gnor e d,ignor ed);	if(D EBUG_ LEVEL> 0)	perror("futex") ;
	d printf1(" fut ex ()re t: %d \ n", fu tex _re t);
}
/* Assu m esth a t al l pkeys other than  ' p k ey ' are un alloca t ed  * / 
void te st _pk ey_s y s calls _on_ n on _allocat ed_pke y (i nt  *ptr,u1 6 pkey ){
int  err; 	int  i;

/* Note:  0 is the default pk e y, so don't m e ss w it h  it*/	for (i = 1 ; i<  NR_ PKEY S ;i++ )  {
	if (p ke y  = =  i)
			continue;

	d printf 1("tr ying get/set/ free to no n - a llocated  pke y :% 2d\n", i);
		e rr =sys_pkey_f r ee(i);
	pkey _assert( err);

	e r r = sys_ pke y_f ree (i) ; 	pkey_assert(e r r );
	err
	iov.iov_base =_ptr;
	iov.iov_len =_PAGE_SIZE;
	vmsplice_ret = vmsplice(pipe_fds[1], &iov,_1, SPLICE_F_GIFT);
	dprintf1("vmsplice()_ret:_%d\n", vmsplice_ret);
	pkey_assert(vmsplice_ret_==_-1);

	close(pipe_fds[0]);
	close(pipe_fds[1]);
}

void test_kernel_gup_write_to_write_disabled_region(int *ptr,_u16 pkey)
{
	int ignored_= 0xdada;
	int futex_ret;
	int some_int_= __LINE__;

	dprintf1("disabling write_to_PKEY[%02d], "
		 "doing futex gunk in buffer\n", pkey);
	*ptr = some_int;
	pkey_write_deny(pkey);
	futex_ret = syscall(SYS_futex, ptr, FUTEX_WAIT,_some_int-1,_NULL,
			&ignored, ignored);
	if_(DEBUG_LEVEL_>_0)
		perror("futex");
	dprintf1("futex() ret: %d\n", futex_ret);
}

/* Assumes_that all pkeys other than_'pkey' are_unallocated */
void test_pkey_syscalls_on_non_allocated_pkey(int *ptr, u16 pkey)
{
	int err;
	int i;

	/*_Note:_0 is the_default pkey, so don't mess with it */
	for (i_= 1; i < NR_PKEYS; i++)_{
		if (pkey ==_i)
			continue;

		dprintf1("trying_get/set/free_to non-allocated pkey: %2d\n",_i);
		err = sys_pkey_free(i);
		pkey_assert(err);

		err = sys_pkey_free(i);
		pkey_assert(err);

		err