Fixed FreeBSD compatibility and added LOG_STACK