/**
	 * Get an allocated message buffer from the free pool.  The ownership of the buffer
	 * is the responsibility of the caller until they are finished and call ReturnToPool.
	 * @param Function function signature that defines the kind of buffer to return
	 * 
	 * @return allocated buffer ready to be filled with data
	 */
	MessagePoolElem* GetNextFree(UFunction* Function)
	{
		// Create or allocate the appropriate pool to get a buffer from
		MessagePoolElem* NextMsg = NULL;
		TWeakObjectPtr<UFunction> FuncPtr(Function);
		PoolMapping* FuncPool = Pool.Find(FuncPtr);
		if (!FuncPool)
		{
			FuncPool = CreatePool(Function);
		}

		if (FuncPool)
		{
			if (FuncPool->FreeList)
			{
				// Retrieve and clear an existing allocation
				NextMsg = FuncPool->FreeList;
				FuncPool->FreeList = NextMsg->Next();

				NextMsg->Unlink();
				(**NextMsg).Msg->Clear();
			}
			else
			{
				// Create a new allocation from the head prototype
				NextMsg = new MessagePoolElem();
				(**NextMsg).OwnerFunc = FuncPtr;
				(**NextMsg).Msg = FuncPool->Prototype.Msg->New();
			}
		}

		return NextMsg;
	}
Example #2
0
		void * GetProcAddress(HMODULE module, const void * lpProcName, std::function<int(LPCSTR, const void*)> comp)
		{
			assert(module != NULL);
			PeDecoder::PeImage pe(module, true);
			if (!pe.IsPe())
			{
				return nullptr;
			}
			auto& exportDir = pe.GetExportDirectory();
			if (!exportDir)
			{
				return nullptr;
			}
			auto end = exportDir->end();

			auto result = _STD lower_bound(exportDir->begin(), end, lpProcName, [&comp]
			(PeDecoder::ExportIteratorNode& node, const void* val)
			{
				return comp(node.NamePtr(), val) < 0;
			});

			if (result == end || comp(result->NamePtr(), lpProcName) != 0)
			{
				return nullptr;
			}
			return result->FuncPtr();
		}
Example #3
0
		void * GetProcAddress(HMODULE module, std::function<bool(LPCSTR)> comp)
		{
			assert(module != NULL);
			assert(comp);
			PeDecoder::PeImage pe(module, true);
			if (!pe.IsPe())
			{
				return nullptr;
			}
			auto& exportDir = pe.GetExportDirectory();
			if (!exportDir)
			{
				return nullptr;
			}
			auto end = exportDir->end();

			auto result = _STD find_if(exportDir->begin(), end, [&comp]
			(PeDecoder::ExportIteratorNode& node)
			{
				return comp(node.NamePtr());
			});

			if (end == result)
			{
				return nullptr;
			}
			return result->FuncPtr();
		}
	/**
	 * Create a pool to hold a given function's message buffers
	 * Creates the message prototype and holds it in the never released head of the list
	 * 
	 * @return head of a new linked list for the given function
	 */
	PoolMapping* CreatePool(class UFunction* OwnerFunc)
	{
		TWeakObjectPtr<UFunction> FuncPtr(OwnerFunc);
		PoolMapping* FuncPool = Pool.Find(FuncPtr);
		check(!FuncPool);

		PoolMapping NewPool;
		NewPool.Prototype.OwnerFunc = OwnerFunc;
		NewPool.Prototype.Msg = const_cast<google::protobuf::Message*>(CreateRPCPrototype(OwnerFunc)); 
		Pool.Add(OwnerFunc, NewPool);
		return Pool.Find(OwnerFunc);
	}