HRESULT Library_spot_hardware_native_Microsoft_SPOT_Hardware_NativeEventDispatcher::_ctor___VOID__STRING__U8( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); CLR_RT_DriverInterruptMethods* pDriverMethods; const CLR_RT_NativeAssemblyData* pNativeDriverData; CLR_RT_HeapBlock_NativeEventDispatcher* pNativeDisp = NULL; LPCSTR lpszDriverName; UINT64 driverData; CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); // Retrieve paramenters; if (stack.Arg1().DataType() != DATATYPE_OBJECT) { TINYCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } lpszDriverName = stack.Arg1().RecoverString(); FAULT_ON_NULL(lpszDriverName); driverData = stack.Arg2().NumericByRef().u8; // Throw NULL exception if string is empty. if(hal_strlen_s( lpszDriverName ) == 0) { TINYCLR_CHECK_HRESULT(CLR_E_ARGUMENT_NULL); } // Retrives pointers to driver implemented functions. pNativeDriverData = GetAssemblyNativeData( lpszDriverName ); // Validates check sum and presence of the structure. if(pNativeDriverData == NULL || pNativeDriverData->m_checkSum != DRIVER_INTERRUPT_METHODS_CHECKSUM) { TINYCLR_CHECK_HRESULT(CLR_E_DRIVER_NOT_REGISTERED); } // Get pointer to CLR_RT_DriverInterruptMethods pDriverMethods = (CLR_RT_DriverInterruptMethods *)pNativeDriverData->m_pNativeMethods; // Check that all methods are present: if(pDriverMethods->m_InitProc == NULL || pDriverMethods->m_EnableProc == NULL || pDriverMethods->m_CleanupProc == NULL) { TINYCLR_CHECK_HRESULT(CLR_E_DRIVER_NOT_REGISTERED); } // So we found driver by name and now we create instance of CLR_RT_HeapBlock_NativeEventDispatcher TINYCLR_CHECK_HRESULT(CLR_RT_HeapBlock_NativeEventDispatcher::CreateInstance( *pThis, pThis[ FIELD__m_NativeEventDispatcher ] )); // Initialize the driver with and provide the instance of CLR_RT_HeapBlock_NativeEventDispatcher TINYCLR_CHECK_HRESULT(GetEventDispatcher( stack, pNativeDisp )); // Now call the driver. First save pointer to driver data. pNativeDisp->m_DriverMethods = pDriverMethods; TINYCLR_CHECK_HRESULT(pDriverMethods->m_InitProc( pNativeDisp, driverData )); TINYCLR_NOCLEANUP(); }
HRESULT Library_spot_hardware_usb_native_Microsoft_SPOT_Hardware_UsbClient_UsbStream::nativeWrite___I4__SZARRAY_U1__I4__I4( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); CLR_INT32 retVal = 0; CLR_INT32 controllerIndex, streamIndex, stream; CLR_UINT32 offset, count; CLR_RT_HeapBlock* pThis; CLR_RT_HeapBlock_Array* array; pThis = stack.This(); FAULT_ON_NULL(pThis); controllerIndex = pThis[ Library_spot_hardware_usb_native_Microsoft_SPOT_Hardware_UsbClient_UsbStream::FIELD__m_controllerIndex ].NumericByRef().s4; streamIndex = pThis[ Library_spot_hardware_usb_native_Microsoft_SPOT_Hardware_UsbClient_UsbStream::FIELD__m_streamIndex ].NumericByRef().s4; array = stack.Arg1().DereferenceArray(); FAULT_ON_NULL( array ); offset = stack.Arg2().NumericByRef().u4; count = stack.Arg3().NumericByRef().u4; stream = (controllerIndex << USB_CONTROLLER_SHIFT) + streamIndex; if( array->m_numOfElements < (offset + count) ) { TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } else { retVal = USB_Write( stream, (char*)array->GetFirstElement()+offset, count ); } stack.SetResult_I4( retVal ); TINYCLR_NOCLEANUP(); }
HRESULT Library_spot_net_security_native_Microsoft_SPOT_Net_Security_SslNative::SecureConnect___STATIC__VOID__I4__STRING__OBJECT( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_NETWORK(); TINYCLR_HEADER(); CLR_INT32 sslContext = stack.Arg0().NumericByRef().s4; CLR_RT_HeapBlock* hb = stack.Arg1().DereferenceString(); CLR_RT_HeapBlock* socket = stack.Arg2().Dereference(); CLR_INT32 timeout_ms = -1; // wait forever CLR_RT_HeapBlock hbTimeout; int result; LPCSTR szName; CLR_INT32 handle; bool fRes = true; CLR_INT64 *timeout; FAULT_ON_NULL(socket); handle = socket[ Library_spot_net_native_Microsoft_SPOT_Net_SocketNative::FIELD__m_Handle ].NumericByRef().s4; /* Because we could have been a rescheduled call due to a prior call that would have blocked, we need to see * if our handle has been shutdown before continuing. */ if (handle == Library_spot_net_native_Microsoft_SPOT_Net_SocketNative::DISPOSED_HANDLE) { ThrowError( stack, CLR_E_OBJECT_DISPOSED ); TINYCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } FAULT_ON_NULL_ARG(hb); szName = hb->StringText(); hbTimeout.SetInteger( timeout_ms ); TINYCLR_CHECK_HRESULT(stack.SetupTimeout( hbTimeout, timeout )); while(true) { result = SSL_Connect( handle, szName, sslContext ); if(result == SOCK_EWOULDBLOCK || result == SOCK_TRY_AGAIN) { // non-blocking - allow other threads to run while we wait for socket activity TINYCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_Socket, fRes )); if(result < 0) break; } else { break; } } stack.PopValue(); // Timeout TINYCLR_CHECK_HRESULT(ThrowOnError( stack, result )); TINYCLR_NOCLEANUP(); }
HRESULT Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_CryptokiDigest::DigestInternal___SZARRAY_U1__SZARRAY_U1__I4__I4( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); CLR_RT_HeapBlock* pThis = stack.This(); CLR_RT_HeapBlock_Array* pData = stack.Arg1().DereferenceArray(); CLR_INT32 offset = stack.Arg2().NumericByRef().s4; CLR_INT32 len = stack.Arg3().NumericByRef().s4; CLR_RT_HeapBlock* pSession = pThis[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_SessionContainer::FIELD__m_session].Dereference(); CLR_INT32 digestSize = pThis[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_CryptokiDigest::FIELD__m_hashSize].NumericByRef().s4; CK_SESSION_HANDLE hSession; //CLR_INT32 maxProcessingBytes; FAULT_ON_NULL_ARG(pData); FAULT_ON_NULL(pSession); if((offset + len) > (CLR_INT32)pData->m_numOfElements) TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); hSession = (CK_SESSION_HANDLE)pSession[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_Session::FIELD__m_handle].NumericByRef().s4; if(hSession == CK_SESSION_HANDLE_INVALID) TINYCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); // TODO: add code for processing chunks at a time if size is too big //maxProcessingBytes = pSession[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_Session::FIELD__m_maxProcessingBytes].NumericByRef().s4; TINYCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(stack.PushValue(), digestSize, g_CLR_RT_WellKnownTypes.m_UInt8)); CRYPTOKI_CHECK_RESULT(stack, C_Digest(hSession, pData->GetElement(offset), len, stack.TopValue().DereferenceArray()->GetFirstElement(), (CK_ULONG_PTR)&digestSize)); TINYCLR_NOCLEANUP(); }
HRESULT Library_spot_net_native_Microsoft_SPOT_Net_SocketNative::SockNameHelper( CLR_RT_StackFrame& stack, bool fPeer ) { NATIVE_PROFILE_CLR_NETWORK(); TINYCLR_HEADER(); CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); CLR_INT32 handle; CLR_INT32 ret; struct SOCK_sockaddr addr; CLR_INT32 addrLen = sizeof(addr); FAULT_ON_NULL(socket); handle = socket[ FIELD__m_Handle ].NumericByRef().s4; if(fPeer) { ret = SOCK_getpeername( handle, &addr, &addrLen ); } else { ret = SOCK_getsockname( handle, &addr, &addrLen ); } TINYCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); TINYCLR_CHECK_HRESULT(MarshalSockAddress( stack.Arg1(), &addr, addrLen )); TINYCLR_NOCLEANUP(); }
HRESULT Library_corlib_native_System_Reflection_Assembly::GetType___SystemType__STRING( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_CORE(); TINYCLR_HEADER(); CLR_RT_Assembly_Instance assm; CLR_RT_TypeDef_Index td; CLR_RT_HeapBlock* hbRef; CLR_RT_HeapBlock* hbObj; LPCSTR szClass = stack.Arg1().RecoverString(); CLR_RT_HeapBlock* hbAsm = stack.Arg0().Dereference(); FAULT_ON_NULL(szClass); FAULT_ON_NULL(hbAsm); TINYCLR_CHECK_HRESULT(GetTypeDescriptor( *hbAsm, assm )); hbRef = &stack.PushValueAndClear(); if(g_CLR_RT_TypeSystem.FindTypeDef( szClass, assm.m_assm, td )) { TINYCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*hbRef, g_CLR_RT_WellKnownTypes.m_TypeStatic)); hbObj = hbRef->Dereference(); hbObj->SetReflection( td ); } TINYCLR_NOCLEANUP(); }
HRESULT Library_spot_hardware_native_Microsoft_SPOT_Hardware_InterruptPort::set_Interrupt___VOID__MicrosoftSPOTHardwarePortInterruptMode( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_HARDWARE(); TINYCLR_HEADER(); CLR_RT_HeapBlock_NativeEventDispatcher* port; GPIO_INT_EDGE interrupt; CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); if(pThis[ Library_spot_hardware_native_Microsoft_SPOT_Hardware_NativeEventDispatcher::FIELD__m_disposed ].NumericByRef().s1 != 0) { TINYCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); } TINYCLR_CHECK_HRESULT(Library_spot_hardware_native_Microsoft_SPOT_Hardware_NativeEventDispatcher::GetEventDispatcher( stack, port )); interrupt = (GPIO_INT_EDGE)stack.Arg1().NumericByRef().u4; pThis[ Library_spot_hardware_native_Microsoft_SPOT_Hardware_Port::FIELD__m_interruptMode ].NumericByRef().s4 = interrupt; // Changes hardware state to new interrupt mode for input port. The last false means input port. TINYCLR_CHECK_HRESULT(Library_spot_hardware_native_Microsoft_SPOT_Hardware_Port::ChangeState( pThis, port, false )); TINYCLR_NOCLEANUP(); }
HRESULT Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_CryptokiVerify::VerifyInternal___BOOLEAN__SZARRAY_U1__I4__I4__SZARRAY_U1__I4__I4( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); CLR_RT_HeapBlock* pThis = stack.This(); CLR_RT_HeapBlock_Array* pData = stack.Arg1().DereferenceArray(); CLR_INT32 offset = stack.Arg2().NumericByRef().s4; CLR_INT32 len = stack.Arg3().NumericByRef().s4; CLR_RT_HeapBlock_Array* pSig = stack.Arg4().DereferenceArray(); CLR_INT32 sigOff = stack.Arg5().NumericByRef().s4; CLR_INT32 sigLen = stack.Arg6().NumericByRef().s4; CLR_RT_HeapBlock* pSession = pThis[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_SessionContainer::FIELD__m_session].Dereference(); CK_SESSION_HANDLE hSession; bool retVal = false; CK_RV result; FAULT_ON_NULL_ARG(pData); FAULT_ON_NULL_ARG(pSig); if((offset + len ) > (CLR_INT32)pData->m_numOfElements) TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); if((sigOff + sigLen) > (CLR_INT32)pSig->m_numOfElements ) TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); hSession = (CK_SESSION_HANDLE)pSession[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_Session::FIELD__m_handle].NumericByRef().s4; if(hSession == CK_SESSION_HANDLE_INVALID) TINYCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); result = C_Verify(hSession, pData->GetElement(offset), len, pSig->GetElement(sigOff), sigLen); retVal = CKR_OK == result; stack.SetResult_Boolean(retVal); TINYCLR_NOCLEANUP(); }
HRESULT Library_corlib_native_System_Reflection_ConstructorInfo::Invoke___OBJECT__SZARRAY_OBJECT( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_CORE(); TINYCLR_HEADER(); CLR_RT_HeapBlock* thisRef = stack.ThisRef().Dereference(); CLR_RT_MethodDef_Instance md; CLR_RT_HeapBlock_Array* pArray = stack.Arg1().DereferenceArray(); CLR_RT_HeapBlock* args = NULL; int numArgs = 0; if(md.InitializeFromIndex( thisRef->ReflectionDataConst().m_data.m_method ) == false) TINYCLR_SET_AND_LEAVE(CLR_E_NULL_REFERENCE); if(stack.m_customState == 0) { stack.m_customState = 1; if(pArray) { args = (CLR_RT_HeapBlock*)pArray->GetFirstElement(); numArgs = pArray->m_numOfElements; } TINYCLR_CHECK_HRESULT(stack.MakeCall( md, NULL, args, numArgs )); } TINYCLR_NOCLEANUP(); }
HRESULT Library_spot_native_Microsoft_SPOT_Hardware_SystemInfo::GetSystemVersion___STATIC__VOID__BYREF_I4__BYREF_I4__BYREF_I4__BYREF_I4( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_CORE(); TINYCLR_HEADER(); { CLR_RT_HeapBlock hbMajor; CLR_RT_HeapBlock hbMinor; CLR_RT_HeapBlock hbBuild; CLR_RT_HeapBlock hbRevision; MfReleaseInfo releaseInfo; Solution_GetReleaseInfo( releaseInfo ); hbMajor.SetInteger( releaseInfo.version.usMajor ); TINYCLR_CHECK_HRESULT(hbMajor.StoreToReference( stack.Arg0(), 0 )); hbMinor.SetInteger( releaseInfo.version.usMinor ); TINYCLR_CHECK_HRESULT(hbMinor.StoreToReference( stack.Arg1(), 0 )); hbBuild.SetInteger( releaseInfo.version.usBuild ); TINYCLR_CHECK_HRESULT(hbBuild.StoreToReference( stack.Arg2(), 0 )); hbRevision.SetInteger( releaseInfo.version.usRevision ); TINYCLR_CHECK_HRESULT(hbRevision.StoreToReference( stack.Arg3(), 0 )); } TINYCLR_NOCLEANUP(); }
HRESULT Library_corlib_native_System_BitConverter::ToString___STATIC__STRING__SZARRAY_U1__I4__I4( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_CORE(); TINYCLR_HEADER(); CLR_RT_HeapBlock_Array* pArray = stack.Arg0().DereferenceArray(); FAULT_ON_NULL_ARG(pArray); int index; index = stack.Arg1().NumericByRefConst().s4; int length; length = stack.Arg2().NumericByRefConst().s4; if (pArray->m_numOfElements == 0 && index == 0 && length == 0) { TINYCLR_CHECK_HRESULT(stack.SetResult_String("")); } else { if (index < 0 || length < 0 || (unsigned int)index >= pArray->m_numOfElements) TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); if ((unsigned int)index + length > pArray->m_numOfElements) TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); BYTE* p; p = pArray->GetFirstElement(); char* pOutput = ByteArrayToHex(p, index, length); TINYCLR_CHECK_HRESULT(stack.SetResult_String(pOutput)); delete[] pOutput; } TINYCLR_NOCLEANUP(); }
HRESULT Library_corlib_native_System_DateTime::_ctor___VOID__I4__I4__I4__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_CORE(); TINYCLR_HEADER(); CLR_RT_HeapBlock* pArg = &(stack.Arg1()); SYSTEMTIME st; TINYCLR_CLEAR(st); st.wYear = pArg[ 0 ].NumericByRef().s4; st.wMonth = pArg[ 1 ].NumericByRef().s4; st.wDay = pArg[ 2 ].NumericByRef().s4; st.wHour = pArg[ 3 ].NumericByRef().s4; st.wMinute = pArg[ 4 ].NumericByRef().s4; st.wSecond = pArg[ 5 ].NumericByRef().s4; st.wMilliseconds = pArg[ 6 ].NumericByRef().s4; /// Our current supported range is between 1601 and 3000. Years before 1582 requires different calculation (see explanation /// in time_decl.h), same way years after 3000 will not hold the simple arithmatic which we are using. More complex calculations /// outside these range are not worth the CPU cycle and codesize. if ((st.wYear < 1601) || (st.wYear > 3000) || (st.wMonth < 1) || (st.wMonth > 12) || (st.wDay < 1) || (st.wDay > 31)) { TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); } Compress( stack, st ); TINYCLR_NOCLEANUP(); }
HRESULT Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_FindObjectEnum::FindObjectsInit___VOID__SZARRAY_MicrosoftSPOTCryptokiCryptokiAttribute( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); CLR_RT_HeapBlock* pThis = stack.This(); CLR_RT_HeapBlock_Array* pAttribs = stack.Arg1().DereferenceArray(); CLR_RT_HeapBlock* pAttrib; CLR_RT_HeapBlock* pSession = pThis[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_FindObjectEnum::FIELD__m_session].Dereference(); CK_SESSION_HANDLE hSession; CK_ATTRIBUTE attribs[20]; CLR_UINT32 i; FAULT_ON_NULL_ARG(pAttribs); FAULT_ON_NULL(pSession); if(pAttribs->m_numOfElements > ARRAYSIZE(attribs)) TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); hSession = pSession[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_Session::FIELD__m_handle].NumericByRef().u4; pAttrib = (CLR_RT_HeapBlock*)pAttribs->GetFirstElement(); for(i=0; i<pAttribs->m_numOfElements; i++) { CLR_RT_HeapBlock* pElement = pAttrib->Dereference(); FAULT_ON_NULL(pElement); CLR_RT_HeapBlock_Array* pValueArray = pElement[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_CryptokiAttribute::FIELD__Value].DereferenceArray(); FAULT_ON_NULL(pValueArray); attribs[i].type = pElement[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_CryptokiAttribute::FIELD__Type].NumericByRef().u4; attribs[i].pValue = pValueArray->GetFirstElement(); attribs[i].ulValueLen = pValueArray->m_numOfElements; pAttrib++; } CRYPTOKI_CHECK_RESULT(stack, C_FindObjectsInit(hSession, attribs, pAttribs->m_numOfElements)); TINYCLR_NOCLEANUP(); }
HRESULT Library_spot_update_native_Microsoft_SPOT_MFUpdate_MFNativeUpdate::AddPacket___STATIC__BOOLEAN__I4__I4__SZARRAY_U1__SZARRAY_U1( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); CLR_INT32 handle = stack.Arg0().NumericByRef().s4; CLR_INT32 pktIndex = stack.Arg1().NumericByRef().s4; CLR_RT_HeapBlock_Array* pPacket = stack.Arg2().DereferenceArray(); CLR_RT_HeapBlock_Array* pValidation = stack.Arg3().DereferenceArray(); CLR_UINT8* pValidData; CLR_INT32 validLen; FAULT_ON_NULL(pPacket); if(pValidation == NULL) { pValidData = NULL; validLen = 0; } else { pValidData = pValidation->GetFirstElement(); validLen = pValidation->m_numOfElements; } stack.SetResult_Boolean(TRUE == MFUpdate_AddPacket(handle, pktIndex, pPacket->GetFirstElement(), pPacket->m_numOfElements, pValidData, validLen)); TINYCLR_NOCLEANUP(); }
//--// SPI HRESULT Library_spot_hardware_native_Microsoft_SPOT_Hardware_HardwareProvider::NativeGetSpiPins___VOID__MicrosoftSPOTHardwareSPISPImodule__BYREF_MicrosoftSPOTHardwareCpuPin__BYREF_MicrosoftSPOTHardwareCpuPin__BYREF_MicrosoftSPOTHardwareCpuPin( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); CLR_RT_HeapBlock hbmsk; CLR_RT_HeapBlock hbmiso; CLR_RT_HeapBlock hbmosi; CLR_UINT32 port, msk, miso, mosi; msk = (CLR_UINT32)-1; // GPIO_NONE miso = (CLR_UINT32)-1; // GPIO_NONE mosi = (CLR_UINT32)-1; // GPIO_NONE port = stack.Arg1().NumericByRef().u4; // SPI ports are numbered from 0 up if(port >= CPU_SPI_PortsCount()) { TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } ::CPU_SPI_GetPins( port, msk, miso, mosi ); hbmsk.SetInteger ( (CLR_INT32)msk ); TINYCLR_CHECK_HRESULT(hbmsk .StoreToReference( stack.Arg2(), 0 )); hbmiso.SetInteger( (CLR_INT32)miso ); TINYCLR_CHECK_HRESULT(hbmiso.StoreToReference( stack.Arg3(), 0 )); hbmosi.SetInteger( (CLR_INT32)mosi ); TINYCLR_CHECK_HRESULT(hbmosi.StoreToReference( stack.Arg4(), 0 )); TINYCLR_NOCLEANUP(); }
HRESULT Library_spot_net_native_Microsoft_SPOT_Net_NetworkInformation_NetworkInterface::UpdateConfiguration___VOID__I4( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_NETWORK(); TINYCLR_HEADER(); SOCK_NetworkConfiguration config; CLR_RT_HeapBlock* pConfig = stack.Arg0().Dereference(); _ASSERTE(pConfig != NULL); CLR_UINT32 interfaceIndex = pConfig[ FIELD___interfaceIndex ].NumericByRefConst().u4; CLR_UINT32 updateFlags = stack.Arg1().NumericByRef().u4; CLR_RT_HeapBlock_Array* pMACAddress = pConfig[ FIELD___macAddress ].DereferenceArray(); TINYCLR_CLEAR(config); config.flags = pConfig[ FIELD___flags ].NumericByRef().u4; config.ipaddr = pConfig[ FIELD___ipAddress ].NumericByRef().u4; config.gateway = pConfig[ FIELD___gatewayAddress ].NumericByRef().u4; config.subnetmask = pConfig[ FIELD___subnetMask ].NumericByRef().u4; config.dnsServer1 = pConfig[ FIELD___dnsAddress1 ].NumericByRef().u4; config.dnsServer2 = pConfig[ FIELD___dnsAddress2 ].NumericByRef().u4; config.networkInterfaceType = pConfig[ FIELD___networkInterfaceType ].NumericByRef().u4; if(pMACAddress != NULL) { config.macAddressLen = pMACAddress->m_numOfElements; if(config.macAddressLen > sizeof(config.macAddressBuffer)) TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); memcpy( &config.macAddressBuffer, pMACAddress->GetFirstElement(), config.macAddressLen ); } TINYCLR_CHECK_HRESULT(SOCK_CONFIGURATION_UpdateAdapterConfiguration( interfaceIndex, updateFlags, &config )); TINYCLR_NOCLEANUP(); }
HRESULT Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_CryptokiSign::SignUpdateInternal___VOID__SZARRAY_U1__I4__I4( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); CLR_RT_HeapBlock* pThis = stack.This(); CLR_RT_HeapBlock_Array* pData = stack.Arg1().DereferenceArray(); CLR_INT32 offset = stack.Arg2().NumericByRef().s4; CLR_INT32 len = stack.Arg3().NumericByRef().s4; CLR_RT_HeapBlock* pSession = pThis[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_SessionContainer::FIELD__m_session].Dereference(); CLR_INT32 sigLen = pThis[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_CryptokiSign::FIELD__m_signatureLength].NumericByRef().s4; CK_SESSION_HANDLE hSession; FAULT_ON_NULL_ARG(pData); FAULT_ON_NULL(pSession); if((offset + len) > (CLR_INT32)pData->m_numOfElements) TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); hSession = (CK_SESSION_HANDLE)pSession[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_Session::FIELD__m_handle].NumericByRef().s4; // TODO: add code for processing chunks at a time if size is too big //maxProcessingBytes = pSession[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_Session::FIELD__m_maxProcessingBytes].NumericByRef().s4; if(hSession == CK_SESSION_HANDLE_INVALID) TINYCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); CRYPTOKI_CHECK_RESULT(stack, C_SignUpdate(hSession, pData->GetElement(offset), len)); TINYCLR_NOCLEANUP(); }
HRESULT Library_corlib_native_System_Reflection_FieldInfo::Initialize( CLR_RT_StackFrame& stack, CLR_RT_FieldDef_Instance& instFD, CLR_RT_TypeDef_Instance& instTD, CLR_RT_HeapBlock*& obj ) { NATIVE_PROFILE_CLR_CORE(); TINYCLR_HEADER(); CLR_RT_HeapBlock* hbField = stack.Arg0().Dereference(); if(CLR_RT_ReflectionDef_Index::Convert( *hbField, instFD ) == false || instTD.InitializeFromField ( instFD ) == false ) { TINYCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } if(instFD.m_target->flags & CLR_RECORD_FIELDDEF::FD_Static) { obj = CLR_RT_ExecutionEngine::AccessStaticField( instFD ); if(obj == NULL) TINYCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } else { TINYCLR_CHECK_HRESULT(stack.Arg1().EnsureObjectReference( obj )); if(CLR_RT_ExecutionEngine::IsInstanceOf( *obj, instTD ) == false) { TINYCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } obj = &obj[ instFD.CrossReference().m_offset ]; } TINYCLR_NOCLEANUP(); }
HRESULT Library_spot_hardware_usb_native_Microsoft_SPOT_Hardware_UsbClient_UsbStream::nativeOpen___I4__I4__I4( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); CLR_INT32 streamIndex, controllerIndex, writeEndpoint, readEndpoint; CLR_RT_HeapBlock* pThis; pThis = stack.This(); FAULT_ON_NULL(pThis); controllerIndex = pThis[ Library_spot_hardware_usb_native_Microsoft_SPOT_Hardware_UsbClient_UsbStream::FIELD__m_controllerIndex ].NumericByRef().s4; writeEndpoint = stack.Arg1().NumericByRef().s4; readEndpoint = stack.Arg2().NumericByRef().s4; for( streamIndex = 0; streamIndex < USB_MAX_QUEUES; streamIndex++ ) { CLR_INT32 stream = (controllerIndex << USB_CONTROLLER_SHIFT) + streamIndex; if( USB_OpenStream( stream, writeEndpoint, readEndpoint ) ) break; } if( streamIndex >= USB_MAX_QUEUES ) { TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } stack.SetResult_I4( streamIndex ); TINYCLR_NOCLEANUP(); }
HRESULT Library_spot_hardware_native_Microsoft_SPOT_Hardware_SPI::InternalWriteRead___VOID__SZARRAY_U2__I4__I4__SZARRAY_U2__I4__I4__I4( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_HARDWARE(); TINYCLR_HEADER(); { CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); CLR_RT_HeapBlock_Array* writeBuffer = stack.Arg1().DereferenceArray(); FAULT_ON_NULL(writeBuffer); CLR_INT32 writeOffset = stack.Arg2().NumericByRef().s4; CLR_INT32 writeCount = stack.Arg3().NumericByRef().s4; CLR_RT_HeapBlock_Array* readBuffer = stack.Arg4().DereferenceArray(); CLR_INT32 readOffset = stack.Arg5().NumericByRef().s4; CLR_INT32 readCount = stack.Arg6().NumericByRef().s4; CLR_UINT32 startReadOffset = stack.Arg7().NumericByRef().s4; SPI_CONFIGURATION config; TINYCLR_CHECK_HRESULT(Library_spot_hardware_native_Microsoft_SPOT_Hardware_SPI__Configuration::GetInitialConfig( pThis[ FIELD__m_config ], config )); config.MD_16bits = TRUE; CPU_SPI_Initialize(); if(!::CPU_SPI_nWrite16_nRead16( config, (CLR_UINT16*)writeBuffer->GetElement(writeOffset), writeCount, readBuffer == NULL ? NULL : (CLR_UINT16*)readBuffer ->GetElement(readOffset), readBuffer == NULL ? 0 : readCount, startReadOffset )) { TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_OPERATION); } } TINYCLR_NOCLEANUP(); }
HRESULT Library_corlib_native_System_Text_UTF8Encoding::GetBytes___I4__STRING__I4__I4__SZARRAY_U1__I4( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_CORE(); TINYCLR_HEADER(); size_t cMaxBytes; LPCSTR str = stack.Arg1().RecoverString(); CLR_INT32 strIdx = stack.Arg2().NumericByRef().s4; CLR_INT32 strCnt = stack.Arg3().NumericByRef().s4; CLR_RT_HeapBlock_Array* pArrayBytes = stack.Arg4().DereferenceArray(); CLR_INT32 byteIdx = stack.Arg5().NumericByRef().s4; FAULT_ON_NULL(str); FAULT_ON_NULL(pArrayBytes); cMaxBytes = hal_strlen_s(str); if((strIdx + strCnt) > (CLR_INT32)cMaxBytes ) TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); if((byteIdx + strCnt) > (CLR_INT32)pArrayBytes->m_numOfElements) TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); memcpy(pArrayBytes->GetElement(byteIdx), &str[strIdx], strCnt); stack.SetResult_I4(strCnt); TINYCLR_NOCLEANUP(); }
HRESULT Library_spot_hardware_serial_native_System_IO_Ports_SerialPort::DiscardBuffer___VOID__BOOLEAN( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_HARDWARE(); TINYCLR_HEADER(); CLR_RT_HeapBlock* pThis; BOOL fInput; CLR_RT_HeapBlock* config; CLR_UINT32 portId; pThis = stack.This(); FAULT_ON_NULL(pThis); // check if the object was disposed if(pThis[ FIELD__m_fDisposed ].NumericByRef().s1 != 0) { TINYCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); } config = pThis[ FIELD__m_config ].Dereference(); FAULT_ON_NULL(config); fInput = (TRUE == stack.Arg1().NumericByRef().u1); portId = config[ Library_spot_hardware_serial_native_System_IO_Ports_SerialPort__Configuration::FIELD__PortIndex ].NumericByRef().u4; USART_DiscardBuffer( portId, fInput ); TINYCLR_NOCLEANUP(); }
// TODO: Make common functions for transformBlock for encrypt/decrypt when async logic is in place HRESULT Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_Decryptor::TransformBlockInternal___I4__SZARRAY_U1__I4__I4__SZARRAY_U1__I4( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); CLR_RT_HeapBlock* pThis = stack.This(); CLR_RT_HeapBlock_Array* pData = stack.Arg1().DereferenceArray(); CLR_INT32 dataOffset = stack.Arg2().NumericByRef().s4; CLR_INT32 dataLen = stack.Arg3().NumericByRef().s4; CLR_RT_HeapBlock_Array* pOutput = stack.Arg4().DereferenceArray(); CLR_INT32 outOffset = stack.Arg5().NumericByRef().s4; CLR_RT_HeapBlock* pSession = pThis[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_SessionContainer::FIELD__m_session].Dereference(); CK_SESSION_HANDLE hSession; CLR_UINT32 decrSize; FAULT_ON_NULL_ARG(pData); FAULT_ON_NULL_ARG(pOutput); FAULT_ON_NULL_ARG(pSession); hSession = (CK_SESSION_HANDLE)pSession[Library_security_pkcs11_native_Microsoft_SPOT_Cryptoki_Session::FIELD__m_handle].NumericByRef().s4; if(hSession == CK_SESSION_HANDLE_INVALID) TINYCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); if((dataOffset + dataLen) > (CLR_INT32)pData->m_numOfElements ) TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); if((outOffset ) > (CLR_INT32)pOutput->m_numOfElements) TINYCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); decrSize = pOutput->m_numOfElements - outOffset; CRYPTOKI_CHECK_RESULT(stack, C_DecryptUpdate(hSession, pData->GetElement(dataOffset), dataLen, pOutput->GetElement(outOffset), (CK_ULONG_PTR)&decrSize)); stack.SetResult_I4(decrSize); TINYCLR_NOCLEANUP(); }
HRESULT Library_corlib_native_System_Reflection_Assembly::GetVersion___VOID__BYREF_I4__BYREF_I4__BYREF_I4__BYREF_I4( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_CORE(); TINYCLR_HEADER(); CLR_RT_StackFrame* caller = stack.Caller(); if(caller == NULL) { TINYCLR_SET_AND_LEAVE(S_OK); } else { CLR_RT_Assembly_Instance assm; TINYCLR_CHECK_HRESULT(GetTypeDescriptor( stack.Arg0(), assm )); const CLR_RECORD_VERSION& version = assm.m_assm->m_header->version; // we do not check for the reference not to be NULL because this is an internal method stack.Arg1().Dereference()->NumericByRef().s4 = version.iMajorVersion; stack.Arg2().Dereference()->NumericByRef().s4 = version.iMinorVersion; stack.Arg3().Dereference()->NumericByRef().s4 = version.iBuildNumber; stack.Arg4().Dereference()->NumericByRef().s4 = version.iRevisionNumber; } TINYCLR_NOCLEANUP(); }
HRESULT Library_corlib_native_System_Resources_ResourceManager::GetObject___STATIC__OBJECT__SystemResourcesResourceManager__SystemEnum( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_CORE(); TINYCLR_HEADER(); CLR_RT_HeapBlock& blkResourceManager = stack.Arg0(); CLR_RT_HeapBlock& blkEnumObj = stack.Arg1(); CLR_RT_HeapBlock* blkVT = blkEnumObj.Dereference(); CLR_RT_HeapBlock* blkEnum = blkVT + 1; CLR_RT_MethodDef_Instance md; if(stack.m_customState == 0) { stack.m_customState = 1; FAULT_ON_NULL(blkVT); if(blkEnum->DataType() != DATATYPE_I2 && blkEnum->DataType() != DATATYPE_U2) TINYCLR_SET_AND_LEAVE( CLR_E_INVALID_PARAMETER ); //call back into ResourceManager.GetObjectFromId(short id); _SIDE_ASSERTE(md.InitializeFromIndex( g_CLR_RT_WellKnownMethods.m_ResourceManager_GetObjectFromId )); TINYCLR_CHECK_HRESULT( stack.MakeCall( md, &blkResourceManager, blkEnum, 1 )); } TINYCLR_NOCLEANUP(); }
HRESULT Library_spot_hardware_native_Microsoft_SPOT_Hardware_HardwareProvider::NativeGetSerialPins___VOID__I4__BYREF_MicrosoftSPOTHardwareCpuPin__BYREF_MicrosoftSPOTHardwareCpuPin__BYREF_MicrosoftSPOTHardwareCpuPin__BYREF_MicrosoftSPOTHardwareCpuPin( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); CLR_RT_HeapBlock hbrxPin; CLR_RT_HeapBlock hbtxPin; CLR_RT_HeapBlock hbctsPin; CLR_RT_HeapBlock hbrtsPin; CLR_UINT32 port, rxPin, txPin, ctsPin, rtsPin; port = stack.Arg1().NumericByRef().u4; rxPin = (CLR_UINT32)-1; // GPIO_NONE txPin = (CLR_UINT32)-1; // GPIO_NONE ctsPin = (CLR_UINT32)-1; // GPIO_NONE rtsPin = (CLR_UINT32)-1; // GPIO_NONE // COM ports are numbered from 0 up if(port >= CPU_USART_PortsCount()) { TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } ::CPU_USART_GetPins( port, rxPin, txPin, ctsPin, rtsPin ); hbrxPin.SetInteger ( (CLR_INT32)rxPin ); TINYCLR_CHECK_HRESULT(hbrxPin.StoreToReference ( stack.Arg2(), 0 )); hbtxPin.SetInteger ( (CLR_INT32)txPin ); TINYCLR_CHECK_HRESULT(hbtxPin.StoreToReference ( stack.Arg3(), 0 )); hbctsPin.SetInteger( (CLR_INT32)ctsPin ); TINYCLR_CHECK_HRESULT(hbctsPin.StoreToReference( stack.Arg4(), 0 )); hbrtsPin.SetInteger( (CLR_INT32)rtsPin ); TINYCLR_CHECK_HRESULT(hbrtsPin.StoreToReference( stack.ArgN(5), 0 )); TINYCLR_NOCLEANUP(); }
HRESULT Library_spot_hardware_native_Microsoft_SPOT_Hardware_HardwareProvider::NativeGetBaudRateBoundary___VOID__I4__BYREF_U4__BYREF_U4( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); CLR_RT_HeapBlock hbmaxBR; CLR_RT_HeapBlock hbminBR; CLR_UINT32 port, maxBR, minBR; port = stack.Arg1().NumericByRef().u4; maxBR = (CLR_UINT32)0; minBR = (CLR_UINT32)0; // COM ports are numbered from 0 up if(port >= CPU_USART_PortsCount()) { TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } ::CPU_USART_GetBaudrateBoundary( port, maxBR, minBR ); hbmaxBR.SetInteger( (CLR_INT32)maxBR ); TINYCLR_CHECK_HRESULT(hbmaxBR.StoreToReference( stack.Arg2(), 0 )); hbminBR.SetInteger( (CLR_INT32)minBR ); TINYCLR_CHECK_HRESULT(hbminBR.StoreToReference( stack.Arg3(), 0 )); TINYCLR_NOCLEANUP(); }
HRESULT Library_spot_native_Microsoft_SPOT_Reflection::GetAssemblyInfo___STATIC__BOOLEAN__SZARRAY_U1__MicrosoftSPOTReflectionAssemblyInfo( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_CORE(); TINYCLR_HEADER(); CLR_RT_HeapBlock_Array* array = NULL; CLR_RT_Assembly* assm = NULL; CLR_RECORD_ASSEMBLY* header; array = stack.Arg0().DereferenceArray(); FAULT_ON_NULL(array); header = (CLR_RECORD_ASSEMBLY*)array->GetFirstElement(); if(header->GoodAssembly()) { CLR_RT_HeapBlock* dst = stack.Arg1().Dereference(); FAULT_ON_NULL(dst); TINYCLR_CHECK_HRESULT(CLR_RT_Assembly::CreateInstance( header, assm )); TINYCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( dst[ Library_spot_native_Microsoft_SPOT_Reflection__AssemblyInfo::FIELD__m_name ], assm->m_szName )); { CLR_RT_HeapBlock& refs = dst[ Library_spot_native_Microsoft_SPOT_Reflection__AssemblyInfo::FIELD__m_refs ]; CLR_UINT32 numRef = assm->m_pTablesSize[ TBL_AssemblyRef ]; TINYCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( refs, numRef, g_CLR_RT_WellKnownTypes.m_UInt32 )); { const CLR_RECORD_ASSEMBLYREF* ar = assm->GetAssemblyRef( 0 ); CLR_UINT32* dst = (CLR_UINT32*)refs.DereferenceArray()->GetFirstElement(); while(numRef--) { *dst++ = assm->ComputeAssemblyHash( ar++ ); } } } dst[ Library_spot_native_Microsoft_SPOT_Reflection__AssemblyInfo::FIELD__m_flags ].SetInteger( assm->m_header->flags , DATATYPE_U4 ); dst[ Library_spot_native_Microsoft_SPOT_Reflection__AssemblyInfo::FIELD__m_size ].SetInteger( ROUNDTOMULTIPLE(assm->m_header->TotalSize(), CLR_INT32), DATATYPE_I4 ); dst[ Library_spot_native_Microsoft_SPOT_Reflection__AssemblyInfo::FIELD__m_hash ].SetInteger( assm->ComputeAssemblyHash() , DATATYPE_U4 ); stack.SetResult_Boolean( true ); } else { stack.SetResult_Boolean( false ); } TINYCLR_CLEANUP(); if(assm) { assm->DestroyInstance(); } TINYCLR_CLEANUP_END(); }
HRESULT Library_spot_hardware_native_Microsoft_SPOT_Hardware_HardwareProvider::NativeGetButtonPins___MicrosoftSPOTHardwareCpuPin__MicrosoftSPOTHardwareButton( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); stack.SetResult_U4( ::VirtualKey_GetPins( stack.Arg1().NumericByRef().u4 ) ); TINYCLR_NOCLEANUP_NOLABEL(); }
HRESULT Library_spot_hardware_native_Microsoft_SPOT_Hardware_HardwareProvider::NativeGetSupportedInterruptModes___MicrosoftSPOTHardwareCpuPinValidInterruptMode__MicrosoftSPOTHardwareCpuPin( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); stack.SetResult_U4( ::CPU_GPIO_GetSupportedInterruptModes( stack.Arg1().NumericByRef().u4 ) ); TINYCLR_NOCLEANUP_NOLABEL(); }