Skip to content

Commit be751d2

Browse files
committed
Implement all *_get_page_size() functions on Windows
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent c860b3a commit be751d2

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

src/base_alloc/base_alloc_windows.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ void *ba_os_alloc(size_t size) {
1313

1414
void ba_os_free(void *ptr, size_t size) { VirtualFree(ptr, 0, MEM_RELEASE); }
1515

16-
size_t ba_os_get_page_size(void) { return 4096; /* TODO */ }
17-
18-
//
19-
// TODO:
20-
// 1) implement ba_os_get_page_size()
21-
//
16+
size_t ba_os_get_page_size(void) {
17+
SYSTEM_INFO SystemInfo;
18+
GetSystemInfo(&SystemInfo);
19+
return SystemInfo.dwPageSize;
20+
}

src/utils/utils_common.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
#include <stdio.h>
1515
#include <stdlib.h>
1616

17-
#ifndef _WIN32
18-
#include <sys/syscall.h>
19-
#include <unistd.h>
20-
#endif
21-
2217
#ifdef __cplusplus
2318
extern "C" {
2419
#endif
@@ -35,15 +30,10 @@ extern "C" {
3530

3631
#define __TLS __declspec(thread)
3732

38-
// TODO: implement util_get_page_size() for Windows
39-
static inline size_t util_get_page_size(void) { return 4096; }
40-
4133
#else /* Linux */
4234

4335
#define __TLS __thread
4436

45-
static inline size_t util_get_page_size(void) { return sysconf(_SC_PAGE_SIZE); }
46-
4737
#endif /* _WIN32 */
4838

4939
// util_env_var - populate the given buffer with the value
@@ -69,6 +59,8 @@ static inline int is_running_in_proxy_lib(void) {
6959
return util_env_var_has_str("LD_PRELOAD", "libumf_proxy.so");
7060
}
7161

62+
size_t util_get_page_size(void);
63+
7264
#define NOFUNCTION \
7365
do { \
7466
} while (0)

src/utils/utils_posix_common.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include <stdlib.h>
1111
#include <string.h>
12+
#include <sys/syscall.h>
13+
#include <unistd.h>
1214

1315
int util_env_var(const char *envvar, char *buffer, size_t buffer_size) {
1416
char *value = getenv(envvar);
@@ -36,3 +38,5 @@ int util_env_var_has_str(const char *envvar, const char *str) {
3638

3739
return 0;
3840
}
41+
42+
size_t util_get_page_size(void) { return sysconf(_SC_PAGE_SIZE); }

src/utils/utils_windows_common.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ int util_env_var_has_str(const char *envvar, const char *str) {
3030

3131
return 0;
3232
}
33+
34+
size_t util_get_page_size(void) {
35+
SYSTEM_INFO SystemInfo;
36+
GetSystemInfo(&SystemInfo);
37+
return SystemInfo.dwPageSize;
38+
}

0 commit comments

Comments
 (0)