Path: blob/main/contrib/llvm-project/compiler-rt/lib/profile/InstrProfilingUtil.h
35233 views
/*===- InstrProfilingUtil.h - Support library for PGO instrumentation -----===*\1|*2|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3|* See https://llvm.org/LICENSE.txt for license information.4|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5|*6\*===----------------------------------------------------------------------===*/78#ifndef PROFILE_INSTRPROFILINGUTIL_H9#define PROFILE_INSTRPROFILINGUTIL_H1011#include <inttypes.h>12#include <stddef.h>13#include <stdio.h>1415/*! \brief Create a directory tree. */16void __llvm_profile_recursive_mkdir(char *Pathname);1718/*! Set the mode used when creating profile directories. */19void __llvm_profile_set_dir_mode(unsigned Mode);2021/*! Return the directory creation mode. */22unsigned __llvm_profile_get_dir_mode(void);2324int lprofLockFd(int fd);25int lprofUnlockFd(int fd);26int lprofLockFileHandle(FILE *F);27int lprofUnlockFileHandle(FILE *F);2829/*! Open file \c Filename for read+write with write30* lock for exclusive access. The caller will block31* if the lock is already held by another process. */32FILE *lprofOpenFileEx(const char *Filename);33/* PS4 doesn't have setenv/getenv/fork. Define a shim. */34#if __ORBIS__35#include <sys/types.h>36static inline char *getenv(const char *name) { return NULL; }37static inline int setenv(const char *name, const char *value, int overwrite)38{ return 0; }39static pid_t fork() { return -1; }40#endif /* #if __ORBIS__ */4142/* GCOV_PREFIX and GCOV_PREFIX_STRIP support */43/* Return the path prefix specified by GCOV_PREFIX environment variable.44* If GCOV_PREFIX_STRIP is also specified, the strip level (integer value)45* is returned via \c *PrefixStrip. The prefix length is stored in *PrefixLen.46*/47const char *lprofGetPathPrefix(int *PrefixStrip, size_t *PrefixLen);48/* Apply the path prefix specified in \c Prefix to path string in \c PathStr,49* and store the result to buffer pointed to by \c Buffer. If \c PrefixStrip50* is not zero, path prefixes are stripped from \c PathStr (the level of51* stripping is specified by \c PrefixStrip) before \c Prefix is added.52*/53void lprofApplyPathPrefix(char *Dest, const char *PathStr, const char *Prefix,54size_t PrefixLen, int PrefixStrip);5556/* Returns a pointer to the first occurrence of \c DIR_SEPARATOR char in57* the string \c Path, or NULL if the char is not found. */58const char *lprofFindFirstDirSeparator(const char *Path);59/* Returns a pointer to the last occurrence of \c DIR_SEPARATOR char in60* the string \c Path, or NULL if the char is not found. */61const char *lprofFindLastDirSeparator(const char *Path);6263int lprofGetHostName(char *Name, int Len);6465unsigned lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV);66void *lprofPtrFetchAdd(void **Mem, long ByteIncr);6768/* Temporarily suspend SIGKILL. Return value of 1 means a restore is needed.69* Other return values mean no restore is needed.70*/71int lprofSuspendSigKill();7273/* Restore previously suspended SIGKILL. */74void lprofRestoreSigKill();7576static inline size_t lprofRoundUpTo(size_t x, size_t boundary) {77return (x + boundary - 1) & ~(boundary - 1);78}7980static inline size_t lprofRoundDownTo(size_t x, size_t boundary) {81return x & ~(boundary - 1);82}8384int lprofReleaseMemoryPagesToOS(uintptr_t Begin, uintptr_t End);8586#endif /* PROFILE_INSTRPROFILINGUTIL_H */878889