Skip to content

Commit

Permalink
Merge pull request #22771 from chouquette/chouquette/glibc_guard
Browse files Browse the repository at this point in the history
glibc: guard more function declarations
  • Loading branch information
alexrp authored Feb 7, 2025
2 parents 2d4954a + edee702 commit 8ad0732
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/libc/include/generic-glibc/bits/spawn_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
__END_DECLS
7 changes: 6 additions & 1 deletion lib/libc/include/generic-glibc/bits/statx-generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <bits/types/struct_statx_timestamp.h>
#include <bits/types/struct_statx.h>

// 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
Expand Down Expand Up @@ -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
__END_DECLS

#endif /* (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 28) || __GLIBC__ > 2 */
10 changes: 9 additions & 1 deletion lib/libc/include/generic-glibc/sys/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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

Expand All @@ -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;
Expand Down Expand Up @@ -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 */
#endif /* _SYS_MOUNT_H */
12 changes: 11 additions & 1 deletion lib/libc/include/generic-glibc/sys/pidfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include <fcntl.h>
#include <bits/types/siginfo_t.h>

// zig patch: check target glibc version
#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 36) || __GLIBC__ > 2

#define PIDFD_NONBLOCK O_NONBLOCK
#define PIDFD_THREAD O_EXCL

Expand All @@ -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 */
#endif /* (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 36) || __GLIBC__ > 2 */

#endif /* _PIDFD_H */
5 changes: 4 additions & 1 deletion lib/libc/include/generic-glibc/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -1203,13 +1203,16 @@ 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
encountered while closing file descriptors are ignored. Returns 0 on
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. */
Expand All @@ -1222,4 +1225,4 @@ extern int close_range (unsigned int __fd, unsigned int __max_fd,

__END_DECLS

#endif /* unistd.h */
#endif /* unistd.h */

0 comments on commit 8ad0732

Please sign in to comment.