From 6c7de5aff91a7d28a462944da763b9b4c1760ae8 Mon Sep 17 00:00:00 2001
From: David CARLIER <devnexen@gmail.com>
Date: Sat, 29 Jan 2022 00:15:27 +0000
Subject: [PATCH] freebsd support update.

adding missing constants to fix warning at compile time.
providing tid fetching as well.
---
 include/tccdefs.h      | 5 +++++
 lib/bcheck.c           | 6 +++++-
 tests/tests2/46_grep.c | 3 +++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/tccdefs.h b/include/tccdefs.h
index 2d42bea..1bef382 100644
--- a/include/tccdefs.h
+++ b/include/tccdefs.h
@@ -91,6 +91,11 @@
 # if __SIZEOF_POINTER__ == 8
     /* FIXME, __int128_t is used by setjump */
     #define __int128_t struct { unsigned char _dummy[16] __attribute((aligned(16))); }
+    #define __SIZEOF_SIZE_T__ 8
+    #define __SIZEOF_PTRDIFF_T__ 8
+#else
+    #define __SIZEOF_SIZE_T__ 4
+    #define __SIZEOF_PTRDIFF_T__ 4
 # endif
 
 #elif defined __FreeBSD_kernel__
diff --git a/lib/bcheck.c b/lib/bcheck.c
index 0379b6e..8dabfba 100644
--- a/lib/bcheck.c
+++ b/lib/bcheck.c
@@ -228,7 +228,11 @@ typedef struct alloca_list_struct {
 #define BOUND_GET_TID    syscall (SYS_getthrid)
 #elif defined(__FreeBSD__) || defined(__NetBSD__)
 #define BOUND_TID_TYPE   pid_t
-#define BOUND_GET_TID    0
+#if defined(__FreeBSD__)
+#define BOUND_GET_TID    syscall (SYS_thr_self)
+#else
+#define BOUND_GET_TID    syscall (SYS_lwp_self)
+#endif
 #elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__riscv)
 #define BOUND_TID_TYPE   pid_t
 #define BOUND_GET_TID    syscall (SYS_gettid)
diff --git a/tests/tests2/46_grep.c b/tests/tests2/46_grep.c
index acda793..89fc0c1 100644
--- a/tests/tests2/46_grep.c
+++ b/tests/tests2/46_grep.c
@@ -14,6 +14,9 @@
  * included and reference made to  the  fact  that  reproduction
  * privileges were granted by DECUS.
  */
+#if defined(__FreeBSD__)
+#include <sys/cdefs.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>	// tolower()
-- 
2.34.1

