experiment with unaligned address in ffi
This commit is contained in:
		@ -408,3 +408,7 @@ class SmallPointer(Object)
 | 
			
		||||
 | 
			
		||||
	method(#primitive) free.
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class LargePointer(Object)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -40,7 +40,8 @@ class MyObject(Object)
 | 
			
		||||
		| ffi now |
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		ffi := FFI new: 'libc.so.6'.
 | 
			
		||||
		[ ffi := FFI new: 'libc.so.6'. ] on: Exception do: [:ex | ffi := FFI new: 'libc.so' ].
 | 
			
		||||
 | 
			
		||||
		now := ffi call: #time signature: 'l>i' arguments: #(0).
 | 
			
		||||
		////ffi call: #srand signature: 'i>' arguments: ##(now).
 | 
			
		||||
		ffi call: #srandom signature: 'i>' arguments: ##(now).
 | 
			
		||||
 | 
			
		||||
@ -840,7 +840,7 @@ int moo_genpfmethod (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class, moo_met
 | 
			
		||||
		goto oops;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	mnsym = (moo_oop_char_t)moo_makesymbol (moo, mthname, i);
 | 
			
		||||
	mnsym = (moo_oop_char_t)moo_makesymbol(moo, mthname, i);
 | 
			
		||||
	if (!mnsym) goto oops;
 | 
			
		||||
	moo_pushvolat (moo, (moo_oop_t*)&mnsym); tmp_count++;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -282,7 +282,7 @@ static MOO_INLINE moo_oop_t _fetch_raw_uint (moo_t* moo, moo_uint8_t* rawptr, mo
 | 
			
		||||
			return MOO_NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return moo_oowtoint (moo, v);
 | 
			
		||||
	return moo_oowtoint(moo, v);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1093,7 +1093,7 @@ moo_pfrc_t moo_pf_smptr_as_string (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
 | 
			
		||||
	ptr = MOO_OOP_TO_SMPTR(rcv);
 | 
			
		||||
	sprintptr (buf, (moo_oow_t)ptr, &len);
 | 
			
		||||
 | 
			
		||||
	ss = moo_makestring (moo, buf, len);
 | 
			
		||||
	ss = moo_makestring(moo, buf, len);
 | 
			
		||||
	if (!ss) return MOO_PF_FAILURE;
 | 
			
		||||
 | 
			
		||||
	MOO_STACK_SETRET (moo, nargs, ss);
 | 
			
		||||
 | 
			
		||||
@ -542,7 +542,8 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
 | 
			
		||||
	sig = MOO_STACK_GETARG(moo, nargs, 1);
 | 
			
		||||
	args = MOO_STACK_GETARG(moo, nargs, 2);
 | 
			
		||||
 | 
			
		||||
	if (!MOO_OOP_IS_SMPTR(fun)) goto inval;
 | 
			
		||||
	if (MOO_OOP_IS_SMPTR(fun)) f = MOO_OOP_TO_SMPTR(fun);
 | 
			
		||||
	else if (moo_inttooow(moo, fun, (moo_oow_t*)&f) <= -1) goto softfail;
 | 
			
		||||
 | 
			
		||||
	/* the signature must not be empty. at least the return type must be
 | 
			
		||||
	 * specified */
 | 
			
		||||
@ -553,9 +554,7 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
 | 
			
		||||
	if (MOO_OBJ_GET_SIZE(sig) > 1 && MOO_CLASSOF(moo,args) != moo->_array) goto inval;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	f = MOO_OOP_TO_SMPTR(fun); 
 | 
			
		||||
	arr = (moo_oop_oop_t)args;
 | 
			
		||||
 | 
			
		||||
	/*MOO_DEBUG2 (moo, "<ffi.call> %p in %p\n", f, ffi->handle);*/
 | 
			
		||||
 | 
			
		||||
#if defined(USE_DYNCALL)
 | 
			
		||||
@ -782,7 +781,7 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
 | 
			
		||||
			if (!MOO_IN_SMPTR_RANGE(r)) 
 | 
			
		||||
			{
 | 
			
		||||
				/* the returned pointer is not aligned */
 | 
			
		||||
				goto softfail;
 | 
			
		||||
				goto inval;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			MOO_STACK_SETRET (moo, nargs, MOO_SMPTR_TO_OOP(r));
 | 
			
		||||
@ -827,7 +826,7 @@ hardfail:
 | 
			
		||||
static moo_pfrc_t pf_getsym (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
 | 
			
		||||
{
 | 
			
		||||
	ffi_t* ffi;
 | 
			
		||||
	moo_oop_t name;
 | 
			
		||||
	moo_oop_t name, ret;
 | 
			
		||||
	void* sym;
 | 
			
		||||
 | 
			
		||||
	MOO_ASSERT (moo, nargs == 1);
 | 
			
		||||
@ -852,8 +851,28 @@ static moo_pfrc_t pf_getsym (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
 | 
			
		||||
 | 
			
		||||
	MOO_DEBUG4 (moo, "<ffi.getsym> %.*js => %p in %p\n", MOO_OBJ_GET_SIZE(name), MOO_OBJ_GET_CHAR_SLOT(name), sym, ffi->handle);
 | 
			
		||||
 | 
			
		||||
	MOO_ASSERT (moo, MOO_IN_SMPTR_RANGE(sym));
 | 
			
		||||
	MOO_STACK_SETRET (moo, nargs, MOO_SMPTR_TO_OOP(sym));
 | 
			
		||||
#if 0
 | 
			
		||||
	ret = moo_oowtoptr(moo, (moo_oow_t)sym);
 | 
			
		||||
	if (!ret) goto softfail;
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
	if (MOO_IN_SMPTR_RANGE(sym))
 | 
			
		||||
	{
 | 
			
		||||
		ret = MOO_SMPTR_TO_OOP(sym);
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		ret = moo_oowtoint(moo, (moo_oow_t)sym);
 | 
			
		||||
		if (!ret) goto softfail;
 | 
			
		||||
		/*
 | 
			
		||||
		MOO_DEBUG1 (moo, "<ffi.getsym> unaligned symbol address - %p\n", sym);
 | 
			
		||||
		moo_seterrnum (moo, MOO_EINVAL);
 | 
			
		||||
		goto softfail;
 | 
			
		||||
		*/
 | 
			
		||||
	}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	MOO_STACK_SETRET (moo, nargs, ret);
 | 
			
		||||
	return MOO_PF_SUCCESS;
 | 
			
		||||
 | 
			
		||||
softfail:
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user