moved utility function to kernelport.h