MCPcopy Create free account
hub / github.com/crossuo/crossuo / rpmalloc_initialize_config

Function rpmalloc_initialize_config

external/tracy/client/tracy_rpmalloc.cpp:1717–1905  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1715}
1716
1717int
1718rpmalloc_initialize_config(const rpmalloc_config_t* config) {
1719 if (_rpmalloc_initialized) {
1720 rpmalloc_thread_initialize();
1721 return 0;
1722 }
1723 _rpmalloc_initialized = 1;
1724
1725 if (config)
1726 memcpy(&_memory_config, config, sizeof(rpmalloc_config_t));
1727
1728 if (!_memory_config.memory_map || !_memory_config.memory_unmap) {
1729 _memory_config.memory_map = _memory_map_os;
1730 _memory_config.memory_unmap = _memory_unmap_os;
1731 }
1732
1733#if RPMALLOC_CONFIGURABLE
1734 _memory_page_size = _memory_config.page_size;
1735#else
1736 _memory_page_size = 0;
1737#endif
1738 _memory_huge_pages = 0;
1739 _memory_map_granularity = _memory_page_size;
1740 if (!_memory_page_size) {
1741#if PLATFORM_WINDOWS
1742 SYSTEM_INFO system_info;
1743 memset(&system_info, 0, sizeof(system_info));
1744 GetSystemInfo(&system_info);
1745 _memory_page_size = system_info.dwPageSize;
1746 _memory_map_granularity = system_info.dwAllocationGranularity;
1747 if (config && config->enable_huge_pages) {
1748 HANDLE token = 0;
1749 size_t large_page_minimum = GetLargePageMinimum();
1750 if (large_page_minimum)
1751 OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token);
1752 if (token) {
1753 LUID luid;
1754 if (LookupPrivilegeValue(0, SE_LOCK_MEMORY_NAME, &luid)) {
1755 TOKEN_PRIVILEGES token_privileges;
1756 memset(&token_privileges, 0, sizeof(token_privileges));
1757 token_privileges.PrivilegeCount = 1;
1758 token_privileges.Privileges[0].Luid = luid;
1759 token_privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1760 if (AdjustTokenPrivileges(token, FALSE, &token_privileges, 0, 0, 0)) {
1761 DWORD err = GetLastError();
1762 if (err == ERROR_SUCCESS) {
1763 _memory_huge_pages = 1;
1764 _memory_page_size = large_page_minimum;
1765 _memory_map_granularity = large_page_minimum;
1766 }
1767 }
1768 }
1769 CloseHandle(token);
1770 }
1771 }
1772#else
1773 _memory_page_size = (size_t)sysconf(_SC_PAGESIZE);
1774 _memory_map_granularity = _memory_page_size;

Callers 1

rpmalloc_initializeFunction · 0.85

Calls 5

memcpyFunction · 0.85
atomic_store32Function · 0.85
atomic_store_ptrFunction · 0.85

Tested by

no test coverage detected