Exemplo n.º 1
0
PortManager::PortManager(
    util::daemon::Daemon & daemon)
    : ppbox::common::CommonModuleBase<PortManager>(daemon, "PortManager")
{
    ports_ = (PortContainer *)shared_memory().alloc_with_id(PORTMANAGE_OBJECT_ID, sizeof(PortContainer));
    if (ports_)
    {
        new (ports_) PortContainer();
    }
    else
    {
        ports_ = (PortContainer *)shared_memory().get_by_id(PORTMANAGE_OBJECT_ID);
    }
}
Exemplo n.º 2
0
SharedPtr<SharedMemory> SharedMemory::Create(std::string name) {
    SharedPtr<SharedMemory> shared_memory(new SharedMemory);

    shared_memory->name = std::move(name);

    return shared_memory;
}
Exemplo n.º 3
0
IDL_VPTR IDL_CDECL idl_bam_cxc_get_data(int argc, IDL_VPTR argv[]) {
	QSharedMemory shared_memory("photo");

	//QTextStream(stdout) << shared_memory.nativeKey() << endl;

	if (!shared_memory.attach(QSharedMemory::ReadOnly)) {
		IDL_MessageFromBlock(bam_cxc_msg_block, BAM_CXC_ERROR, IDL_MSG_LONGJMP, "Could not attach to shared memory block photo");
	}

	shared_memory.lock();
	int size = shared_memory.size();
	if (size != sizeof(unsigned int) * NPIXELX * NPIXELY * NCHANNELS) {
		shared_memory.unlock();
		shared_memory.detach();
		IDL_MessageFromBlock(bam_cxc_msg_block, BAM_CXC_ERROR, IDL_MSG_LONGJMP, "Unexpected size for shared memory block photo");
	
	}
	const unsigned int *data = (const unsigned int *) shared_memory.data();
	unsigned int *data_copy = (unsigned int *) malloc(sizeof(unsigned int) * NPIXELX * NPIXELY * NCHANNELS);
	memcpy(data_copy, data, sizeof(unsigned int) * NPIXELX * NPIXELY * NCHANNELS);

	shared_memory.unlock();
	shared_memory.detach();

	int n_dim = 3;
	IDL_MEMINT dim[3] = {NCHANNELS, NPIXELY, NPIXELX};
	IDL_VPTR rv = IDL_ImportArray(n_dim, dim, IDL_TYP_ULONG, (UCHAR *) data_copy, (IDL_ARRAY_FREE_CB) free, 0);

	return rv;
}
Exemplo n.º 4
0
static unsigned long int* get_shared_memory(const char* key) {
	QSharedMemory shared_memory(key);

	//QTextStream(stdout) << shared_memory.nativeKey() << endl;

	if (!shared_memory.attach(QSharedMemory::ReadOnly)) {
		IDL_MessageFromBlock(bam_cxc_msg_block, BAM_CXC_ERROR, IDL_MSG_LONGJMP, "Could not attach to shared memory block %s", key);
	}

	shared_memory.lock();
	int size = shared_memory.size();
	if (size != sizeof(unsigned long int) * NPIXELX * NPIXELY) {
		shared_memory.unlock();
		shared_memory.detach();
		IDL_MessageFromBlock(bam_cxc_msg_block, BAM_CXC_ERROR, IDL_MSG_LONGJMP, "Unexpected size for shared memory block %s", key);
	
	}
	const unsigned long int *data = (const unsigned long int *) shared_memory.data();
	unsigned long int *data_copy = (unsigned long int *) malloc(sizeof(unsigned long int) * NPIXELX * NPIXELY);
	memcpy(data_copy, data, sizeof(unsigned long int) * NPIXELX * NPIXELY);

	shared_memory.unlock();
	shared_memory.detach();

	return data_copy;
}
Exemplo n.º 5
0
        Debuger::Debuger(
            util::daemon::Daemon & daemon)
            : ppbox::common::CommonModuleBase<Debuger>(daemon, "Debuger")
            , debug_log_stream_(NULL)
            , hook_log_stream_(NULL)
            , timer_(NULL)
            , msg_queue_("Debuger", shared_memory())
            , out_streamed_(false)
            , hook_streamed_(false)
        {
            debug_mode_ = (boost::uint32_t *)shared_memory().alloc_with_id(DEBUG_OBJECT_ID, sizeof(boost::uint32_t));
            if (debug_mode_) {
                new (debug_mode_) boost::uint32_t(0);
            } else {
                debug_mode_ = (boost::uint32_t *)shared_memory().get_by_id(DEBUG_OBJECT_ID);
            }

            check_debug_mode();
        }
