Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef GIT_COMPAT_UTIL_H
0003 #define GIT_COMPAT_UTIL_H
0004 
0005 #define _BSD_SOURCE 1
0006 /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
0007 #define _DEFAULT_SOURCE 1
0008 
0009 #include <fcntl.h>
0010 #include <stdbool.h>
0011 #include <stddef.h>
0012 #include <linux/compiler.h>
0013 #include <sys/types.h>
0014 #ifndef __cplusplus
0015 #include <internal/cpumap.h>
0016 #endif
0017 
0018 /* General helper functions */
0019 void usage(const char *err) __noreturn;
0020 void die(const char *err, ...) __noreturn __printf(1, 2);
0021 
0022 struct dirent;
0023 struct strlist;
0024 
0025 int mkdir_p(char *path, mode_t mode);
0026 int rm_rf(const char *path);
0027 int rm_rf_perf_data(const char *path);
0028 struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
0029 bool lsdir_no_dot_filter(const char *name, struct dirent *d);
0030 
0031 size_t hex_width(u64 v);
0032 
0033 int sysctl__max_stack(void);
0034 
0035 bool sysctl__nmi_watchdog_enabled(void);
0036 
0037 int fetch_kernel_version(unsigned int *puint,
0038              char *str, size_t str_sz);
0039 #define KVER_VERSION(x)     (((x) >> 16) & 0xff)
0040 #define KVER_PATCHLEVEL(x)  (((x) >> 8) & 0xff)
0041 #define KVER_SUBLEVEL(x)    ((x) & 0xff)
0042 #define KVER_FMT    "%d.%d.%d"
0043 #define KVER_PARAM(x)   KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
0044 
0045 int perf_tip(char **strp, const char *dirpath);
0046 
0047 #ifndef HAVE_SCHED_GETCPU_SUPPORT
0048 int sched_getcpu(void);
0049 #endif
0050 
0051 extern bool perf_singlethreaded;
0052 
0053 void perf_set_singlethreaded(void);
0054 void perf_set_multithreaded(void);
0055 
0056 char *perf_exe(char *buf, int len);
0057 
0058 #ifndef O_CLOEXEC
0059 #ifdef __sparc__
0060 #define O_CLOEXEC      0x400000
0061 #elif defined(__alpha__) || defined(__hppa__)
0062 #define O_CLOEXEC      010000000
0063 #else
0064 #define O_CLOEXEC      02000000
0065 #endif
0066 #endif
0067 
0068 extern bool test_attr__enabled;
0069 void test_attr__ready(void);
0070 void test_attr__init(void);
0071 struct perf_event_attr;
0072 void test_attr__open(struct perf_event_attr *attr, pid_t pid, struct perf_cpu cpu,
0073              int fd, int group_fd, unsigned long flags);
0074 
0075 struct perf_debuginfod {
0076     const char  *urls;
0077     bool         set;
0078 };
0079 void perf_debuginfod_setup(struct perf_debuginfod *di);
0080 
0081 char *filename_with_chroot(int pid, const char *filename);
0082 
0083 int do_realloc_array_as_needed(void **arr, size_t *arr_sz, size_t x,
0084                    size_t msz, const void *init_val);
0085 
0086 #define realloc_array_as_needed(a, n, x, v) ({          \
0087     typeof(x) __x = (x);                    \
0088     __x >= (n) ?                        \
0089         do_realloc_array_as_needed((void **)&(a),   \
0090                        &(n),        \
0091                        __x,         \
0092                        sizeof(*(a)),    \
0093                        (const void *)(v)) : \
0094         0;                      \
0095     })
0096 
0097 #endif /* GIT_COMPAT_UTIL_H */