Skip to content

Commit 310dbe1

Browse files
authored
Merge pull request #197 from igchor/windows
Add linker map and .def file
2 parents 5876bdc + 9b96f8b commit 310dbe1

17 files changed

+228
-70
lines changed

.github/workflows/basic.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,28 +207,39 @@ jobs:
207207
pool_tracking: ['ON', 'OFF']
208208
shared_library: ['OFF']
209209
sanitizers: [{asan: OFF}]
210+
os_provider: ['ON']
210211
include:
211212
- os: 'windows-2022'
212213
build_type: Release
213214
compiler: {c: clang-cl, cxx: clang-cl}
214215
pool_tracking: 'ON'
216+
os_provider: 'ON'
215217
toolset: "-T ClangCL"
216218
- os: 'windows-2022'
217219
build_type: Release
218220
compiler: {c: cl, cxx: cl}
219221
pool_tracking: 'ON'
220222
shared_library: 'ON'
223+
os_provider: 'ON'
224+
- os: 'windows-2022'
225+
build_type: Release
226+
compiler: {c: cl, cxx: cl}
227+
pool_tracking: 'ON'
228+
shared_library: 'ON'
229+
os_provider: 'OFF'
221230
- os: 'windows-2022'
222231
build_type: Debug
223232
compiler: {c: cl, cxx: cl}
224233
pool_tracking: 'OFF'
225234
shared_library: 'OFF'
235+
os_provider: 'ON'
226236
sanitizers: {asan: ON}
227237
- os: 'windows-2022'
228238
build_type: Debug
229239
compiler: {c: clang-cl, cxx: clang-cl}
230240
pool_tracking: 'OFF'
231241
shared_library: 'OFF'
242+
os_provider: 'ON'
232243
sanitizers: {asan: ON}
233244

234245
runs-on: ${{matrix.os}}
@@ -261,6 +272,7 @@ jobs:
261272
-DUMF_DEVELOPER_MODE=ON
262273
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
263274
-DUSE_ASAN=${{matrix.sanitizers.asan}}
275+
-DUMF_BUILD_OS_MEMORY_PROVIDER=${{matrix.os_provider}}
264276
265277
- name: Build UMF
266278
run: cmake --build ${{env.BUILD_DIR}} --config ${{matrix.build_type}} -j $Env:NUMBER_OF_PROCESSORS

benchmark/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5+
include(FindThreads)
6+
57
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
68
message(WARNING "The ubench SHOULD NOT be run in the Debug build type!")
79
endif()
@@ -29,7 +31,7 @@ target_include_directories(ubench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/)
2931
target_link_libraries(ubench
3032
umf
3133
${LIBS_OPTIONAL}
32-
pthread
34+
${CMAKE_THREAD_LIBS_INIT}
3335
m)
3436

3537
if (UMF_BUILD_OS_MEMORY_PROVIDER)

cmake/helpers.cmake

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,33 @@ endfunction()
9494
function(add_umf_library)
9595
# NAME - a name of the library
9696
# TYPE - type of the library (shared or static)
97+
# if shared library, LINUX_MAP_FILE and WINDOWS_DEF_FILE must also be specified
9798
# SRCS - source files
9899
# LIBS - libraries to be linked with
99-
set(oneValueArgs NAME TYPE)
100+
# LINUX_MAP_FILE - path to linux linker map (.map) file
101+
# WINDOWS_DEF_FILE - path to windows module-definition (DEF) file
102+
103+
set(oneValueArgs NAME TYPE LINUX_MAP_FILE WINDOWS_DEF_FILE)
100104
set(multiValueArgs SRCS LIBS)
101105
cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
102106

