diff --git a/changes/bug3894_more b/changes/bug3894_more
new file mode 100644
index 0000000000000000000000000000000000000000..4c2220aba8bd923a6b49da93f612bd47f52d3978
--- /dev/null
+++ b/changes/bug3894_more
@@ -0,0 +1,4 @@
+  o Build fixes:
+    - Clean up some code issues that prevented Tor from building on older
+      BSDs.  Fixes bug 3894; reported by grarpamp.
+      
diff --git a/configure.in b/configure.in
index 424cccb87472a1300573af7d58f3df29206907f3..df4c6f62b21d44268851a7e0a23f80b7c3bdc59f 100644
--- a/configure.in
+++ b/configure.in
@@ -417,6 +417,8 @@ dnl These headers are not essential
 
 AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/param.h sys/wait.h limits.h sys/limits.h netinet/in.h arpa/inet.h machine/limits.h syslog.h sys/time.h sys/resource.h inttypes.h utime.h sys/utime.h sys/mman.h netinet/in6.h malloc.h sys/syslimits.h malloc/malloc.h linux/types.h sys/file.h malloc_np.h sys/prctl.h)
 
+AC_CHECK_HEADERS(sys/param.h)
+
 TOR_CHECK_PROTOTYPE(malloc_good_size, HAVE_MALLOC_GOOD_SIZE_PROTOTYPE,
 [#ifdef HAVE_MALLOC_H
 #include <malloc.h>
diff --git a/src/common/compat.h b/src/common/compat.h
index d2f1fd12959a5ba267b14a768ef3cc5b57c62dd4..2c50ef154abc2a2f4e09428b343665b7271ff118 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -19,6 +19,9 @@
 #include <ws2tcpip.h>
 #endif
 #endif
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
diff --git a/src/common/torint.h b/src/common/torint.h
index 0b5c29adc009d7382fc2e14a972157e154710543..2a1ca3051eb2ea1f3891e2be7a3ee61879790df2 100644
--- a/src/common/torint.h
+++ b/src/common/torint.h
@@ -182,6 +182,16 @@ typedef unsigned __int64 uint64_t;
 #endif
 #endif
 
+#ifndef SIZE_MAX
+#if SIZEOF_SIZE_T == 8
+#define SIZE_MAX UINT64_MAX
+#elif  SIZEOF_SIZE_T == 4
+#define SIZE_MAX UINT32_MAX
+#else
+#error "Can't define SIZE_MAX"
+#endif
+#endif
+
 #ifndef HAVE_SSIZE_T
 #if SIZEOF_SIZE_T == 8
 typedef int64_t ssize_t;
diff --git a/src/common/util.c b/src/common/util.c
index a03a57632187c7ce6b9d3dc51425d2e344be3ad6..f0ca4cb3a8d1c229a30ebab8c31d5fb4f03d8202 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -77,7 +77,7 @@
 #include <malloc/malloc.h>
 #endif
 #ifdef HAVE_MALLOC_H
-#ifndef OPENBSD
+#if !defined(OPENBSD) && !defined(__FreeBSD__)
 /* OpenBSD has a malloc.h, but for our purposes, it only exists in order to
  * scold us for being so stupid as to autodetect its presence.  To be fair,
  * they've done this since 1996, when autoconf was only 5 years old. */