void __llvm_profile_enable_continuous_mode(void);
/*!
+ * \brief Set the page size.
+ *
+ * This is a pre-requisite for enabling continuous mode. The buffer size
+ * calculation code inside of libprofile cannot simply call getpagesize(), as
+ * it is not allowed to depend on libc.
+ */
+void __llvm_profile_set_page_size(unsigned PageSize);
+
+/*!
* \brief Get number of bytes necessary to pad the argument to eight
* byte boundary.
*/
* layering is violated. */
static int ContinuouslySyncProfile = 0;
+/* The system page size. Only valid when non-zero. If 0, the page size is
+ * unavailable. */
+static unsigned PageSize = 0;
+
COMPILER_RT_VISIBILITY int __llvm_profile_is_continuous_mode_enabled(void) {
- return ContinuouslySyncProfile;
+ return ContinuouslySyncProfile && PageSize;
}
COMPILER_RT_VISIBILITY void __llvm_profile_enable_continuous_mode(void) {
ContinuouslySyncProfile = 1;
}
+COMPILER_RT_VISIBILITY void __llvm_profile_set_page_size(unsigned PS) {
+ PageSize = PS;
+}
+
COMPILER_RT_VISIBILITY
uint64_t __llvm_profile_get_size_for_buffer(void) {
const __llvm_profile_data *DataBegin = __llvm_profile_begin_data();
/// Calculate the number of padding bytes needed to add to \p Offset in order
/// for (\p Offset + Padding) to be page-aligned.
-static uint64_t calculateBytesNeededToPageAlign(uint64_t Offset,
- unsigned PageSize) {
+static uint64_t calculateBytesNeededToPageAlign(uint64_t Offset) {
uint64_t OffsetModPage = Offset % PageSize;
if (OffsetModPage > 0)
return PageSize - OffsetModPage;
// In continuous mode, the file offsets for headers and for the start of
// counter sections need to be page-aligned.
- unsigned PageSize = getpagesize();
uint64_t DataSizeInBytes = DataSize * sizeof(__llvm_profile_data);
uint64_t CountersSizeInBytes = CountersSize * sizeof(uint64_t);
*PaddingBytesBeforeCounters = calculateBytesNeededToPageAlign(
- sizeof(__llvm_profile_header) + DataSizeInBytes, PageSize);
+ sizeof(__llvm_profile_header) + DataSizeInBytes);
*PaddingBytesAfterCounters =
- calculateBytesNeededToPageAlign(CountersSizeInBytes, PageSize);
- *PaddingBytesAfterNames =
- calculateBytesNeededToPageAlign(NamesSize, PageSize);
+ calculateBytesNeededToPageAlign(CountersSizeInBytes);
+ *PaddingBytesAfterNames = calculateBytesNeededToPageAlign(NamesSize);
}
COMPILER_RT_VISIBILITY