|*
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|* See https://llvm.org/LICENSE.txt for license information.
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|*
\*===----------------------------------------------------------------------===*/
#ifndef PROFILE_INSTRPROFILINGUTIL_H
#define PROFILE_INSTRPROFILINGUTIL_H
#include <inttypes.h>
#include <stddef.h>
#include <stdio.h>
void __llvm_profile_recursive_mkdir(char *Pathname);
void __llvm_profile_set_dir_mode(unsigned Mode);
unsigned __llvm_profile_get_dir_mode(void);
int lprofLockFd(int fd);
int lprofUnlockFd(int fd);
int lprofLockFileHandle(FILE *F);
int lprofUnlockFileHandle(FILE *F);
* lock for exclusive access. The caller will block
* if the lock is already held by another process. */
FILE *lprofOpenFileEx(const char *Filename);
enum MemoryStatus {
MS_INVALID,
MS_MMAP,
MS_MALLOC
};
typedef struct {
void *Addr;
enum MemoryStatus Status;
} ManagedMemory;
* Certain files (e.g. NFS mounted) cannot be opened reliably with mmap,
* so we use fread in those cases. The corresponding lprofReleaseBuffer
* will free/munmap the buffer.
*/
void lprofGetFileContentBuffer(FILE *F, uint64_t FileSize, ManagedMemory *Buf);
void lprofReleaseBuffer(ManagedMemory *FileBuffer, size_t Length);
#if __ORBIS__
#include <sys/types.h>
static inline char *getenv(const char *name) { return NULL; }
static inline int setenv(const char *name, const char *value, int overwrite)
{ return 0; }
static pid_t fork() { return -1; }
#endif
* If GCOV_PREFIX_STRIP is also specified, the strip level (integer value)
* is returned via \c *PrefixStrip. The prefix length is stored in *PrefixLen.
*/
const char *lprofGetPathPrefix(int *PrefixStrip, size_t *PrefixLen);
* and store the result to buffer pointed to by \c Buffer. If \c PrefixStrip
* is not zero, path prefixes are stripped from \c PathStr (the level of
* stripping is specified by \c PrefixStrip) before \c Prefix is added.
*/
void lprofApplyPathPrefix(char *Dest, const char *PathStr, const char *Prefix,
size_t PrefixLen, int PrefixStrip);
* the string \c Path, or NULL if the char is not found. */
const char *lprofFindFirstDirSeparator(const char *Path);
* the string \c Path, or NULL if the char is not found. */
const char *lprofFindLastDirSeparator(const char *Path);
int lprofGetHostName(char *Name, int Len);
unsigned lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV);
void *lprofPtrFetchAdd(void **Mem, long ByteIncr);
* Other return values mean no restore is needed.
*/
int lprofSuspendSigKill(void);
void lprofRestoreSigKill(void);
static inline size_t lprofRoundUpTo(size_t x, size_t boundary) {
return (x + boundary - 1) & ~(boundary - 1);
}
static inline size_t lprofRoundDownTo(size_t x, size_t boundary) {
return x & ~(boundary - 1);
}
int lprofReleaseMemoryPagesToOS(uintptr_t Begin, uintptr_t End);
typedef void (*AtExit_Fn_ptr)(void);
int lprofAtExit(AtExit_Fn_ptr);
#endif