103107
add_library(${ARG_NAME} ${ARG_TYPE} ${ARG_SRCS})
108+
109+
string(TOUPPER "${ARG_TYPE}" ARG_TYPE)
110+
if(ARG_TYPE STREQUAL "SHARED")
111+
if(NOT ARG_LINUX_MAP_FILE OR NOT ARG_WINDOWS_DEF_FILE)
112+
message(FATAL_ERROR "LINUX_MAP_FILE or WINDOWS_DEF_FILE not specified")
113+
endif()
114+
115+
if (WINDOWS)
116+
target_link_options(${ARG_NAME} PRIVATE /DEF:${ARG_WINDOWS_DEF_FILE})
117+
else()
118+
target_link_options(${ARG_NAME} PRIVATE "-Wl,--version-script=${ARG_LINUX_MAP_FILE}")
119+
endif()
120+
endif()
121+
104122
target_link_libraries(${ARG_NAME} PRIVATE ${ARG_LIBS})
123+
105124
target_include_directories(${ARG_NAME} PRIVATE
106125
${UMF_CMAKE_SOURCE_DIR}/include
107126
${UMF_CMAKE_SOURCE_DIR}/src/base_alloc)

include/umf/base.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
extern "C" {
1818
#endif
1919

20-
#if defined(_WIN32) && defined(UMF_SHARED_LIBRARY)
21-
#define UMF_EXPORT __declspec(dllexport)
22-
#else
23-
#define UMF_EXPORT
24-
#endif
25-
2620
/// @brief Generates generic 'UMF' API versions
2721
#define UMF_MAKE_VERSION(_major, _minor) \
2822
((_major << 16) | (_minor & 0x0000ffff))

include/umf/memory_pool.h

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,24 @@ typedef enum umf_pool_create_flag_t {
5252
/// @param hPool [out] handle to the newly created memory pool
5353
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
5454
///
55-
UMF_EXPORT umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
56-
umf_memory_provider_handle_t provider,
57-
void *params,
58-
umf_pool_create_flags_t flags,
59-
umf_memory_pool_handle_t *hPool);
55+
umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
56+
umf_memory_provider_handle_t provider, void *params,
57+
umf_pool_create_flags_t flags,
58+
umf_memory_pool_handle_t *hPool);
6059

6160
///
6261
/// @brief Destroys memory pool.
6362
/// @param hPool handle to the pool
6463
///
65-
UMF_EXPORT void umfPoolDestroy(umf_memory_pool_handle_t hPool);
64+
void umfPoolDestroy(umf_memory_pool_handle_t hPool);
6665

6766
///
6867
/// @brief Allocates \p size bytes of uninitialized storage from \p hPool
6968
/// @param hPool specified memory hPool
7069
/// @param size number of bytes to allocate
7170
/// @return Pointer to the allocated memory.
7271
///
73-
UMF_EXPORT void *umfPoolMalloc(umf_memory_pool_handle_t hPool, size_t size);
72+
void *umfPoolMalloc(umf_memory_pool_handle_t hPool, size_t size);
7473

7574
///
7675
/// @brief Allocates \p size bytes of uninitialized storage from the specified \p hPool
@@ -80,8 +79,8 @@ UMF_EXPORT void *umfPoolMalloc(umf_memory_pool_handle_t hPool, size_t size);
8079
/// @param alignment alignment of the allocation in bytes
8180
/// @return Pointer to the allocated memory
8281
///
83-
UMF_EXPORT void *umfPoolAlignedMalloc(umf_memory_pool_handle_t hPool,
84-
size_t size, size_t alignment);
82+
void *umfPoolAlignedMalloc(umf_memory_pool_handle_t hPool, size_t size,
83+
size_t alignment);
8584

8685
///
8786
/// @brief Allocates memory from \p hPool for an array of \p num elements
@@ -92,8 +91,7 @@ UMF_EXPORT void *umfPoolAlignedMalloc(umf_memory_pool_handle_t hPool,
9291
/// @param size number of bytes to allocate for each object
9392
/// @return Pointer to the allocated memory
9493
///
95-
UMF_EXPORT void *umfPoolCalloc(umf_memory_pool_handle_t hPool, size_t num,
96-
size_t size);
94+
void *umfPoolCalloc(umf_memory_pool_handle_t hPool, size_t num, size_t size);
9795

9896
///
9997
/// @brief Reallocates memory from \p hPool
@@ -102,17 +100,15 @@ UMF_EXPORT void *umfPoolCalloc(umf_memory_pool_handle_t hPool, size_t num,
102100
/// @param size new size for the memory block in bytes
103101
/// @return Pointer to the allocated memory
104102
///
105-
UMF_EXPORT void *umfPoolRealloc(umf_memory_pool_handle_t hPool, void *ptr,
106-
size_t size);
103+
void *umfPoolRealloc(umf_memory_pool_handle_t hPool, void *ptr, size_t size);
107104

108105
///
109106
/// @brief Obtains size of block of memory allocated from the \p hPool for a given \p ptr
110107
/// @param hPool specified memory hPool
111108
/// @param ptr pointer to the allocated memory
112109
/// @return size of the memory block allocated from the \p hPool
113110
///
114-
UMF_EXPORT size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool,
115-
void *ptr);
111+
size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool, void *ptr);
116112

