0xFireWolf / RealtekCardReader

An unofficial Realtek PCIe/USB-based SD card reader driver for macOS
BSD 3-Clause "New" or "Revised" License
182 stars 18 forks source link

IOMallocZero breaks 10.14 compatibility #11

Closed reelgirly closed 2 years ago

reelgirly commented 2 years ago

First thanks for the great project :)

But implementation of IOMallocZero breaks compatibility with macOS 10.14 :/

2021-09-09 15:37:37.620042+0200 0x31c Default 0x0 0 0 kernel: kxld[science.firewolf.rtsx]: The following symbols are unresolved for this kext: 2021-09-09 15:37:37.620070+0200 0x31c Default 0x0 0 0 kernel: kxld[science.firewolf.rtsx]: _IOMallocZero 2021-09-09 15:37:37.621031+0200 0x31c Default 0x0 0 0 kernel: Can't load kext science.firewolf.rtsx - link failed. 2021-09-09 15:37:37.621326+0200 0x31c Default 0x0 0 0 kernel: Failed to load executable for kext science.firewolf.rtsx. 2021-09-09 15:37:37.621425+0200 0x31c Default 0x0 0 0 kernel: Kext science.firewolf.rtsx failed to load (0xdc008016). 2021-09-09 15:37:37.621428+0200 0x31c Default 0x0 0 0 kernel: Failed to load kext science.firewolf.rtsx (error 0xdc008016).

Perhaps u can replace it somehow...

Meanwhile i simply replaced to IOMallocZero and IOMalloc in Debug.hpp:

static inline void pbuf(IOMemoryDescriptor* descriptor, size_t length, size_t column = 8)
{
    auto buffer = IOMalloc(length);

    psoftassert(descriptor->readBytes(0, buffer, length) == length, "Failed to read the memory descriptor contents.");

    pbuf(buffer, length, column);

    IOFree(buffer, length);
}

static inline void pdma(IODMACommand* dma, IOByteCount length, IOByteCount column)
{
    auto buffer = IOMalloc(length);

    psoftassert(dma->readBytes(0, buffer, length) == length, "Failed to read the DMA contents.");

    pbuf(buffer, length, column);

    IOFree(buffer, length);
}

and in IOEnhancedCommandPool.hpp IONewZero and IONew to:

private:
    ///
    /// Setup the storage for preallocated commands
    ///
    /// @param capacity The number of preallocated commands
    /// @return `true` on success, `false` otherwise.
    ///
    bool setupStorage(IOItemCount capacity)
    {
        this->commands = IONew(Command*, capacity);

        this->capacity = capacity;

        return this->commands != nullptr;
    }

not sure if it breaks something, but for me it works :D

0xFireWolf commented 2 years ago

Indeed. These functions are available on macOS Catalina and later. Resolved by the commit https://github.com/0xFireWolf/RealtekCardReader/commit/4611a7fa737e4f74dd3c63d0808abb510b161ea6. Thank you.