# Linux Kernel Module Cheat
The perfect emulation setup to study and develop the <<linux-kernel>> v5.9.2, kernel modules, <<qemu-buildroot-setup,QEMU>>, <<gem5-buildroot-setup,gem5>> and x86_64, ARMv7 and ARMv8 <<userland-assembly,userland>> and <<baremetal-setup,baremetal>> assembly, <<c,ANSI C>>, <<cpp,C++>> and <<posix,POSIX>>. <<gdb>> and <<kgdb>> just work. Powered by <<about-the-qemu-buildroot-setup,Buildroot>> and <<about-the-baremetal-setup,crosstool-NG>>. Highly automated. Thoroughly documented. Automated <<test-this-repo,tests>>.

##### 24.22.6.2. gem5 `ThreadState`

Owned one per `ThreadContext`.

Many `ThreadContext` methods simply forward to `ThreadState` implementations.

`SimpleThread` inherits from `ThreadState`, and forwards to it on several methods e.g.:

        int cpuId() const override { return ThreadState::cpuId(); }
        uint32_t socketId() const override { return ThreadState::socketId(); }
        int threadId() const override { return ThreadState::threadId(); }
        void setThreadId(int id) override { ThreadState::setThreadId(id); }
        ContextID contextId() const override { return ThreadState::contextId(); }
        void setContextId(ContextID id) override { ThreadState::setContextId(id); }

`O3ThreadContext` on the other hand contains an `O3ThreadState`:

    template <class Impl>
    struct O3ThreadState : public ThreadState

at:

    template <class Impl>
    class O3ThreadContext : public ThreadContext
    {
        O3ThreadState<Impl> *thread

        ContextID contextId() const override { return thread->contextId(); }

        void setContextId(ContextID id) override { thread->setContextId(id); }