1 /* Common functions for Microsoft Windows builds of Emacs
2 Copyright (C) 2012-2021 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or (at
9 your option) any later version.
10
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
18
19 */
20
21 #ifndef W32COMMON_H
22 #define W32COMMON_H
23
24 #include <windows.h>
25
26 #define ROUND_UP(p, align) (((DWORD_PTR)(p) + (align)-1) & ~((DWORD_PTR)(align)-1))
27 #define ROUND_DOWN(p, align) ((DWORD_PTR)(p) & ~((DWORD_PTR)(align)-1))
28
29 #define get_page_size() sysinfo_cache.dwPageSize
30 #define get_allocation_unit() sysinfo_cache.dwAllocationGranularity
31 #define get_processor_type() sysinfo_cache.dwProcessorType
32 #define get_w32_major_version() w32_major_version
33 #define get_w32_minor_version() w32_minor_version
34
35 extern SYSTEM_INFO sysinfo_cache;
36 extern OSVERSIONINFO osinfo_cache;
37 extern DWORD_PTR syspage_mask;
38
39 extern int w32_major_version;
40 extern int w32_minor_version;
41 extern int w32_build_number;
42
43 enum {
44 OS_9X = 1,
45 OS_NT
46 };
47
48 extern int os_subtype;
49
50 /* Cache system info, e.g., the NT page size. */
51 extern void cache_system_info (void);
52
53 typedef void (* VOIDFNPTR) (void);
54
55 /* Load a function address from a DLL. Cast the result via VOIDFNPTR
56 to pacify -Wcast-function-type in GCC 8.1. The return value must
57 be cast to the correct function pointer type. */
58 INLINE VOIDFNPTR get_proc_addr (HINSTANCE, LPCSTR);
59 INLINE VOIDFNPTR
get_proc_addr(HINSTANCE handle,LPCSTR fname)60 get_proc_addr (HINSTANCE handle, LPCSTR fname)
61 {
62 return (VOIDFNPTR) GetProcAddress (handle, fname);
63 }
64
65 /* Define a function that will be loaded from a DLL. The variable
66 arguments should contain the argument list for the function, and
67 optionally be followed by function attributes. For example:
68 DEF_DLL_FN (void, png_longjmp, (png_structp, int) PNG_NORETURN);
69 */
70 #define DEF_DLL_FN(type, func, ...) \
71 typedef type (CDECL *W32_PFN_##func) __VA_ARGS__; \
72 static W32_PFN_##func fn_##func
73
74 /* Load a function from the DLL. */
75 #define LOAD_DLL_FN(lib, func) \
76 do \
77 { \
78 fn_##func = (W32_PFN_##func) get_proc_addr (lib, #func); \
79 if (!fn_##func) \
80 return false; \
81 } \
82 while (false)
83
84 #ifdef HAVE_HARFBUZZ
85 extern bool hbfont_init_w32_funcs (HMODULE);
86 #endif
87
88 #endif /* W32COMMON_H */
89