117113
///
118114
/// @brief Frees the memory space of the specified \p hPool pointed by \p ptr
@@ -122,7 +118,7 @@ UMF_EXPORT size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool,
122118
/// Whether any status other than UMF_RESULT_SUCCESS can be returned
123119
/// depends on the memory provider used by the \p hPool.
124120
///
125-
UMF_EXPORT umf_result_t umfPoolFree(umf_memory_pool_handle_t hPool, void *ptr);
121+
umf_result_t umfPoolFree(umf_memory_pool_handle_t hPool, void *ptr);
126122

127123
///
128124
/// @brief Frees the memory space pointed by ptr if it belongs to UMF pool, does nothing otherwise.
@@ -131,7 +127,7 @@ UMF_EXPORT umf_result_t umfPoolFree(umf_memory_pool_handle_t hPool, void *ptr);
131127
/// Whether any status other than UMF_RESULT_SUCCESS can be returned
132128
/// depends on the memory provider used by the pool.
133129
///
134-
UMF_EXPORT umf_result_t umfFree(void *ptr);
130+
umf_result_t umfFree(void *ptr);
135131

136132
///
137133
/// @brief Retrieve \p umf_result_t representing the error of the last failed allocation
@@ -151,16 +147,15 @@ UMF_EXPORT umf_result_t umfFree(void *ptr);
151147
/// @return Error code desciribng the failure of the last failed allocation operation.
152148
/// The value is undefined if the previous allocation was successful.
153149
///
154-
UMF_EXPORT umf_result_t
155-
umfPoolGetLastAllocationError(umf_memory_pool_handle_t hPool);
150+
umf_result_t umfPoolGetLastAllocationError(umf_memory_pool_handle_t hPool);
156151

157152
///
158153
/// @brief Retrieve memory pool associated with a given ptr. Only memory allocated
159154
/// with the usage of a memory provider is being tracked.
160155
/// @param ptr pointer to memory belonging to a memory pool
161156
/// @return Handle to a memory pool that contains ptr or NULL if pointer does not belong to any UMF pool.
162157
///
163-
UMF_EXPORT umf_memory_pool_handle_t umfPoolByPtr(const void *ptr);
158+
umf_memory_pool_handle_t umfPoolByPtr(const void *ptr);
164159

165160
///
166161
/// @brief Retrieve memory provider associated with a given pool.
@@ -169,8 +164,8 @@ UMF_EXPORT umf_memory_pool_handle_t umfPoolByPtr(const void *ptr);
169164
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
170165
/// UMF_RESULT_ERROR_INVALID_ARGUMENT if hProvider is NULL
171166
///
172-
UMF_EXPORT umf_result_t umfPoolGetMemoryProvider(
173-
umf_memory_pool_handle_t hPool, umf_memory_provider_handle_t *hProvider);
167+
umf_result_t umfPoolGetMemoryProvider(umf_memory_pool_handle_t hPool,
168+
umf_memory_provider_handle_t *hProvider);
174169

175170
#ifdef __cplusplus
176171
}

include/umf/memory_provider.h

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@ typedef struct umf_memory_provider_t *umf_memory_provider_handle_t;
2727
/// @param hProvider [out] pointer to the newly created memory provider
2828
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
2929
///
30-
UMF_EXPORT umf_result_t
31-
umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops, void *params,
32-
umf_memory_provider_handle_t *hProvider);
30+
umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
31+
void *params,
32+
umf_memory_provider_handle_t *hProvider);
3333

