On 25/11/2021 14:33, Dillon Min wrote: > Hi Hans, > > On Thu, 25 Nov 2021 at 21:14, Hans Verkuil <hverkuil-cisco@xxxxxxxxx> wrote: >> >> Check if the OS has an MMU. If not, then skip tests that only work for >> systems that have an MMU. >> >> The safest and most generic method I found is the FIONBIO ioctl that is >> available for any file descriptor and is a write-only ioctl, so no memory >> will be accidentally written. On a MMU system this will return EFAULT, and >> on a ucLinux system this will return 0. >> >> Signed-off-by: Hans Verkuil <hverkuil-cisco@xxxxxxxxx> >> --- >> Dillon, the original RFC patch (1) I posted to fix this in the kernel is not >> the correct method. See: >> >> https://stackoverflow.com/questions/24755103/how-to-handle-null-pointer-argument-to-ioctl-system-call > > Thanks for the detailed information. > >> >> So instead I try to detect if there is an MMU in v4l2-compliance and, if not, >> just skip those tests that require an MMU. >> >> Can you test this patch? > > Sure, I'll test it then update the result. Note that v4l2-compliance should say at the top that it detects a no-MMU system: >> @@ -152,8 +153,21 @@ static struct option long_options[] = { >> >> static void print_sha() >> { >> + int fd = open("/dev/null", O_RDONLY); >> + >> + if (fd >= 0) { >> + // FIONBIO is a write-only ioctl that takes an int argument that >> + // enables (!= 0) or disables (== 0) nonblocking mode of a fd. >> + // >> + // Passing a nullptr should return EFAULT on MMU capable machines, >> + // and it works if there is no MMU. >> + has_mmu = ioctl(fd, FIONBIO, nullptr); >> + close(fd); >> + } >> printf("v4l2-compliance %s%s, ", PACKAGE_VERSION, STRING(GIT_COMMIT_CNT)); >> - printf("%zd bits, %zd-bit time_t\n", sizeof(void *) * 8, sizeof(time_t) * 8); >> + printf("%zd bits, %zd-bit time_t%s\n", >> + sizeof(void *) * 8, sizeof(time_t) * 8, >> + has_mmu ? "" : ", has no MMU"); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Please verify that it actually does that. I hope it does :-) Regards, Hans >> if (strlen(STRING(GIT_SHA))) >> printf("v4l2-compliance SHA: %s %s\n", >> STRING(GIT_SHA), STRING(GIT_COMMIT_DATE));