makefiles: Always use the global SOURCES variable for .l files.
[wine.git] / dlls / wow64 / wow64_private.h
blobc063704859a51d7ada9cdba8c2313ddd75469adf
1 /*
2 * WoW64 private definitions
4 * Copyright 2021 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __WOW64_PRIVATE_H
22 #define __WOW64_PRIVATE_H
24 #include "syscall.h"
25 #include "struct32.h"
27 #define SYSCALL_ENTRY(func) extern NTSTATUS WINAPI wow64_ ## func( UINT *args ) DECLSPEC_HIDDEN;
28 ALL_SYSCALLS
29 #undef SYSCALL_ENTRY
31 extern void init_image_mapping( HMODULE module ) DECLSPEC_HIDDEN;
32 extern void init_file_redirects(void) DECLSPEC_HIDDEN;
33 extern BOOL get_file_redirect( OBJECT_ATTRIBUTES *attr ) DECLSPEC_HIDDEN;
35 extern USHORT native_machine DECLSPEC_HIDDEN;
36 extern USHORT current_machine DECLSPEC_HIDDEN;
37 extern ULONG_PTR args_alignment DECLSPEC_HIDDEN;
38 extern ULONG_PTR highest_user_address DECLSPEC_HIDDEN;
39 extern ULONG_PTR default_zero_bits DECLSPEC_HIDDEN;
40 extern SYSTEM_DLL_INIT_BLOCK *pLdrSystemDllInitBlock DECLSPEC_HIDDEN;
42 extern void (WINAPI *pBTCpuNotifyFlushInstructionCache2)( const void *, SIZE_T );
43 extern void (WINAPI *pBTCpuNotifyMapViewOfSection)( void * );
44 extern void (WINAPI *pBTCpuNotifyMemoryAlloc)( void *, SIZE_T, ULONG, ULONG );
45 extern void (WINAPI *pBTCpuNotifyMemoryDirty)( void *, SIZE_T );
46 extern void (WINAPI *pBTCpuNotifyMemoryFree)( void *, SIZE_T, ULONG );
47 extern void (WINAPI *pBTCpuNotifyMemoryProtect)( void *, SIZE_T, ULONG );
48 extern void (WINAPI *pBTCpuNotifyUnmapViewOfSection)( void * );
49 extern void (WINAPI *pBTCpuUpdateProcessorInformation)( SYSTEM_CPU_INFORMATION * );
50 extern void (WINAPI *pBTCpuThreadTerm)( HANDLE );
52 struct object_attr64
54 OBJECT_ATTRIBUTES attr;
55 UNICODE_STRING str;
56 SECURITY_DESCRIPTOR sd;
59 /* cf. GetSystemWow64Directory2 */
60 static inline const WCHAR *get_machine_wow64_dir( USHORT machine )
62 switch (machine)
64 case IMAGE_FILE_MACHINE_TARGET_HOST: return L"\\??\\C:\\windows\\system32";
65 case IMAGE_FILE_MACHINE_I386: return L"\\??\\C:\\windows\\syswow64";
66 case IMAGE_FILE_MACHINE_ARMNT: return L"\\??\\C:\\windows\\sysarm32";
67 case IMAGE_FILE_MACHINE_AMD64: return L"\\??\\C:\\windows\\sysx8664";
68 case IMAGE_FILE_MACHINE_ARM64: return L"\\??\\C:\\windows\\sysarm64";
69 default: return NULL;
73 static inline ULONG get_ulong( UINT **args ) { return *(*args)++; }
74 static inline HANDLE get_handle( UINT **args ) { return LongToHandle( *(*args)++ ); }
75 static inline void *get_ptr( UINT **args ) { return ULongToPtr( *(*args)++ ); }
77 static inline ULONG64 get_ulong64( UINT **args )
79 ULONG64 ret;
81 *args = (UINT *)(((ULONG_PTR)*args + args_alignment - 1) & ~(args_alignment - 1));
82 ret = *(ULONG64 *)*args;
83 *args += 2;
84 return ret;
87 static inline ULONG_PTR get_zero_bits( ULONG_PTR zero_bits )
89 return zero_bits ? zero_bits : default_zero_bits;
92 static inline void **addr_32to64( void **addr, ULONG *addr32 )
94 if (!addr32) return NULL;
95 *addr = ULongToPtr( *addr32 );
96 return addr;
99 static inline SIZE_T *size_32to64( SIZE_T *size, ULONG *size32 )
101 if (!size32) return NULL;
102 *size = *size32;
103 return size;
106 static inline void *apc_32to64( ULONG func )
108 return func ? Wow64ApcRoutine : NULL;
111 static inline void *apc_param_32to64( ULONG func, ULONG context )
113 if (!func) return ULongToPtr( context );
114 return (void *)(ULONG_PTR)(((ULONG64)func << 32) | context);
117 static inline IO_STATUS_BLOCK *iosb_32to64( IO_STATUS_BLOCK *io, IO_STATUS_BLOCK32 *io32 )
119 if (!io32) return NULL;
120 io->Pointer = io32;
121 return io;
124 static inline UNICODE_STRING *unicode_str_32to64( UNICODE_STRING *str, const UNICODE_STRING32 *str32 )
126 if (!str32) return NULL;
127 str->Length = str32->Length;
128 str->MaximumLength = str32->MaximumLength;
129 str->Buffer = ULongToPtr( str32->Buffer );
130 return str;
133 static inline CLIENT_ID *client_id_32to64( CLIENT_ID *id, const CLIENT_ID32 *id32 )
135 if (!id32) return NULL;
136 id->UniqueProcess = LongToHandle( id32->UniqueProcess );
137 id->UniqueThread = LongToHandle( id32->UniqueThread );
138 return id;
141 static inline SECURITY_DESCRIPTOR *secdesc_32to64( SECURITY_DESCRIPTOR *out, const SECURITY_DESCRIPTOR *in )
143 /* relative descr has the same layout for 32 and 64 */
144 const SECURITY_DESCRIPTOR_RELATIVE *sd = (const SECURITY_DESCRIPTOR_RELATIVE *)in;
146 if (!in) return NULL;
147 out->Revision = sd->Revision;
148 out->Sbz1 = sd->Sbz1;
149 out->Control = sd->Control & ~SE_SELF_RELATIVE;
150 if (sd->Control & SE_SELF_RELATIVE)
152 out->Owner = sd->Owner ? (PSID)((BYTE *)sd + sd->Owner) : NULL;
153 out->Group = sd->Group ? (PSID)((BYTE *)sd + sd->Group) : NULL;
154 out->Sacl = ((sd->Control & SE_SACL_PRESENT) && sd->Sacl) ? (PSID)((BYTE *)sd + sd->Sacl) : NULL;
155 out->Dacl = ((sd->Control & SE_DACL_PRESENT) && sd->Dacl) ? (PSID)((BYTE *)sd + sd->Dacl) : NULL;
157 else
159 out->Owner = ULongToPtr( sd->Owner );
160 out->Group = ULongToPtr( sd->Group );
161 out->Sacl = (sd->Control & SE_SACL_PRESENT) ? ULongToPtr( sd->Sacl ) : NULL;
162 out->Dacl = (sd->Control & SE_DACL_PRESENT) ? ULongToPtr( sd->Dacl ) : NULL;
164 return out;
167 static inline OBJECT_ATTRIBUTES *objattr_32to64( struct object_attr64 *out, const OBJECT_ATTRIBUTES32 *in )
169 memset( out, 0, sizeof(*out) );
170 if (!in) return NULL;
171 if (in->Length != sizeof(*in)) return &out->attr;
173 out->attr.Length = sizeof(out->attr);
174 out->attr.RootDirectory = LongToHandle( in->RootDirectory );
175 out->attr.Attributes = in->Attributes;
176 out->attr.ObjectName = unicode_str_32to64( &out->str, ULongToPtr( in->ObjectName ));
177 out->attr.SecurityQualityOfService = ULongToPtr( in->SecurityQualityOfService );
178 out->attr.SecurityDescriptor = secdesc_32to64( &out->sd, ULongToPtr( in->SecurityDescriptor ));
179 return &out->attr;
182 static inline OBJECT_ATTRIBUTES *objattr_32to64_redirect( struct object_attr64 *out,
183 const OBJECT_ATTRIBUTES32 *in )
185 OBJECT_ATTRIBUTES *attr = objattr_32to64( out, in );
187 if (attr) get_file_redirect( attr );
188 return attr;
191 static inline TOKEN_USER *token_user_32to64( TOKEN_USER *out, const TOKEN_USER32 *in )
193 out->User.Sid = ULongToPtr( in->User.Sid );
194 out->User.Attributes = in->User.Attributes;
195 return out;
198 static inline TOKEN_OWNER *token_owner_32to64( TOKEN_OWNER *out, const TOKEN_OWNER32 *in )
200 out->Owner = ULongToPtr( in->Owner );
201 return out;
204 static inline TOKEN_PRIMARY_GROUP *token_primary_group_32to64( TOKEN_PRIMARY_GROUP *out, const TOKEN_PRIMARY_GROUP32 *in )
206 out->PrimaryGroup = ULongToPtr( in->PrimaryGroup );
207 return out;
210 static inline TOKEN_DEFAULT_DACL *token_default_dacl_32to64( TOKEN_DEFAULT_DACL *out, const TOKEN_DEFAULT_DACL32 *in )
212 out->DefaultDacl = ULongToPtr( in->DefaultDacl );
213 return out;
216 static inline void put_handle( ULONG *handle32, HANDLE handle )
218 *handle32 = HandleToULong( handle );
221 static inline void put_addr( ULONG *addr32, void *addr )
223 if (addr32) *addr32 = PtrToUlong( addr );
226 static inline void put_size( ULONG *size32, SIZE_T size )
228 if (size32) *size32 = min( size, MAXDWORD );
231 static inline void put_client_id( CLIENT_ID32 *id32, const CLIENT_ID *id )
233 if (!id32) return;
234 id32->UniqueProcess = HandleToLong( id->UniqueProcess );
235 id32->UniqueThread = HandleToLong( id->UniqueThread );
238 static inline void put_iosb( IO_STATUS_BLOCK32 *io32, const IO_STATUS_BLOCK *io )
240 /* sync I/O modifies the 64-bit iosb right away, so in that case we update the 32-bit one */
241 /* async I/O leaves the 64-bit one untouched and updates the 32-bit one directly later on */
242 if (io32 && io->Pointer != io32)
244 io32->Status = io->Status;
245 io32->Information = io->Information;
249 extern void put_section_image_info( SECTION_IMAGE_INFORMATION32 *info32,
250 const SECTION_IMAGE_INFORMATION *info ) DECLSPEC_HIDDEN;
251 extern void put_vm_counters( VM_COUNTERS_EX32 *info32, const VM_COUNTERS_EX *info,
252 ULONG size ) DECLSPEC_HIDDEN;
254 #endif /* __WOW64_PRIVATE_H */