3434
///
3535
/// @brief Destroys memory provider.
3636
/// @param hProvider handle to the memory provider
3737
///
38-
UMF_EXPORT void
39-
umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);
38+
void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);
4039

4140
///
4241
/// @brief Allocates \p size bytes of uninitialized storage from memory \p hProvider
@@ -47,9 +46,8 @@ umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);
4746
/// @param ptr [out] pointer to the allocated memory
4847
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
4948
///
50-
UMF_EXPORT umf_result_t
51-
umfMemoryProviderAlloc(umf_memory_provider_handle_t hProvider, size_t size,
52-
size_t alignment, void **ptr);
49+
umf_result_t umfMemoryProviderAlloc(umf_memory_provider_handle_t hProvider,
50+
size_t size, size_t alignment, void **ptr);
5351

5452
///
5553
/// @brief Frees the memory space pointed by \p ptr from the memory \p hProvider
@@ -58,8 +56,8 @@ umfMemoryProviderAlloc(umf_memory_provider_handle_t hProvider, size_t size,
5856
/// @param size size of the allocation
5957
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
6058
///
61-
UMF_EXPORT umf_result_t umfMemoryProviderFree(
62-
umf_memory_provider_handle_t hProvider, void *ptr, size_t size);
59+
umf_result_t umfMemoryProviderFree(umf_memory_provider_handle_t hProvider,
60+
void *ptr, size_t size);
6361

6462
///
6563
/// @brief Retrieve string representation of the underlying provider specific
@@ -85,9 +83,9 @@ UMF_EXPORT umf_result_t umfMemoryProviderFree(
8583
/// result in string representation
8684
/// @param pError [out] pointer to an integer where the adapter specific error code will be stored
8785
///
88-
UMF_EXPORT void
89-
umfMemoryProviderGetLastNativeError(umf_memory_provider_handle_t hProvider,
90-
const char **ppMessage, int32_t *pError);
86+
void umfMemoryProviderGetLastNativeError(umf_memory_provider_handle_t hProvider,
87+
const char **ppMessage,
88+
int32_t *pError);
9189

9290
///
9391
/// @brief Retrieve recommended page size for a given allocation size.
@@ -96,8 +94,9 @@ umfMemoryProviderGetLastNativeError(umf_memory_provider_handle_t hProvider,
9694
/// @param pageSize [out] pointer to the recommended page size
9795
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
9896
///
99-
UMF_EXPORT umf_result_t umfMemoryProviderGetRecommendedPageSize(
100-
umf_memory_provider_handle_t hProvider, size_t size, size_t *pageSize);
97+
umf_result_t
98+
umfMemoryProviderGetRecommendedPageSize(umf_memory_provider_handle_t hProvider,
99+
size_t size, size_t *pageSize);
101100

102101
///
103102
/// @brief Retrieve minimum possible page size used by memory region referenced by a given \p ptr
@@ -107,8 +106,9 @@ UMF_EXPORT umf_result_t umfMemoryProviderGetRecommendedPageSize(
107106
/// @param pageSize [out] pointer to the minimum possible page size
108107
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
109108
///
110-
UMF_EXPORT umf_result_t umfMemoryProviderGetMinPageSize(
111-
umf_memory_provider_handle_t hProvider, void *ptr, size_t *pageSize);
109+
umf_result_t
110+
umfMemoryProviderGetMinPageSize(umf_memory_provider_handle_t hProvider,
111+
void *ptr, size_t *pageSize);
112112

113113
///
114114
/// @brief Discard physical pages within the virtual memory mapping associated at the given addr
@@ -120,8 +120,8 @@ UMF_EXPORT umf_result_t umfMemoryProviderGetMinPageSize(
120120
/// UMF_RESULT_ERROR_INVALID_ALIGNMENT if ptr or size is not page-aligned.
121121
/// UMF_RESULT_ERROR_NOT_SUPPORTED if operation is not supported by this provider.
122122
///
123-
UMF_EXPORT umf_result_t umfMemoryProviderPurgeLazy(
124-
umf_memory_provider_handle_t hProvider, void *ptr, size_t size);
123+
umf_result_t umfMemoryProviderPurgeLazy(umf_memory_provider_handle_t hProvider,
124+
void *ptr, size_t size);
125125

126126
///
127127
/// @brief Discard physical pages within the virtual memory mapping associated at the given addr and \p size.
@@ -133,16 +133,15 @@ UMF_EXPORT umf_result_t umfMemoryProviderPurgeLazy(
133133
/// UMF_RESULT_ERROR_INVALID_ALIGNMENT if ptr or size is not page-aligned.
134134
/// UMF_RESULT_ERROR_NOT_SUPPORTED if operation is not supported by this provider.
135135
///
136-
UMF_EXPORT umf_result_t umfMemoryProviderPurgeForce(
137-
umf_memory_provider_handle_t hProvider, void *ptr, size_t size);
136+
umf_result_t umfMemoryProviderPurgeForce(umf_memory_provider_handle_t hProvider,
137+
void *ptr, size_t size);
138138

139139
///
140140
/// @brief Retrieve name of a given memory \p hProvider.
141141
/// @param hProvider handle to the memory provider
142142
/// @return pointer to a string containing the name of the \p hProvider
143143
///
144-
UMF_EXPORT const char *
145-
umfMemoryProviderGetName(umf_memory_provider_handle_t hProvider);
144+
const char *umfMemoryProviderGetName(umf_memory_provider_handle_t hProvider);
146145

147146
///
148147
/// @brief Retrieve handle to the last memory provider that returned status other
@@ -154,7 +153,7 @@ umfMemoryProviderGetName(umf_memory_provider_handle_t hProvider);
154153
///
155154
/// @return Handle to the memory provider
156155
///
157-
UMF_EXPORT umf_memory_provider_handle_t umfGetLastFailedMemoryProvider(void);
156+
umf_memory_provider_handle_t umfGetLastFailedMemoryProvider(void);
158157

159158
///
160159
/// @brief Splits a coarse grain allocation into 2 adjacent allocations that
@@ -166,7 +165,7 @@ UMF_EXPORT umf_memory_provider_handle_t umfGetLastFailedMemoryProvider(void);
166165
// has a size equal to totalSize - firstSize
167166
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
168167
///
169-
UMF_EXPORT umf_result_t
168+
umf_result_t
170169
umfMemoryProviderAllocationSplit(umf_memory_provider_handle_t hProvider,
171170
void *ptr, size_t totalSize, size_t firstSize);
172171

@@ -180,7 +179,7 @@ umfMemoryProviderAllocationSplit(umf_memory_provider_handle_t hProvider,
180179
/// to the sum of sizes of allocations beginning at lowPtr and highPtr
181180
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
182181
///
183-
UMF_EXPORT umf_result_t
182+
umf_result_t
184183
umfMemoryProviderAllocationMerge(umf_memory_provider_handle_t hProvider,
185184
void *lowPtr, void *highPtr, size_t totalSize);
186185

include/umf/pools/pool_proxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
extern "C" {
1919
#endif
2020

21-
UMF_EXPORT umf_memory_pool_ops_t *umfProxyPoolOps(void);
21+
umf_memory_pool_ops_t *umfProxyPoolOps(void);
2222

2323
#ifdef __cplusplus
2424
}

src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ if(UMF_BUILD_SHARED_LIBRARY)
7070
add_umf_library(NAME umf
7171
TYPE SHARED
7272
SRCS ${UMF_SOURCES}
73-
LIBS ${UMF_LIBS})
73+
LIBS ${UMF_LIBS}
74+
LINUX_MAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libumf.map
75+
WINDOWS_DEF_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libumf.def)
7476
target_compile_definitions(umf PUBLIC UMF_SHARED_LIBRARY)
7577
set_target_properties(umf PROPERTIES
7678
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_UMF_OUTPUT_DIRECTORY})

0 commit comments

Comments
 (0)