Partly integrated with linux kernel's list.h