typename Generic_obj_space<SPACE>::Status Generic_obj_space<SPACE>::v_insert(Phys_addr phys, Addr const &virt, Size size, unsigned char page_attribs) { (void)size; assert (size.value() == 1); Entry *c = get_cap(virt.value()); if (!c && !(c = caps_alloc(virt.value()))) return Insert_err_nomem; assert (size.value() == 1); if (c->valid()) { if (c->obj() == phys) { if (EXPECT_FALSE(c->rights() == page_attribs)) return Insert_warn_exists; c->add_rights(page_attribs); return Insert_warn_attrib_upgrade; } else return Insert_err_exists; } Obj::set_entry(virt, c); c->set(phys, page_attribs); return Insert_ok; }
bool Generic_obj_space<SPACE>::v_lookup(Addr const &virt, Phys_addr *phys = 0, Size *size = 0, unsigned *attribs = 0) { if (size) size->set_value(1); Entry *cap; if (Optimize_local && mem_space() == Mem_space::current_mem_space(current_cpu())) cap = cap_virt(virt.value()); else cap = get_cap(virt.value()); if (EXPECT_FALSE(!cap)) { if (size) size->set_value(Caps_per_page); return false; } if (Optimize_local) { Capability c = Mem_layout::read_special_safe((Capability*)cap); if (phys) *phys = c.obj(); if (c.valid() && attribs) *attribs = c.rights(); return c.valid(); } else { Obj::set_entry(virt, cap); if (phys) *phys = cap->obj(); if (cap->valid() && attribs) *attribs = cap->rights(); return cap->valid(); } }
void TestAddr::defaultConstruction() { Addr a; CPPUNIT_ASSERT_EQUAL( Addr::PortType( 0u ), a.getPort() ); CPPUNIT_ASSERT_EQUAL( Addr::HostType( 0u ), a.getHost() ); }
Addr max_addr() { Addr tmp; std::fill(tmp.begin(), tmp.end() , (std::numeric_limits<typename Addr::value_type>::max)()); return Addr(tmp); }
void TestAddr::SetPortStr() { Addr a; a.setPort( "telnet" ); CPPUNIT_ASSERT_EQUAL( std::string( "telnet" ), a.getPortStr() ); CPPUNIT_ASSERT_EQUAL( Addr::PortType( 23u ), a.getPort() ); }
void TestAddr::SetHostStr() { Addr a; bool result = a.setHost( "localhost" ); CPPUNIT_ASSERT( result ); CPPUNIT_ASSERT_EQUAL( std::string( "localhost" ), a.getHostStr() ); }
void Socket::connect(const Addr& addr) { int err = ::connect(m_socket, (const struct sockaddr *)&(addr.getAddr()), sizeof (addr.getAddr())); if(err < 0) throw ConnectErr(errno); m_connected = true; }
void Cfg::GetRegName(char *buf, Addr nic_addr, int port_no) { buf += sprintf(buf, "%s", GetLoadStr(IDS_IPMSG)); if (port_no != IPMSG_DEFAULT_PORT) { buf += sprintf(buf, "%d", port_no); } if (nic_addr.IsEnabled()) { *buf++ = '_'; nic_addr.ToStr(buf); } }
std::shared_ptr<Chunk> ChunkList::createChunk(const Addr &addr, Chunk::Type type) { auto ch1 = _chunks.find(addr.offset()); if (ch1 != _chunks.end()) { if (ch1->second->type()!=Chunk::Type::UNPARSED) return nullptr; } std::shared_ptr<Chunk> ch; ch = std::make_shared<Chunk>(addr, type); _chunks[addr.offset()]=ch; return ch; }
// for code lines InstrItem::InstrItem(InstrView* iv, QTreeWidget* parent, Addr addr, bool inside, const QString& code, const QString& cmd, const QString& args, TraceInstr* instr) : QTreeWidgetItem(parent) { _view = iv; _addr = addr; _instr = instr; _instrCall = 0; _instrJump = 0; _inside = inside; setTextAlignment(0, Qt::AlignRight); setTextAlignment(1, Qt::AlignRight); setTextAlignment(2, Qt::AlignRight); if (args == "...") setText(0, args); else setText(0, addr.pretty()); setText(4, code); setText(5, cmd); setText(6, args); TraceLine* l; if (instr && (l = instr->line())) setText(7, l->name()); updateGroup(); updateCost(); }
int Socket::send(const char* msg, size_t len, const Addr& dest, int flags, CheckingType check) { if(check == DONT_CHECK) { return ::sendto(m_socket, msg, len, flags, (struct sockaddr *)&(dest.getAddr()), sizeof (dest.getAddr())); } else { for(;;) { int sent = ::sendto(m_socket, msg, len, flags, (struct sockaddr *)&(dest.getAddr()), sizeof (dest.getAddr())); if(sent != -1 || (errno != EINTR && errno != EWOULDBLOCK)) return sent; } } }
FixCallCost::FixCallCost(TracePart* part, FixPool* pool, TraceFunctionSource* functionSource, unsigned int line, Addr addr, TracePartCall* partCall, SubCost callCount, FixString& s) { if (0) qDebug("Got FixCallCost (addr 0x%s, line %d): calls %s", qPrintable(addr.toString()), line, qPrintable(callCount.pretty())); int maxCount = part->eventTypeMapping()->count(); _part = part; _functionSource = functionSource; _line = line; _addr = addr; _cost = (SubCost*) pool->reserve(sizeof(SubCost) * (maxCount+1)); s.stripSpaces(); int i = 0; while(i<maxCount) { if (!s.stripUInt64(_cost[i])) break; i++; } _count = i; if (!pool->allocateReserved(sizeof(SubCost) * (_count+1) )) _count = 0; else _cost[_count] = callCount; _nextCostOfPartCall = partCall ? partCall->setFirstFixCallCost(this) : 0; }
typename Generic_obj_space<SPACE>::Status Generic_obj_space<SPACE>::v_insert(Phys_addr phys, Addr const &virt, Size size, unsigned char page_attribs) { (void)size; assert (size.value() == 1); Entry *c; if (Optimize_local && mem_space() == Mem_space::current_mem_space(current_cpu())) { c = cap_virt(virt.value()); if (!c) return Insert_err_nomem; Capability cap; if (!Mem_layout::read_special_safe((Capability*)c, cap) && !caps_alloc(virt.value())) return Insert_err_nomem; } else { c = alien_lookup(virt.value()); if (!c && !(c = caps_alloc(virt.value()))) return Insert_err_nomem; Obj::set_entry(virt, c); } if (c->valid()) { if (c->obj() == phys) { if (EXPECT_FALSE(c->rights() == page_attribs)) return Insert_warn_exists; c->add_rights(page_attribs); return Insert_warn_attrib_upgrade; } else return Insert_err_exists; } c->set(phys, page_attribs); return Insert_ok; }
int Socket::send( const char* msg, size_t len, const Addr& dest, int flags, CheckingType check ) { if( check == DONT_CHECK ) { return ::sendto( getFD(), msg, #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) (int)len, #else len, #endif flags, (struct sockaddr *)&( dest.getAddr() ), sizeof( dest.getAddr() ) ); } else { for(;;) { int sent = ::sendto( getFD(), msg, #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) (int)len, #else len, #endif flags, (struct sockaddr *)&( dest.getAddr() ), sizeof( dest.getAddr() ) ); if( sent != -1 || ( errno != EINTR #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) && errno != WSAEWOULDBLOCK #else && errno != EWOULDBLOCK #endif ) ) return sent; } } }
T * Mem_space::user_to_kernel (T const *addr, bool write) { Phys_addr phys; Addr virt = Addr::create((Address) addr); unsigned attr, error = 0; Size size; for (;;) { // See if there is a mapping for this address if (v_lookup (virt, &phys, &size, &attr)) { // Add offset to frame phys = phys | virt.offset(size); // See if we want to write and are not allowed to // Generic check because INTEL_PTE_WRITE == INTEL_PDE_WRITE if (!write || (attr & Pt_entry::Writable)) return (T *) Mem_layout::phys_to_pmem (phys.value()); error |= PF_ERR_PRESENT; } if (write) error |= PF_ERR_WRITE; // If we tried to access user memory of a space other than current_mem_space() // our Long-IPC partner must do a page-in. This is analogue to IA32 // page-faulting in the IPC window. Set PF_ERR_REMTADDR hint. // Otherwise we faulted on our own user memory. Set PF_ERR_USERADDR hint. error |= (dir() == current_pdir() ? PF_ERR_USERADDR : PF_ERR_REMTADDR); // No mapping or insufficient access rights, raise pagefault. // Pretend open interrupts, we restore the current state afterwards. Cpu_lock::Status was_locked = cpu_lock.test(); thread_page_fault (virt.value(), error, 0, Proc::processor_state() | EFLAGS_IF, 0); cpu_lock.set (was_locked); } }
int SocketDgram::sharedOpen(const Addr& local, int protocolFamily) { bool error = false; if(local == Addr::sapAny) { if(protocolFamily == PF_INET) { if(bindport(this->getHandle(), INADDR_ANY, protocolFamily) == -1) error = true; } } else if(OS::bind(this->getHandle(), reinterpret_cast<sockaddr*> (local.getAddr()), local.getSize()) == -1) error = true; if(error) this->close(); return error ? -1:0; }
bool Socket::bind( const Addr& addr ) { if( isOpen() ) { int err = ::bind( getFD(), (struct sockaddr *)&( addr.getAddr() ), sizeof( addr.getAddr() ) ); #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) if( err == SOCKET_ERROR ) return false; #else if( err < 0 ) return false; #endif return true; } return false; }
std::size_t do_generate_successor_frame(net_link& link, const Addr& sucessor_address, boost::uint16_t sucessor_port) { successor_frame<Addr>* frame = buffer_cast<successor_frame<Addr>*>(link.send_buffer(sizeof(successor_frame<Addr>))); frame->type = connection::frame_successor; typename Addr::bytes_type peer_ip = sucessor_address.to_bytes(); std::memcpy(frame->sucessor_ip, peer_ip.data(), peer_ip.size()); u16(frame->sucessor_port, sucessor_port); return sizeof(successor_frame<Addr>); }
int SocketDgram::open (const Addr &local, int protocolFamily, int protocol, int reuseAddr) { if(local != Addr::sapAny) protocolFamily = local.getType(); else if (protocolFamily == PF_UNSPEC) protocolFamily = PF_INET; if(Socket::open(SOCK_DGRAM, protocolFamily, protocol, reuseAddr) == -1) return -1; else return this->sharedOpen(local, protocolFamily); }
bool Generic_obj_space<SPACE>::v_lookup(Addr const &virt, Phys_addr *phys = 0, Size *size = 0, unsigned *attribs = 0) { if (size) *size = Size::create(1); Entry *cap = get_cap(virt.value()); if (EXPECT_FALSE(!cap)) { if (size) *size = Size::create(Caps_per_page); return false; } Capability c = *cap; Obj::set_entry(virt, cap); if (phys) *phys = c.obj(); if (c.valid() && attribs) *attribs = cap->rights(); return c.valid(); }
// for messages InstrItem::InstrItem(InstrView* iv, QTreeWidget* parent, Addr addr, const QString& msg) : QTreeWidgetItem(parent) { _view = iv; _addr = addr; _instr = 0; _instrCall = 0; _instrJump = 0; _inside = false; setTextAlignment(0, Qt::AlignRight); setTextAlignment(1, Qt::AlignRight); setTextAlignment(2, Qt::AlignRight); setText(0, addr.pretty()); setText(6, msg); updateGroup(); updateCost(); }
Addr zero() { Addr zero; std::fill(zero.begin(), zero.end(), 0); return zero; }
void Socket::bind(const Addr& addr) { int err = ::bind(m_socket, (struct sockaddr *)&(addr.getAddr()), sizeof (addr.getAddr())); if(err < 0) throw BindErr(errno); }
void TestAddr::SetNullHostStr() { Addr a; CPPUNIT_ASSERT( !a.setHost( "" ) ); }