dinput: Implement SetProperty DIPROP_APPDATA using enum_objects.
[wine.git] / dlls / wow64 / wow64_private.h
blob1a9d05eaf4398129567fe20e0bec766ea184fa05
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 void * WINAPI Wow64AllocateTemp( SIZE_T size );
32 void WINAPI Wow64ApcRoutine( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3, CONTEXT *context );
33 void WINAPI Wow64PassExceptionToGuest( EXCEPTION_POINTERS *ptrs );
35 extern void init_image_mapping( HMODULE module ) DECLSPEC_HIDDEN;
36 extern void init_file_redirects(void) DECLSPEC_HIDDEN;
37 extern BOOL get_file_redirect( OBJECT_ATTRIBUTES *attr ) DECLSPEC_HIDDEN;
39 extern USHORT native_machine DECLSPEC_HIDDEN;
40 extern USHORT current_machine DECLSPEC_HIDDEN;
41 extern ULONG_PTR args_alignment DECLSPEC_HIDDEN;
42 extern SYSTEM_DLL_INIT_BLOCK *pLdrSystemDllInitBlock DECLSPEC_HIDDEN;
44 struct object_attr64
46 OBJECT_ATTRIBUTES attr;
47 UNICODE_STRING str;
48 SECURITY_DESCRIPTOR sd;
51 static inline void *get_rva( HMODULE module, DWORD va )
53 return (void *)((char *)module + va);
56 /* cf. GetSystemWow64Directory2 */
57 static inline const WCHAR *get_machine_wow64_dir( USHORT machine )
59 switch (machine)
61 case IMAGE_FILE_MACHINE_TARGET_HOST: return L"\\??\\C:\\windows\\system32";
62 case IMAGE_FILE_MACHINE_I386: return L"\\??\\C:\\windows\\syswow64";
63 case IMAGE_FILE_MACHINE_ARMNT: return L"\\??\\C:\\windows\\sysarm32";
64 case IMAGE_FILE_MACHINE_AMD64: return L"\\??\\C:\\windows\\sysx8664";
65 case IMAGE_FILE_MACHINE_ARM64: return L"\\??\\C:\\windows\\sysarm64";
66 default: return NULL;
70 static inline ULONG get_ulong( UINT **args ) { return *(*args)++; }
71 static inline HANDLE get_handle( UINT **args ) { return LongToHandle( *(*args)++ ); }
72 static inline void *get_ptr( UINT **args ) { return ULongToPtr( *(*args)++ ); }
74 static inline ULONG64 get_ulong64( UINT **args )
76 ULONG64 ret;
78 *args = (UINT *)(((ULONG_PTR)*args + args_alignment - 1) & ~(args_alignment - 1));
79 ret = *(ULONG64 *)*args;
80 *args += 2;
81 return ret;
84 static inline ULONG_PTR get_zero_bits( ULONG_PTR zero_bits )
86 return zero_bits ? zero_bits : 0x7fffffff;
89 static inline void **addr_32to64( void **addr, ULONG *addr32 )
91 if (!addr32) return NULL;
92 *addr = ULongToPtr( *addr32 );
93 return addr;
96 static inline SIZE_T *size_32to64( SIZE_T *size, ULONG *size32 )
98 if (!size32) return NULL;
99 *size = *size32;
100 return size;
103 static inline void *apc_32to64( ULONG func )
105 return func ? Wow64ApcRoutine : NULL;
108 static inline void *apc_param_32to64( ULONG func, ULONG context )
110 if (!func) return ULongToPtr( context );
111 return (void *)(ULONG_PTR)(((ULONG64)func << 32) | context);
114 static inline IO_STATUS_BLOCK *iosb_32to64( IO_STATUS_BLOCK *io, IO_STATUS_BLOCK32 *io32 )
116 if (!io32) return NULL;
117 io->Pointer = io32;
118 return io;
121 static inline UNICODE_STRING *unicode_str_32to64( UNICODE_STRING *str, const UNICODE_STRING32 *str32 )
123 if (!str32) return NULL;
124 str->Length = str32->Length;
125 str->MaximumLength = str32->MaximumLength;
126 str->Buffer = ULongToPtr( str32->Buffer );
127 return str;
130 static inline CLIENT_ID *client_id_32to64( CLIENT_ID *id, const CLIENT_ID32 *id32 )
132 if (!id32) return NULL;
133 id->UniqueProcess = LongToHandle( id32->UniqueProcess );
134 id->UniqueThread = LongToHandle( id32->UniqueThread );
135 return id;
138 static inline SECURITY_DESCRIPTOR *secdesc_32to64( SECURITY_DESCRIPTOR *out, const SECURITY_DESCRIPTOR *in )
140 /* relative descr has the same layout for 32 and 64 */
141 const SECURITY_DESCRIPTOR_RELATIVE *sd = (const SECURITY_DESCRIPTOR_RELATIVE *)in;
143 if (!in) return NULL;
144 out->Revision = sd->Revision;
145 out->Sbz1 = sd->Sbz1;
146 out->Control = sd->Control & ~SE_SELF_RELATIVE;
147 if (sd->Control & SE_SELF_RELATIVE)
149 if (sd->Owner) out->Owner = (PSID)((BYTE *)sd + sd->Owner);
150 if (sd->Group) out->Group = (PSID)((BYTE *)sd + sd->Group);
151 if ((sd->Control & SE_SACL_PRESENT) && sd->Sacl) out->Sacl = (PSID)((BYTE *)sd + sd->Sacl);
152 if ((sd->Control & SE_DACL_PRESENT) && sd->Dacl) out->Dacl = (PSID)((BYTE *)sd + sd->Dacl);
154 else
156 out->Owner = ULongToPtr( sd->Owner );
157 out->Group = ULongToPtr( sd->Group );
158 if (sd->Control & SE_SACL_PRESENT) out->Sacl = ULongToPtr( sd->Sacl );
159 if (sd->Control & SE_DACL_PRESENT) out->Dacl = ULongToPtr( sd->Dacl );
161 return out;
164 static inline OBJECT_ATTRIBUTES *objattr_32to64( struct object_attr64 *out, const OBJECT_ATTRIBUTES32 *in )
166 memset( out, 0, sizeof(*out) );
167 if (!in) return NULL;
168 if (in->Length != sizeof(*in)) return &out->attr;
170 out->attr.Length = sizeof(out->attr);
171 out->attr.RootDirectory = LongToHandle( in->RootDirectory );
172 out->attr.Attributes = in->Attributes;
173 out->attr.ObjectName = unicode_str_32to64( &out->str, ULongToPtr( in->ObjectName ));
174 out->attr.SecurityQualityOfService = ULongToPtr( in->SecurityQualityOfService );
175 out->attr.SecurityDescriptor = secdesc_32to64( &out->sd, ULongToPtr( in->SecurityDescriptor ));
176 return &out->attr;
179 static inline OBJECT_ATTRIBUTES *objattr_32to64_redirect( struct object_attr64 *out,
180 const OBJECT_ATTRIBUTES32 *in )
182 OBJECT_ATTRIBUTES *attr = objattr_32to64( out, in );
184 if (attr) get_file_redirect( attr );
185 return attr;
188 static inline void put_handle( ULONG *handle32, HANDLE handle )
190 *handle32 = HandleToULong( handle );
193 static inline void put_addr( ULONG *addr32, void *addr )
195 if (addr32) *addr32 = PtrToUlong( addr );
198 static inline void put_size( ULONG *size32, SIZE_T size )
200 if (size32) *size32 = min( size, MAXDWORD );
203 static inline void put_client_id( CLIENT_ID32 *id32, const CLIENT_ID *id )
205 if (!id32) return;
206 id32->UniqueProcess = HandleToLong( id->UniqueProcess );
207 id32->UniqueThread = HandleToLong( id->UniqueThread );
210 static inline void put_iosb( IO_STATUS_BLOCK32 *io32, const IO_STATUS_BLOCK *io )
212 /* sync I/O modifies the 64-bit iosb right away, so in that case we update the 32-bit one */
213 /* async I/O leaves the 64-bit one untouched and updates the 32-bit one directly later on */
214 if (io32 && io->Pointer != io32)
216 io32->Status = io->Status;
217 io32->Information = io->Information;
221 extern void put_section_image_info( SECTION_IMAGE_INFORMATION32 *info32,
222 const SECTION_IMAGE_INFORMATION *info ) DECLSPEC_HIDDEN;
223 extern void put_vm_counters( VM_COUNTERS_EX32 *info32, const VM_COUNTERS_EX *info,
224 ULONG size ) DECLSPEC_HIDDEN;
226 #endif /* __WOW64_PRIVATE_H */