| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT RUN-TIME COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S Y S T E M . W I N 3 2 -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2008-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 12 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 13 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 14 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 15 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 16 |
-- or FITNESS FOR A PARTICULAR PURPOSE. -- |
| 17 |
-- -- |
| 18 |
-- As a special exception under Section 7 of GPL version 3, you are granted -- |
| 19 |
-- additional permissions described in the GCC Runtime Library Exception, -- |
| 20 |
-- version 3.1, as published by the Free Software Foundation. -- |
| 21 |
-- -- |
| 22 |
-- You should have received a copy of the GNU General Public License and -- |
| 23 |
-- a copy of the GCC Runtime Library Exception along with this program; -- |
| 24 |
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- |
| 25 |
-- <http://www.gnu.org/licenses/>. -- |
| 26 |
-- -- |
| 27 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 28 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 29 |
-- -- |
| 30 |
------------------------------------------------------------------------------ |
| 31 |
|
| 32 |
-- This package plus its child provide the low level interface to the Win32 |
| 33 |
-- API. The core part of the Win32 API (common to RTX and Win32) is in this |
| 34 |
-- package, and an additional part of the Win32 API which is not supported by |
| 35 |
-- RTX is in package System.Win32.Ext. |
| 36 |
|
| 37 |
with Interfaces.C; |
| 38 |
|
| 39 |
package System.Win32 is |
| 40 |
pragma Pure; |
| 41 |
|
| 42 |
------------------- |
| 43 |
-- General Types -- |
| 44 |
------------------- |
| 45 |
|
| 46 |
-- The LARGE_INTEGER type is actually a fixed point type |
| 47 |
-- that only can represent integers. The reason for this is |
| 48 |
-- easier conversion to Duration or other fixed point types. |
| 49 |
-- (See System.OS_Primitives.Clock, mingw and rtx versions.) |
| 50 |
|
| 51 |
type LARGE_INTEGER is delta 1.0 range -2.0**63 .. 2.0**63 - 1.0; |
| 52 |
|
| 53 |
subtype PVOID is Address; |
| 54 |
|
| 55 |
type HANDLE is new Interfaces.C.ptrdiff_t; |
| 56 |
|
| 57 |
INVALID_HANDLE_VALUE : constant HANDLE := -1; |
| 58 |
INVALID_FILE_SIZE : constant := 16#FFFFFFFF#; |
| 59 |
|
| 60 |
type ULONG is new Interfaces.C.unsigned_long; |
| 61 |
type DWORD is new Interfaces.C.unsigned_long; |
| 62 |
type WORD is new Interfaces.C.unsigned_short; |
| 63 |
type BYTE is new Interfaces.C.unsigned_char; |
| 64 |
type LONG is new Interfaces.C.long; |
| 65 |
type CHAR is new Interfaces.C.char; |
| 66 |
type SIZE_T is new Interfaces.C.size_t; |
| 67 |
type DWORD_PTR is mod 2 ** Standard'Address_Size; |
| 68 |
|
| 69 |
type BOOL is new Interfaces.C.int; |
| 70 |
for BOOL'Size use Interfaces.C.int'Size; |
| 71 |
|
| 72 |
type Bits1 is range 0 .. 2 ** 1 - 1; |
| 73 |
type Bits2 is range 0 .. 2 ** 2 - 1; |
| 74 |
type Bits17 is range 0 .. 2 ** 17 - 1; |
| 75 |
for Bits1'Size use 1; |
| 76 |
for Bits2'Size use 2; |
| 77 |
for Bits17'Size use 17; |
| 78 |
|
| 79 |
-- Note that the following clashes with standard names are to stay |
| 80 |
-- compatible with the historical choice of following the C names. |
| 81 |
|
| 82 |
pragma Warnings (Off); |
| 83 |
FALSE : constant := 0; |
| 84 |
TRUE : constant := 1; |
| 85 |
pragma Warnings (On); |
| 86 |
|
| 87 |
function GetLastError return DWORD; |
| 88 |
pragma Import (Stdcall, GetLastError, "GetLastError"); |
| 89 |
|
| 90 |
----------- |
| 91 |
-- Files -- |
| 92 |
----------- |
| 93 |
|
| 94 |
CP_UTF8 : constant := 65001; |
| 95 |
CP_ACP : constant := 0; |
| 96 |
|
| 97 |
GENERIC_READ : constant := 16#80000000#; |
| 98 |
GENERIC_WRITE : constant := 16#40000000#; |
| 99 |
|
| 100 |
CREATE_NEW : constant := 1; |
| 101 |
CREATE_ALWAYS : constant := 2; |
| 102 |
OPEN_EXISTING : constant := 3; |
| 103 |
OPEN_ALWAYS : constant := 4; |
| 104 |
TRUNCATE_EXISTING : constant := 5; |
| 105 |
|
| 106 |
FILE_SHARE_DELETE : constant := 16#00000004#; |
| 107 |
FILE_SHARE_READ : constant := 16#00000001#; |
| 108 |
FILE_SHARE_WRITE : constant := 16#00000002#; |
| 109 |
|
| 110 |
FILE_BEGIN : constant := 0; |
| 111 |
FILE_CURRENT : constant := 1; |
| 112 |
FILE_END : constant := 2; |
| 113 |
|
| 114 |
PAGE_NOACCESS : constant := 16#0001#; |
| 115 |
PAGE_READONLY : constant := 16#0002#; |
| 116 |
PAGE_READWRITE : constant := 16#0004#; |
| 117 |
PAGE_WRITECOPY : constant := 16#0008#; |
| 118 |
PAGE_EXECUTE : constant := 16#0010#; |
| 119 |
|
| 120 |
FILE_MAP_ALL_ACCESS : constant := 16#F001f#; |
| 121 |
FILE_MAP_READ : constant := 4; |
| 122 |
FILE_MAP_WRITE : constant := 2; |
| 123 |
FILE_MAP_COPY : constant := 1; |
| 124 |
|
| 125 |
FILE_ADD_FILE : constant := 16#0002#; |
| 126 |
FILE_ADD_SUBDIRECTORY : constant := 16#0004#; |
| 127 |
FILE_APPEND_DATA : constant := 16#0004#; |
| 128 |
FILE_CREATE_PIPE_INSTANCE : constant := 16#0004#; |
| 129 |
FILE_DELETE_CHILD : constant := 16#0040#; |
| 130 |
FILE_EXECUTE : constant := 16#0020#; |
| 131 |
FILE_LIST_DIRECTORY : constant := 16#0001#; |
| 132 |
FILE_READ_ATTRIBUTES : constant := 16#0080#; |
| 133 |
FILE_READ_DATA : constant := 16#0001#; |
| 134 |
FILE_READ_EA : constant := 16#0008#; |
| 135 |
FILE_TRAVERSE : constant := 16#0020#; |
| 136 |
FILE_WRITE_ATTRIBUTES : constant := 16#0100#; |
| 137 |
FILE_WRITE_DATA : constant := 16#0002#; |
| 138 |
FILE_WRITE_EA : constant := 16#0010#; |
| 139 |
STANDARD_RIGHTS_READ : constant := 16#20000#; |
| 140 |
STANDARD_RIGHTS_WRITE : constant := 16#20000#; |
| 141 |
SYNCHRONIZE : constant := 16#100000#; |
| 142 |
|
| 143 |
FILE_ATTRIBUTE_READONLY : constant := 16#00000001#; |
| 144 |
FILE_ATTRIBUTE_HIDDEN : constant := 16#00000002#; |
| 145 |
FILE_ATTRIBUTE_SYSTEM : constant := 16#00000004#; |
| 146 |
FILE_ATTRIBUTE_DIRECTORY : constant := 16#00000010#; |
| 147 |
FILE_ATTRIBUTE_ARCHIVE : constant := 16#00000020#; |
| 148 |
FILE_ATTRIBUTE_DEVICE : constant := 16#00000040#; |
| 149 |
FILE_ATTRIBUTE_NORMAL : constant := 16#00000080#; |
| 150 |
FILE_ATTRIBUTE_TEMPORARY : constant := 16#00000100#; |
| 151 |
FILE_ATTRIBUTE_SPARSE_FILE : constant := 16#00000200#; |
| 152 |
FILE_ATTRIBUTE_REPARSE_POINT : constant := 16#00000400#; |
| 153 |
FILE_ATTRIBUTE_COMPRESSED : constant := 16#00000800#; |
| 154 |
FILE_ATTRIBUTE_OFFLINE : constant := 16#00001000#; |
| 155 |
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED : constant := 16#00002000#; |
| 156 |
FILE_ATTRIBUTE_ENCRYPTED : constant := 16#00004000#; |
| 157 |
FILE_ATTRIBUTE_VALID_FLAGS : constant := 16#00007fb7#; |
| 158 |
FILE_ATTRIBUTE_VALID_SET_FLAGS : constant := 16#000031a7#; |
| 159 |
|
| 160 |
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS : constant := 16#04#; |
| 161 |
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT : constant := 16#02#; |
| 162 |
|
| 163 |
type OVERLAPPED is record |
| 164 |
Internal : access ULONG; |
| 165 |
InternalHigh : access ULONG; |
| 166 |
Offset : DWORD; |
| 167 |
OffsetHigh : DWORD; |
| 168 |
hEvent : HANDLE; |
| 169 |
end record; |
| 170 |
pragma Convention (C_Pass_By_Copy, OVERLAPPED); |
| 171 |
|
| 172 |
type SECURITY_ATTRIBUTES is record |
| 173 |
nLength : DWORD; |
| 174 |
pSecurityDescriptor : PVOID; |
| 175 |
bInheritHandle : BOOL; |
| 176 |
end record; |
| 177 |
pragma Convention (C_Pass_By_Copy, SECURITY_ATTRIBUTES); |
| 178 |
|
| 179 |
function CreateFileA |
| 180 |
(lpFileName : Address; |
| 181 |
dwDesiredAccess : DWORD; |
| 182 |
dwShareMode : DWORD; |
| 183 |
lpSecurityAttributes : access SECURITY_ATTRIBUTES; |
| 184 |
dwCreationDisposition : DWORD; |
| 185 |
dwFlagsAndAttributes : DWORD; |
| 186 |
hTemplateFile : HANDLE) return HANDLE; |
| 187 |
pragma Import (Stdcall, CreateFileA, "CreateFileA"); |
| 188 |
|
| 189 |
function CreateFile |
| 190 |
(lpFileName : Address; |
| 191 |
dwDesiredAccess : DWORD; |
| 192 |
dwShareMode : DWORD; |
| 193 |
lpSecurityAttributes : access SECURITY_ATTRIBUTES; |
| 194 |
dwCreationDisposition : DWORD; |
| 195 |
dwFlagsAndAttributes : DWORD; |
| 196 |
hTemplateFile : HANDLE) return HANDLE; |
| 197 |
pragma Import (Stdcall, CreateFile, "CreateFileW"); |
| 198 |
|
| 199 |
function GetFileSize |
| 200 |
(hFile : HANDLE; |
| 201 |
lpFileSizeHigh : access DWORD) return BOOL; |
| 202 |
pragma Import (Stdcall, GetFileSize, "GetFileSize"); |
| 203 |
|
| 204 |
function SetFilePointer |
| 205 |
(hFile : HANDLE; |
| 206 |
lDistanceToMove : LONG; |
| 207 |
lpDistanceToMoveHigh : access LONG; |
| 208 |
dwMoveMethod : DWORD) return DWORD; |
| 209 |
pragma Import (Stdcall, SetFilePointer, "SetFilePointer"); |
| 210 |
|
| 211 |
function WriteFile |
| 212 |
(hFile : HANDLE; |
| 213 |
lpBuffer : Address; |
| 214 |
nNumberOfBytesToWrite : DWORD; |
| 215 |
lpNumberOfBytesWritten : access DWORD; |
| 216 |
lpOverlapped : access OVERLAPPED) return BOOL; |
| 217 |
pragma Import (Stdcall, WriteFile, "WriteFile"); |
| 218 |
|
| 219 |
function ReadFile |
| 220 |
(hFile : HANDLE; |
| 221 |
lpBuffer : Address; |
| 222 |
nNumberOfBytesToRead : DWORD; |
| 223 |
lpNumberOfBytesRead : access DWORD; |
| 224 |
lpOverlapped : access OVERLAPPED) return BOOL; |
| 225 |
pragma Import (Stdcall, ReadFile, "ReadFile"); |
| 226 |
|
| 227 |
function CloseHandle (hObject : HANDLE) return BOOL; |
| 228 |
pragma Import (Stdcall, CloseHandle, "CloseHandle"); |
| 229 |
|
| 230 |
function CreateFileMapping |
| 231 |
(hFile : HANDLE; |
| 232 |
lpSecurityAttributes : access SECURITY_ATTRIBUTES; |
| 233 |
flProtect : DWORD; |
| 234 |
dwMaximumSizeHigh : DWORD; |
| 235 |
dwMaximumSizeLow : DWORD; |
| 236 |
lpName : Address) return HANDLE; |
| 237 |
pragma Import (Stdcall, CreateFileMapping, "CreateFileMappingA"); |
| 238 |
|
| 239 |
function MapViewOfFile |
| 240 |
(hFileMappingObject : HANDLE; |
| 241 |
dwDesiredAccess : DWORD; |
| 242 |
dwFileOffsetHigh : DWORD; |
| 243 |
dwFileOffsetLow : DWORD; |
| 244 |
dwNumberOfBytesToMap : SIZE_T) return System.Address; |
| 245 |
pragma Import (Stdcall, MapViewOfFile, "MapViewOfFile"); |
| 246 |
|
| 247 |
function UnmapViewOfFile (lpBaseAddress : System.Address) return BOOL; |
| 248 |
pragma Import (Stdcall, UnmapViewOfFile, "UnmapViewOfFile"); |
| 249 |
|
| 250 |
function MultiByteToWideChar |
| 251 |
(CodePage : WORD; |
| 252 |
dwFlags : DWORD; |
| 253 |
lpMultiByteStr : System.Address; |
| 254 |
cchMultiByte : WORD; |
| 255 |
lpWideCharStr : System.Address; |
| 256 |
cchWideChar : WORD) return WORD; |
| 257 |
pragma Import (Stdcall, MultiByteToWideChar, "MultiByteToWideChar"); |
| 258 |
|
| 259 |
------------------------ |
| 260 |
-- System Information -- |
| 261 |
------------------------ |
| 262 |
|
| 263 |
subtype ProcessorId is DWORD; |
| 264 |
|
| 265 |
type SYSTEM_INFO is record |
| 266 |
dwOemId : DWORD; |
| 267 |
dwPageSize : DWORD; |
| 268 |
lpMinimumApplicationAddress : PVOID; |
| 269 |
lpMaximumApplicationAddress : PVOID; |
| 270 |
dwActiveProcessorMask : DWORD_PTR; |
| 271 |
dwNumberOfProcessors : DWORD; |
| 272 |
dwProcessorType : DWORD; |
| 273 |
dwAllocationGranularity : DWORD; |
| 274 |
dwReserved : DWORD; |
| 275 |
end record; |
| 276 |
pragma Convention (C_Pass_By_Copy, SYSTEM_INFO); |
| 277 |
|
| 278 |
procedure GetSystemInfo (SI : access SYSTEM_INFO); |
| 279 |
pragma Import (Stdcall, GetSystemInfo, "GetSystemInfo"); |
| 280 |
|
| 281 |
--------------------- |
| 282 |
-- Time Management -- |
| 283 |
--------------------- |
| 284 |
|
| 285 |
type SYSTEMTIME is record |
| 286 |
wYear : WORD; |
| 287 |
wMonth : WORD; |
| 288 |
wDayOfWeek : WORD; |
| 289 |
wDay : WORD; |
| 290 |
wHour : WORD; |
| 291 |
wMinute : WORD; |
| 292 |
wSecond : WORD; |
| 293 |
wMilliseconds : WORD; |
| 294 |
end record; |
| 295 |
pragma Convention (C_Pass_By_Copy, SYSTEMTIME); |
| 296 |
|
| 297 |
procedure GetSystemTime (pSystemTime : access SYSTEMTIME); |
| 298 |
pragma Import (Stdcall, GetSystemTime, "GetSystemTime"); |
| 299 |
|
| 300 |
procedure GetSystemTimeAsFileTime (lpFileTime : access Long_Long_Integer); |
| 301 |
pragma Import (Stdcall, GetSystemTimeAsFileTime, "GetSystemTimeAsFileTime"); |
| 302 |
|
| 303 |
function FileTimeToSystemTime |
| 304 |
(lpFileTime : access Long_Long_Integer; |
| 305 |
lpSystemTime : access SYSTEMTIME) return BOOL; |
| 306 |
pragma Import (Stdcall, FileTimeToSystemTime, "FileTimeToSystemTime"); |
| 307 |
|
| 308 |
function SystemTimeToFileTime |
| 309 |
(lpSystemTime : access SYSTEMTIME; |
| 310 |
lpFileTime : access Long_Long_Integer) return BOOL; |
| 311 |
pragma Import (Stdcall, SystemTimeToFileTime, "SystemTimeToFileTime"); |
| 312 |
|
| 313 |
function FileTimeToLocalFileTime |
| 314 |
(lpFileTime : access Long_Long_Integer; |
| 315 |
lpLocalFileTime : access Long_Long_Integer) return BOOL; |
| 316 |
pragma Import (Stdcall, FileTimeToLocalFileTime, "FileTimeToLocalFileTime"); |
| 317 |
|
| 318 |
function LocalFileTimeToFileTime |
| 319 |
(lpLocalFileTime : access Long_Long_Integer; |
| 320 |
lpFileTime : access Long_Long_Integer) return BOOL; |
| 321 |
pragma Import (Stdcall, LocalFileTimeToFileTime, "LocalFileTimeToFileTime"); |
| 322 |
|
| 323 |
procedure Sleep (dwMilliseconds : DWORD); |
| 324 |
pragma Import (Stdcall, Sleep, External_Name => "Sleep"); |
| 325 |
|
| 326 |
function QueryPerformanceCounter |
| 327 |
(lpPerformanceCount : access LARGE_INTEGER) return BOOL; |
| 328 |
pragma Import |
| 329 |
(Stdcall, QueryPerformanceCounter, "QueryPerformanceCounter"); |
| 330 |
|
| 331 |
------------ |
| 332 |
-- Module -- |
| 333 |
------------ |
| 334 |
|
| 335 |
function GetModuleHandleEx |
| 336 |
(dwFlags : DWORD; |
| 337 |
lpModuleName : Address; |
| 338 |
phModule : access HANDLE) return BOOL; |
| 339 |
pragma Import (Stdcall, GetModuleHandleEx, "GetModuleHandleExA"); |
| 340 |
|
| 341 |
function GetModuleFileName |
| 342 |
(hModule : HANDLE; |
| 343 |
lpFilename : Address; |
| 344 |
nSize : DWORD) return DWORD; |
| 345 |
pragma Import (Stdcall, GetModuleFileName, "GetModuleFileNameA"); |
| 346 |
|
| 347 |
function FreeLibrary (hModule : HANDLE) return BOOL; |
| 348 |
pragma Import (Stdcall, FreeLibrary, "FreeLibrary"); |
| 349 |
|
| 350 |
end System.Win32; |