--- nono/vm/ethernet.cpp 2026/04/29 17:05:38 1.1.1.10 +++ nono/vm/ethernet.cpp 2026/04/29 17:05:46 1.1.1.12 @@ -24,7 +24,7 @@ EthernetDevice::EthernetDevice(uint obji EthernetDevice::~EthernetDevice() { if ((bool)hostnet) { - hostnet->SetRxCallback(NULL); + hostnet->ResetRxCallback(); } } @@ -32,18 +32,26 @@ EthernetDevice::~EthernetDevice() bool EthernetDevice::Create() { - // ホストドライバを作成してこのデバイスと紐付ける + // ホストドライバを作成してこのデバイスと紐付ける。 + // ポート名は継承先ごとに Init() で設定している。 int n = GetId() - OBJ_ETHERNET0; - hostnet.reset(new HostNetDevice(this, n)); + try { + hostnet.reset(new HostNetDevice(this, n, "")); + } catch (...) { } + if ((bool)hostnet == false) { + warnx("Failed to initialize HostNetDevice(%u) at %s", n, __method__); + return false; + } - hostnet->SetRxCallback(ToDeviceCallback(&EthernetDevice::HostRxCallback)); + auto func = ToDeviceCallback(&EthernetDevice::HostRxCallback); + hostnet->SetRxCallback(func, 0); return true; } // これは Host スレッドから呼ばれる void -EthernetDevice::HostRxCallback() +EthernetDevice::HostRxCallback(uint32 dummy) { // スレッドを超えるためにメッセージを投げる int n = GetId() - OBJ_ETHERNET0; @@ -129,11 +137,10 @@ EthernetDevice::CRC32(const uint8 *buf, static const uint32 CRC_POLY = 0x04c11db6; uint32 crc; uint32 cy; - uint32 s; crc = 0xffffffff; for (size_t i = 0; i < buflen; i++) { - s = buf[i]; + uint32 s = buf[i]; for (size_t j = 0; j < 8; j++) { cy = ((crc & 0x80000000U) ? 0x01 : 0x00) ^ (s & 0x01); crc <<= 1; @@ -154,12 +161,11 @@ EthernetDevice::CRC32(const MacAddr& mac { static const uint32 CRC_POLY = 0x04c11db6; uint32 crc; - uint32 cy; uint64 s = mac.Get(); crc = 0xffffffff; for (size_t i = 0; i < mac.size() * 8; i++) { - cy = ((crc & 0x80000000U) ? 0x01 : 0x00) ^ (s & 0x01); + uint32 cy = ((crc & 0x80000000U) ? 0x01 : 0x00) ^ (s & 0x01); crc <<= 1; s >>= 1; if (cy) {