Exemplo n.º 6
0
SharedPtr<SharedMemory> SharedMemory::Create(u32 size, MemoryPermission permissions,
        MemoryPermission other_permissions, std::string name) {
    SharedPtr<SharedMemory> shared_memory(new SharedMemory);

    shared_memory->name = std::move(name);
    shared_memory->base_address = 0x0;
    shared_memory->fixed_address = 0x0;
    shared_memory->size = size;
    shared_memory->permissions = permissions;
    shared_memory->other_permissions = other_permissions;

    return shared_memory;
}
Exemplo n.º 7
0
void rpcudp::_recv_thread_impl(sysptr_t)
{
	size_t bufsize = _get_mtu();

	udpaddr addr;
	int addrlen = sizeof(addr);
	int code = 0;

	char* tmp = new char[bufsize];
	char* buffer = tmp;
	while (true)
	{
		void* ptr = _alloc_memory_raw(bufsize);

		code = _recvfrom_impl(buffer, bufsize, 0, addr, addrlen);
		if (code == SOCKET_ERROR)
		{//TODO:加上udpsock失效不提示
#ifdef _LOG_RPCUDP_RUNNING
			mylog.log(log_error,
				"rpcudp recvfrom have socket error code:", WSAGetLastError());
#endif
			break;
		}


		shared_memory recvbuf;
		//减少ack包带来的内存损耗
	/*	if (code < static_cast<size_t>(bufsize / 2))
		{
			char* small_buffer = new char[code];
			memcpy(small_buffer, buffer, code);
			recvbuf = shared_memory(memory_block(small_buffer, code));
			_memory_count += code;
		}
		else*/
		if (true)
		{
			recvbuf = shared_memory(memory_block(buffer, code));
			buffer = new char[bufsize];
			_memory_count += bufsize;
		}

		_package_process(addr, addrlen, recvbuf, code);
	}
	delete buffer;
}
Exemplo n.º 8
0
SharedPtr<SharedMemory> SharedMemory::CreateForApplet(std::shared_ptr<std::vector<u8>> heap_block,
                                                      u32 offset, u32 size,
                                                      MemoryPermission permissions,
                                                      MemoryPermission other_permissions,
                                                      std::string name) {
    SharedPtr<SharedMemory> shared_memory(new SharedMemory);

    shared_memory->owner_process = nullptr;
    shared_memory->name = std::move(name);
    shared_memory->size = size;
    shared_memory->permissions = permissions;
    shared_memory->other_permissions = other_permissions;
    shared_memory->backing_block = heap_block;
    shared_memory->backing_block_offset = offset;
    shared_memory->base_address = Memory::HEAP_VADDR + offset;

    return shared_memory;
}
int main(int argc, char *argv[]){
	pid_t pid;

	// initialize shared memory for IPCs
	shared_memory();

	pid = fork();
	switch(pid){
		case -1:
			// process creation failed
			die("process creation failed");
		case 0:
			// input process
			pid = fork();
			switch(pid){
				case -1:
					// process creation failed
					die("process creation failed");
				case 0:
					// event key process (input)
					return eventkey_process();
				default:
					// input process
					return input_process();
			}
		default:
			pid = fork();
			switch(pid){
				case -1:
					// process creation failed
					die("process creation failed");
				case 0:
					// output process
					return output_process();
				default:
					// main process
					main_process();
			}
	}

	free_shared();

	return 0;
}
Exemplo n.º 10
0
Arquivo: user.c Projeto: Artea/psyced
void create() {
    jabber2avail = shared_memory("jabber2avail");
    ::create();
}
Exemplo n.º 11
0
SharedPtr<SharedMemory> SharedMemory::Create(SharedPtr<Process> owner_process, u32 size,
                                             MemoryPermission permissions,
                                             MemoryPermission other_permissions, VAddr address,
                                             MemoryRegion region, std::string name) {
    SharedPtr<SharedMemory> shared_memory(new SharedMemory);

    shared_memory->owner_process = owner_process;
    shared_memory->name = std::move(name);
    shared_memory->size = size;
    shared_memory->permissions = permissions;
    shared_memory->other_permissions = other_permissions;

    if (address == 0) {
        // We need to allocate a block from the Linear Heap ourselves.
        // We'll manually allocate some memory from the linear heap in the specified region.
        MemoryRegionInfo* memory_region = GetMemoryRegion(region);
        auto& linheap_memory = memory_region->linear_heap_memory;

        ASSERT_MSG(linheap_memory->size() + size <= memory_region->size,
                   "Not enough space in region to allocate shared memory!");

        shared_memory->backing_block = linheap_memory;
        shared_memory->backing_block_offset = linheap_memory->size();
        // Allocate some memory from the end of the linear heap for this region.
        linheap_memory->insert(linheap_memory->end(), size, 0);
        memory_region->used += size;

        shared_memory->linear_heap_phys_address =
            Memory::FCRAM_PADDR + memory_region->base + shared_memory->backing_block_offset;

        // Increase the amount of used linear heap memory for the owner process.
        if (shared_memory->owner_process != nullptr) {
            shared_memory->owner_process->linear_heap_used += size;
        }

        // Refresh the address mappings for the current process.
        if (Kernel::g_current_process != nullptr) {
            Kernel::g_current_process->vm_manager.RefreshMemoryBlockMappings(linheap_memory.get());
        }
    } else {
        // TODO(Subv): What happens if an application tries to create multiple memory blocks
        // pointing to the same address?
        auto& vm_manager = shared_memory->owner_process->vm_manager;
        // The memory is already available and mapped in the owner process.
        auto vma = vm_manager.FindVMA(address)->second;
        // Copy it over to our own storage
        shared_memory->backing_block = std::make_shared<std::vector<u8>>(
            vma.backing_block->data() + vma.offset, vma.backing_block->data() + vma.offset + size);
        shared_memory->backing_block_offset = 0;
        // Unmap the existing pages
        vm_manager.UnmapRange(address, size);
        // Map our own block into the address space
        vm_manager.MapMemoryBlock(address, shared_memory->backing_block, 0, size,
                                  MemoryState::Shared);
        // Reprotect the block with the new permissions
        vm_manager.ReprotectRange(address, size, ConvertPermissions(permissions));
    }

    shared_memory->base_address = address;
    return shared_memory;
}