On Sun, Feb 19, 2023 at 11:47:47AM -0700, Theo de Raadt wrote: > The question remains: why the upstream doing that. > > Sometihng is missing here, and it may not just be mechanical.
Yes, one thing they do is wrap around mmap, but with little effect on OpenBSD afaict. > Klemens Nanni <[email protected]> wrote: > > > Still waiting for pkg_add and then my build to finish, but the idea is > > > > - make the existing maros NO-OPs, align with spaces to make it obvious > > - remove includes/defines to break any left-over syscalls This diff builds and packages without WANTLIB or PLIST change. Still WIP, but the initial nheko __syscall crash is gone. The code linked above shows one of the removed hunks around their MMAP2_PAGE_SHIFT hussle. Upstream always defines it as 0 on OpenBSD anyway, so nothing is shifted and the one check is removed as it can never be true: if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) { Now I get another crash on nheko startup inside Qt5, but that looks unrelated to v4l: Core was generated by `nheko'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x0000012acec6b8e7 in QQuickTextPrivate::setupTextLayout(double*) () from /usr/local/lib/qt5/./libQt5Quick.so.5.0 Index: Makefile =================================================================== RCS file: /cvs/ports/multimedia/libv4l/Makefile,v retrieving revision 1.29 diff -u -p -r1.29 Makefile --- Makefile 2 Sep 2022 09:42:27 -0000 1.29 +++ Makefile 19 Feb 2023 18:19:57 -0000 @@ -3,7 +3,7 @@ COMMENT = libv4l userspace library VERSION = 1.20.0 DISTNAME = v4l-utils-${VERSION} PKGNAME = libv4l-${VERSION} -REVISION = 2 +REVISION = 3 SHARED_LIBS += v4l1 0.0 # 0.0 SHARED_LIBS += v4l2 0.0 # 0.0 Index: patches/patch-lib_libv4l-mplane_libv4l-mplane_c =================================================================== RCS file: patches/patch-lib_libv4l-mplane_libv4l-mplane_c diff -N patches/patch-lib_libv4l-mplane_libv4l-mplane_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-lib_libv4l-mplane_libv4l-mplane_c 19 Feb 2023 18:37:13 -0000 @@ -0,0 +1,20 @@ +Stub out SYS_* macros to use syscalls directly not syscall(2) + +Index: lib/libv4l-mplane/libv4l-mplane.c +--- lib/libv4l-mplane/libv4l-mplane.c.orig ++++ lib/libv4l-mplane/libv4l-mplane.c +@@ -36,11 +36,11 @@ + #include "libv4l-plugin.h" + + #define SYS_IOCTL(fd, cmd, arg) \ +- syscall(SYS_ioctl, (int)(fd), (unsigned long)(cmd), (void *)(arg)) ++ ioctl(fd, cmd, arg) + #define SYS_READ(fd, buf, len) \ +- syscall(SYS_read, (int)(fd), (void *)(buf), (size_t)(len)); ++ read(fd, buf, len) + #define SYS_WRITE(fd, buf, len) \ +- syscall(SYS_write, (int)(fd), (const void *)(buf), (size_t)(len)); ++ write(fd, buf, len) + + + #if HAVE_VISIBILITY Index: patches/patch-lib_libv4l1_libv4l1_c =================================================================== RCS file: patches/patch-lib_libv4l1_libv4l1_c diff -N patches/patch-lib_libv4l1_libv4l1_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-lib_libv4l1_libv4l1_c 19 Feb 2023 18:37:13 -0000 @@ -0,0 +1,14 @@ +Use dup(2) not syscall(2) + +Index: lib/libv4l1/libv4l1.c +--- lib/libv4l1/libv4l1.c.orig ++++ lib/libv4l1/libv4l1.c +@@ -472,7 +472,7 @@ int v4l1_dup(int fd) + int index = v4l1_get_index(fd); + + if (index == -1) +- return syscall(SYS_dup, fd); ++ return dup(fd); + + devices[index].open_count++; + Index: patches/patch-lib_libv4l2_libv4l2_c =================================================================== RCS file: patches/patch-lib_libv4l2_libv4l2_c diff -N patches/patch-lib_libv4l2_libv4l2_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-lib_libv4l2_libv4l2_c 19 Feb 2023 19:09:49 -0000 @@ -0,0 +1,26 @@ +Use dup(2) not syscall(2) + +Index: lib/libv4l2/libv4l2.c +--- lib/libv4l2/libv4l2.c.orig ++++ lib/libv4l2/libv4l2.c +@@ -880,7 +880,7 @@ int v4l2_dup(int fd) + int index = v4l2_get_index(fd); + + if (index == -1) +- return syscall(SYS_dup, fd); ++ return dup(fd); + + devices[index].open_count++; + +@@ -1635,11 +1635,6 @@ void *v4l2_mmap(void *start, size_t length, int prot, + if (index != -1) + V4L2_LOG("Passing mmap(%p, %d, ..., %x, through to the driver\n", + start, (int)length, (int)offset); +- +- if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) { +- errno = EINVAL; +- return MAP_FAILED; +- } + + return (void *)SYS_MMAP(start, length, prot, flags, fd, offset); + } Index: patches/patch-lib_libv4lconvert_libv4lsyscall-priv_h =================================================================== RCS file: patches/patch-lib_libv4lconvert_libv4lsyscall-priv_h diff -N patches/patch-lib_libv4lconvert_libv4lsyscall-priv_h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-lib_libv4lconvert_libv4lsyscall-priv_h 19 Feb 2023 19:09:49 -0000 @@ -0,0 +1,65 @@ +Stub out SYS_* macros to use syscalls directly not syscall(2) + +Index: lib/libv4lconvert/libv4lsyscall-priv.h +--- lib/libv4lconvert/libv4lsyscall-priv.h.orig ++++ lib/libv4lconvert/libv4lsyscall-priv.h +@@ -64,12 +64,8 @@ + #endif + + #if defined(__OpenBSD__) +-#include <sys/syscall.h> +-#include <sys/types.h> +-#include <sys/ioctl.h> + #define _IOC_NR(cmd) ((cmd) & 0xFF) + #define _IOC_TYPE(cmd) IOCGROUP(cmd) +-#define MMAP2_PAGE_SHIFT 0 + #endif + + #undef SYS_OPEN +@@ -84,19 +80,19 @@ + + #ifdef SYS_openat + #define SYS_OPEN(file, oflag, mode) \ +- syscall(SYS_openat, AT_FDCWD, (const char *)(file), (int)(oflag), (mode_t)(mode)) ++ open(file, oflag, mode) + #else + #define SYS_OPEN(file, oflag, mode) \ +- syscall(SYS_open, (const char *)(file), (int)(oflag), (mode_t)(mode)) ++ open(file, oflag, mode) + #endif + #define SYS_CLOSE(fd) \ +- syscall(SYS_close, (int)(fd)) ++ close(fd) + #define SYS_IOCTL(fd, cmd, arg) \ +- syscall(SYS_ioctl, (int)(fd), (unsigned long)(cmd), (void *)(arg)) ++ ioctl(fd, cmd, arg) + #define SYS_READ(fd, buf, len) \ +- syscall(SYS_read, (int)(fd), (void *)(buf), (size_t)(len)); ++ read(fd, buf, len) + #define SYS_WRITE(fd, buf, len) \ +- syscall(SYS_write, (int)(fd), (const void *)(buf), (size_t)(len)); ++ write(fd, buf, len) + + #if defined(__FreeBSD__) + #define SYS_MMAP(addr, len, prot, flags, fd, off) \ +@@ -107,10 +103,8 @@ + syscall(SYS_mmap, (void *)(addr), (size_t)(len), \ + (int)(prot), (int)(flags), (int)(fd), (off_t)(off)) + #elif defined(__OpenBSD__) +-register_t __syscall(quad_t, ...); + #define SYS_MMAP(addr, len, prot, flags, fd, offset) \ +- __syscall((quad_t)SYS_mmap, (void *)(addr), (size_t)(len), \ +- (int)(prot), (int)(flags), (int)(fd), 0, (off_t)(offset)) ++ mmap(addr, len, prot, flags, fd, offset) + #else + #define SYS_MMAP(addr, len, prot, flags, fd, off) \ + syscall(SYS_mmap2, (void *)(addr), (size_t)(len), \ +@@ -118,7 +112,7 @@ register_t __syscall(quad_t, ...); + #endif + + #define SYS_MUNMAP(addr, len) \ +- syscall(SYS_munmap, (void *)(addr), (size_t)(len)) ++ munmap(addr, len) + + #else +
