From fdef5c564d0ec96b187b43825d485a33ed52c3c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Wed, 5 Feb 2025 12:02:26 +0100 Subject: [PATCH 1/5] generic glibc: guard close_range declaration It is only available starting from glibc 2.34 --- lib/libc/include/generic-glibc/unistd.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/libc/include/generic-glibc/unistd.h b/lib/libc/include/generic-glibc/unistd.h index 8688f6c445..47628dea65 100644 --- a/lib/libc/include/generic-glibc/unistd.h +++ b/lib/libc/include/generic-glibc/unistd.h @@ -1203,6 +1203,8 @@ int getentropy (void *__buffer, size_t __length) __wur #endif #ifdef __USE_GNU +// zig patch: check target glibc version +# if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 34) || __GLIBC__ > 2 /* Close all file descriptors in the range FD up to MAX_FD. The flag FLAGS are define by the CLOSE_RANGE prefix. This function behaves like close on the range and gaps where the file descriptor is invalid or errors @@ -1210,6 +1212,7 @@ int getentropy (void *__buffer, size_t __length) __wur successor or -1 for failure (and sets errno accordingly). */ extern int close_range (unsigned int __fd, unsigned int __max_fd, int __flags) __THROW; +# endif #endif /* Define some macros helping to catch buffer overflows. */ @@ -1222,4 +1225,4 @@ extern int close_range (unsigned int __fd, unsigned int __max_fd, __END_DECLS -#endif /* unistd.h */ \ No newline at end of file +#endif /* unistd.h */ From 5d2584e53ebefa2727b880ad62e148e016f9860b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Wed, 5 Feb 2025 13:54:17 +0100 Subject: [PATCH 2/5] generic glibc: guard statx declaration It was added in glibc 2.28 --- lib/libc/include/generic-glibc/bits/statx-generic.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/libc/include/generic-glibc/bits/statx-generic.h b/lib/libc/include/generic-glibc/bits/statx-generic.h index 8667c801b2..8f35017d1c 100644 --- a/lib/libc/include/generic-glibc/bits/statx-generic.h +++ b/lib/libc/include/generic-glibc/bits/statx-generic.h @@ -25,6 +25,9 @@ #include #include +// zig patch: check target glibc version +#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 28) || __GLIBC__ > 2 + #ifndef STATX_TYPE # define STATX_TYPE 0x0001U # define STATX_MODE 0x0002U @@ -63,4 +66,6 @@ int statx (int __dirfd, const char *__restrict __path, int __flags, unsigned int __mask, struct statx *__restrict __buf) __THROW __nonnull ((2, 5)); -__END_DECLS \ No newline at end of file +__END_DECLS + +#endif /* (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 28) || __GLIBC__ > 2 */ From e716d135557106410cdd46f01b865eaab3938fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Wed, 5 Feb 2025 14:23:00 +0100 Subject: [PATCH 3/5] generic glibc: guard definitions of functions introduced in 2.36 --- lib/libc/include/generic-glibc/sys/mount.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/libc/include/generic-glibc/sys/mount.h b/lib/libc/include/generic-glibc/sys/mount.h index 0fdc9f3ad0..8f17a7bb09 100644 --- a/lib/libc/include/generic-glibc/sys/mount.h +++ b/lib/libc/include/generic-glibc/sys/mount.h @@ -235,6 +235,8 @@ struct mount_attr #define FSPICK_NO_AUTOMOUNT 0x00000004 #define FSPICK_EMPTY_PATH 0x00000008 +// zig patch: check target glibc version +#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 36) || __GLIBC__ > 2 #ifndef FSOPEN_CLOEXEC /* The type of fsconfig call made. */ @@ -268,6 +270,7 @@ enum fsconfig_command #define OPEN_TREE_CLONE 1 /* Clone the target tree and attach the clone */ #define OPEN_TREE_CLOEXEC O_CLOEXEC /* Close the file on execve() */ +#endif __BEGIN_DECLS @@ -282,6 +285,9 @@ extern int umount (const char *__special_file) __THROW; /* Unmount a filesystem. Force unmounting if FLAGS is set to MNT_FORCE. */ extern int umount2 (const char *__special_file, int __flags) __THROW; +// zig patch: check target glibc version +#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 36) || __GLIBC__ > 2 + /* Open the filesystem referenced by FS_NAME so it can be configured for mouting. */ extern int fsopen (const char *__fs_name, unsigned int __flags) __THROW; @@ -320,6 +326,8 @@ extern int mount_setattr (int __dfd, const char *__path, unsigned int __flags, struct mount_attr *__uattr, size_t __usize) __THROW; +#endif /* (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 36) || __GLIBC__ > 2 */ + __END_DECLS -#endif /* _SYS_MOUNT_H */ \ No newline at end of file +#endif /* _SYS_MOUNT_H */ From 9d85c79f2f09c3db578cc145392099d901986eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Wed, 5 Feb 2025 14:24:09 +0100 Subject: [PATCH 4/5] generic glibc: guard pidfd function declarations They were introduced in 2.36 & 2.39 --- lib/libc/include/generic-glibc/sys/pidfd.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/libc/include/generic-glibc/sys/pidfd.h b/lib/libc/include/generic-glibc/sys/pidfd.h index addf5eec7c..ca981c3ad5 100644 --- a/lib/libc/include/generic-glibc/sys/pidfd.h +++ b/lib/libc/include/generic-glibc/sys/pidfd.h @@ -21,6 +21,9 @@ #include #include +// zig patch: check target glibc version +#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 36) || __GLIBC__ > 2 + #define PIDFD_NONBLOCK O_NONBLOCK #define PIDFD_THREAD O_EXCL @@ -45,8 +48,15 @@ extern int pidfd_getfd (int __pidfd, int __targetfd, extern int pidfd_send_signal (int __pidfd, int __sig, siginfo_t *__info, unsigned int __flags) __THROW; +#endif /* (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 36) || __GLIBC__ > 2 */ + +// zig patch: check target glibc version +#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 39) || __GLIBC__ > 2 + /* Query the process ID (PID) from process descriptor FD. Return the PID or -1 in case of an error. */ extern pid_t pidfd_getpid (int __fd) __THROW; -#endif /* _PIDFD_H */ \ No newline at end of file +#endif /* (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 36) || __GLIBC__ > 2 */ + +#endif /* _PIDFD_H */ From edee702a7fb48859d3bc58628617646439fc066f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Thu, 6 Feb 2025 10:00:48 +0100 Subject: [PATCH 5/5] generic glibc: guard pidfd_spawn(p) declarations --- lib/libc/include/generic-glibc/bits/spawn_ext.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/libc/include/generic-glibc/bits/spawn_ext.h b/lib/libc/include/generic-glibc/bits/spawn_ext.h index 7955fd9f03..b396316575 100644 --- a/lib/libc/include/generic-glibc/bits/spawn_ext.h +++ b/lib/libc/include/generic-glibc/bits/spawn_ext.h @@ -35,6 +35,8 @@ extern int posix_spawnattr_setcgroup_np (posix_spawnattr_t *__attr, int __cgroup) __THROW __nonnull ((1)); +// zig patch: check target glibc version +#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 39) || __GLIBC__ > 2 /* Spawn a new process executing PATH with the attributes describes in *ATTRP. Before running the process perform the actions described in FACTS. Return a PID file descriptor in PIDFD if process creation was successful and the @@ -61,7 +63,8 @@ extern int pidfd_spawnp (int *__restrict __pidfd, char *const __argv[__restrict_arr], char *const __envp[__restrict_arr]) __nonnull ((1, 2, 5)); +#endif /* (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 39) || __GLIBC__ > 2 */ #endif /* __USE_MISC */ -__END_DECLS \ No newline at end of file +__END_DECLS