C++ version, based on linux kernel implementation.