From 8e8d49e11772c5537a1cac8b5c04a85bc627a644 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 3 Jul 2023 21:28:03 +0000 Subject: [PATCH 1/7] minor() is in on BSDs src/direct/direct-export-buf.c:10:10: fatal error: 'sys/sysmacros.h' file not found #include ^~~~~~~~~~~~~~~~~ src/export-buf.c:11:10: fatal error: 'sys/sysmacros.h' file not found #include ^~~~~~~~~~~~~~~~~ --- src/direct/direct-export-buf.c | 2 ++ src/export-buf.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/direct/direct-export-buf.c b/src/direct/direct-export-buf.c index abc5e72..db9c5df 100644 --- a/src/direct/direct-export-buf.c +++ b/src/direct/direct-export-buf.c @@ -7,7 +7,9 @@ #include #include #include +#ifdef __linux__ #include +#endif #include #include "../backend-common.h" diff --git a/src/export-buf.c b/src/export-buf.c index b707985..c355726 100644 --- a/src/export-buf.c +++ b/src/export-buf.c @@ -8,7 +8,9 @@ #include #include #include +#ifdef __linux__ #include +#endif #include #include From 5dc46a5a2fab3e5351155e11465986d762276976 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 3 Jul 2023 21:28:14 +0000 Subject: [PATCH 2/7] Add BSD aliases for ioctl-related macros src/direct/nv-driver.c:46:30: error: use of undeclared identifier '_IOC_READ' int ret = ioctl(fd, _IOC(_IOC_READ|_IOC_WRITE, NV_IOCTL_MAGIC, NV_ESC_RM_ALLOC, size), &alloc); ^ src/direct/nv-driver.c:46:40: error: use of undeclared identifier '_IOC_WRITE' int ret = ioctl(fd, _IOC(_IOC_READ|_IOC_WRITE, NV_IOCTL_MAGIC, NV_ESC_RM_ALLOC, size), &alloc); ^ src/direct/nv-driver.c:80:30: error: use of undeclared identifier '_IOC_READ' int ret = ioctl(fd, _IOC(_IOC_READ|_IOC_WRITE, NV_IOCTL_MAGIC, NV_ESC_RM_FREE, sizeof(NVOS00_PARAMETERS)), &freeParams); ^ src/direct/nv-driver.c:80:40: error: use of undeclared identifier '_IOC_WRITE' int ret = ioctl(fd, _IOC(_IOC_READ|_IOC_WRITE, NV_IOCTL_MAGIC, NV_ESC_RM_FREE, sizeof(NVOS00_PARAMETERS)), &freeParams); ^ src/direct/nv-driver.c:100:30: error: use of undeclared identifier '_IOC_READ' int ret = ioctl(fd, _IOC(_IOC_READ|_IOC_WRITE, NV_IOCTL_MAGIC, NV_ESC_RM_CONTROL, sizeof(NVOS54_PARAMETERS)), &control); ^ src/direct/nv-driver.c:100:40: error: use of undeclared identifier '_IOC_WRITE' int ret = ioctl(fd, _IOC(_IOC_READ|_IOC_WRITE, NV_IOCTL_MAGIC, NV_ESC_RM_CONTROL, sizeof(NVOS54_PARAMETERS)), &control); ^ src/direct/nv-driver.c:138:30: error: use of undeclared identifier '_IOC_READ' int ret = ioctl(fd, _IOC(_IOC_READ|_IOC_WRITE, NV_IOCTL_MAGIC, NV_ESC_ATTACH_GPUS_TO_FD, sizeof(gpu)), &gpu); ^ src/direct/nv-driver.c:138:40: error: use of undeclared identifier '_IOC_WRITE' int ret = ioctl(fd, _IOC(_IOC_READ|_IOC_WRITE, NV_IOCTL_MAGIC, NV_ESC_ATTACH_GPUS_TO_FD, sizeof(gpu)), &gpu); ^ src/direct/nv-driver.c:170:30: error: use of undeclared identifier '_IOC_READ' int ret = ioctl(fd, _IOC(_IOC_READ|_IOC_WRITE, NV_IOCTL_MAGIC, NV_ESC_CHECK_VERSION_STR, sizeof(obj)), &obj); ^ src/direct/nv-driver.c:170:40: error: use of undeclared identifier '_IOC_WRITE' int ret = ioctl(fd, _IOC(_IOC_READ|_IOC_WRITE, NV_IOCTL_MAGIC, NV_ESC_CHECK_VERSION_STR, sizeof(obj)), &obj); ^ src/direct/nv-driver.c:183:34: error: use of undeclared identifier '_IOC_READ' int ret = ioctl(nv0_fd, _IOC(_IOC_READ|_IOC_WRITE, NV_IOCTL_MAGIC, NV_ESC_REGISTER_FD, sizeof(int)), &nvctl_fd); ^ src/direct/nv-driver.c:183:44: error: use of undeclared identifier '_IOC_WRITE' int ret = ioctl(nv0_fd, _IOC(_IOC_READ|_IOC_WRITE, NV_IOCTL_MAGIC, NV_ESC_REGISTER_FD, sizeof(int)), &nvctl_fd); ^ --- src/direct/nv-driver.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/direct/nv-driver.c b/src/direct/nv-driver.c index ad6c267..0c6ca36 100644 --- a/src/direct/nv-driver.c +++ b/src/direct/nv-driver.c @@ -15,6 +15,14 @@ #include #include "../vabackend.h" +#if !defined(_IOC_READ) && defined(IOC_OUT) +#define _IOC_READ IOC_OUT +#endif + +#if !defined(_IOC_WRITE) && defined(IOC_IN) +#define _IOC_WRITE IOC_IN +#endif + static const NvHandle NULL_OBJECT; static bool nv_alloc_object(int fd, int driverMajorVersion, NvHandle hRoot, NvHandle hObjectParent, NvHandle* hObjectNew, From 22be7754bee53a77a7dfaeaafc7709866e17a6cd Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 3 Jul 2023 21:28:24 +0000 Subject: [PATCH 3/7] Add comparison function typedef for qsort_r on non-glibc systems src/hevc.c:237:90: error: use of undeclared identifier '__compar_d_fn_t' qsort_r(ppc->RefPicSetStCurrBefore, ppc->NumPocStCurrBefore, sizeof(unsigned char), (__compar_d_fn_t) sortFuncRev, ppc->PicOrderCntVal); ^ src/hevc.c:238:88: error: use of undeclared identifier '__compar_d_fn_t' qsort_r(ppc->RefPicSetStCurrAfter, ppc->NumPocStCurrAfter, sizeof(unsigned char), (__compar_d_fn_t) sortFunc, ppc->PicOrderCntVal); ^ --- src/hevc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hevc.c b/src/hevc.c index 01fc071..7d95226 100644 --- a/src/hevc.c +++ b/src/hevc.c @@ -3,6 +3,10 @@ #include "vabackend.h" #include +#if !defined(__GLIBC__) +typedef int (*__compar_d_fn_t) (const void *, const void *, void *); +#endif + static const uint8_t ff_hevc_diag_scan4x4_x[16] = { 0, 0, 1, 0, 1, 2, 0, 1, From 119a5a3ac448fc5d53e4167007c04a118d1192da Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 3 Jul 2023 22:39:47 +0000 Subject: [PATCH 4/7] Add qsort_r workaround for FreeBSD < 14 src/hevc.c:241:120: error: incompatible pointer types passing 'int [16]' to parameter of type 'int (*)(void *, const void *, const void *)' [-Werror,-Wincompatible-pointer-types] qsort_r(ppc->RefPicSetStCurrBefore, ppc->NumPocStCurrBefore, sizeof(unsigned char), (__compar_d_fn_t) sortFuncRev, ppc->PicOrderCntVal); ^~~~~~~~~~~~~~~~~~~ /usr/include/stdlib.h:308:12: note: passing argument to parameter here int (*)(void *, const void *, const void *)); ^ src/hevc.c:242:115: error: incompatible pointer types passing 'int [16]' to parameter of type 'int (*)(void *, const void *, const void *)' [-Werror,-Wincompatible-pointer-types] qsort_r(ppc->RefPicSetStCurrAfter, ppc->NumPocStCurrAfter, sizeof(unsigned char), (__compar_d_fn_t) sortFunc, ppc->PicOrderCntVal); ^~~~~~~~~~~~~~~~~~~ /usr/include/stdlib.h:308:12: note: passing argument to parameter here int (*)(void *, const void *, const void *)); ^ --- src/hevc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/hevc.c b/src/hevc.c index 7d95226..c4cf7ad 100644 --- a/src/hevc.c +++ b/src/hevc.c @@ -5,6 +5,12 @@ #if !defined(__GLIBC__) typedef int (*__compar_d_fn_t) (const void *, const void *, void *); +#if defined(__FreeBSD__) && __FreeBSD__ < 14 +// https://github.com/freebsd/freebsd-src/commit/af3c78886fd8 +typedef int (*__old_compar_d_fn_t) (void *, const void *, const void *); +#define qsort_r(base, nmemb, size, compar, thunk) \ + qsort_r(base, nmemb, size, thunk, (__old_compar_d_fn_t)compar) +#endif #endif static const uint8_t ff_hevc_diag_scan4x4_x[16] = { From 39c08a61a888c5d233927f4548baf29bddab2ca4 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 3 Jul 2023 21:29:08 +0000 Subject: [PATCH 5/7] Add FreeBSD header for pthread_timedjoin_np() src/vabackend.c:302:15: warning: call to undeclared function 'pthread_timedjoin_np'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] int ret = pthread_timedjoin_np(nvCtx->resolveThread, NULL, &timeout); ^ --- src/vabackend.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/vabackend.c b/src/vabackend.c index 5376a57..8608628 100644 --- a/src/vabackend.c +++ b/src/vabackend.c @@ -29,6 +29,14 @@ #define __has_builtin(x) 0 #endif +#ifndef __has_include +#define __has_include(x) 0 +#endif + +#if __has_include() +#include +#endif + static pthread_mutex_t concurrency_mutex = PTHREAD_MUTEX_INITIALIZER; static uint32_t instances; static uint32_t max_instances; From fc1afd905f8c33df0354f4232d834f379a5d694f Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 3 Jul 2023 21:29:13 +0000 Subject: [PATCH 6/7] Add FreeBSD alias for gettid() src/vabackend.c:174:98: warning: call to undeclared function 'gettid'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] fprintf(LOG_OUTPUT, "%10ld.%09ld [%d-%d] %s:%4d %24s %s\n", tp.tv_sec, tp.tv_nsec, getpid(), gettid(), filename, line, function, formattedMessage); ^ ld: error: undefined symbol: gettid >>> referenced by vabackend.c:182 (src/vabackend.c:182) >>> nvidia_drv_video.so.p/src_vabackend.c.o:(logger) See also https://github.com/intel/libva/blob/2.18.0/va/va_trace.c#L72-L91 --- src/vabackend.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vabackend.c b/src/vabackend.c index 8608628..da6971b 100644 --- a/src/vabackend.c +++ b/src/vabackend.c @@ -35,6 +35,7 @@ #if __has_include() #include +#define gettid pthread_getthreadid_np #endif static pthread_mutex_t concurrency_mutex = PTHREAD_MUTEX_INITIALIZER; From 97430842d11ac55d68284238aa193be9f6bbb0b6 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 3 Jul 2023 22:55:04 +0000 Subject: [PATCH 7/7] Cast 32-bit time_t on FreeBSD i386 src/vabackend.c:183:65: error: format specifies type 'long' but the argument has type 'time_t' (aka 'int') [-Werror,-Wformat] fprintf(LOG_OUTPUT, "%10ld.%09ld [%d-%d] %s:%4d %24s %s\n", tp.tv_sec, tp.tv_nsec, getpid(), gettid(), filename, line, function, formattedMessage); ~~~~~ ^~~~~~~~~ %10d --- src/vabackend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vabackend.c b/src/vabackend.c index da6971b..a915df4 100644 --- a/src/vabackend.c +++ b/src/vabackend.c @@ -180,7 +180,7 @@ void logger(const char *filename, const char *function, int line, const char *ms struct timespec tp; clock_gettime(CLOCK_MONOTONIC, &tp); - fprintf(LOG_OUTPUT, "%10ld.%09ld [%d-%d] %s:%4d %24s %s\n", tp.tv_sec, tp.tv_nsec, getpid(), gettid(), filename, line, function, formattedMessage); + fprintf(LOG_OUTPUT, "%10ld.%09ld [%d-%d] %s:%4d %24s %s\n", (long)tp.tv_sec, tp.tv_nsec, getpid(), gettid(), filename, line, function, formattedMessage); fflush(LOG_OUTPUT); }