wow64win: Add initial user callbacks support.
[wine.git] / dlls / wow64win / wow64win_private.h
blob643875c69ce1fbfc84cd0805c56250924ab4202e
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 __WOW64WIN_PRIVATE_H
22 #define __WOW64WIN_PRIVATE_H
24 #include "syscall.h"
26 #define SYSCALL_ENTRY(func) extern NTSTATUS WINAPI wow64_ ## func( UINT *args ) DECLSPEC_HIDDEN;
27 ALL_WIN32_SYSCALLS
28 #undef SYSCALL_ENTRY
30 typedef NTSTATUS (WINAPI *user_callback)( void *params, ULONG size );
31 extern user_callback user_callbacks[] DECLSPEC_HIDDEN;
33 void * WINAPI Wow64AllocateTemp( SIZE_T size );
34 NTSTATUS WINAPI Wow64KiUserCallbackDispatcher( ULONG id, void *args, ULONG len,
35 void **ret_ptr, ULONG *ret_len );
37 struct object_attr64
39 OBJECT_ATTRIBUTES attr;
40 UNICODE_STRING str;
41 SECURITY_DESCRIPTOR sd;
44 typedef struct
46 ULONG Length;
47 ULONG RootDirectory;
48 ULONG ObjectName;
49 ULONG Attributes;
50 ULONG SecurityDescriptor;
51 ULONG SecurityQualityOfService;
52 } OBJECT_ATTRIBUTES32;
54 static inline ULONG get_ulong( UINT **args ) { return *(*args)++; }
55 static inline HANDLE get_handle( UINT **args ) { return LongToHandle( *(*args)++ ); }
56 static inline void *get_ptr( UINT **args ) { return ULongToPtr( *(*args)++ ); }
58 static inline void **addr_32to64( void **addr, ULONG *addr32 )
60 if (!addr32) return NULL;
61 *addr = ULongToPtr( *addr32 );
62 return addr;
65 static inline SIZE_T *size_32to64( SIZE_T *size, ULONG *size32 )
67 if (!size32) return NULL;
68 *size = *size32;
69 return size;
72 static inline void put_addr( ULONG *addr32, void *addr )
74 if (addr32) *addr32 = PtrToUlong( addr );
77 static inline void put_size( ULONG *size32, SIZE_T size )
79 if (size32) *size32 = min( size, MAXDWORD );
82 static inline UNICODE_STRING *unicode_str_32to64( UNICODE_STRING *str, const UNICODE_STRING32 *str32 )
84 if (!str32) return NULL;
85 str->Length = str32->Length;
86 str->MaximumLength = str32->MaximumLength;
87 str->Buffer = ULongToPtr( str32->Buffer );
88 return str;
91 static inline SECURITY_DESCRIPTOR *secdesc_32to64( SECURITY_DESCRIPTOR *out, const SECURITY_DESCRIPTOR *in )
93 /* relative descr has the same layout for 32 and 64 */
94 const SECURITY_DESCRIPTOR_RELATIVE *sd = (const SECURITY_DESCRIPTOR_RELATIVE *)in;
96 if (!in) return NULL;
97 out->Revision = sd->Revision;
98 out->Sbz1 = sd->Sbz1;
99 out->Control = sd->Control & ~SE_SELF_RELATIVE;
100 if (sd->Control & SE_SELF_RELATIVE)
102 if (sd->Owner) out->Owner = (PSID)((BYTE *)sd + sd->Owner);
103 if (sd->Group) out->Group = (PSID)((BYTE *)sd + sd->Group);
104 if ((sd->Control & SE_SACL_PRESENT) && sd->Sacl) out->Sacl = (PSID)((BYTE *)sd + sd->Sacl);
105 if ((sd->Control & SE_DACL_PRESENT) && sd->Dacl) out->Dacl = (PSID)((BYTE *)sd + sd->Dacl);
107 else
109 out->Owner = ULongToPtr( sd->Owner );
110 out->Group = ULongToPtr( sd->Group );
111 if (sd->Control & SE_SACL_PRESENT) out->Sacl = ULongToPtr( sd->Sacl );
112 if (sd->Control & SE_DACL_PRESENT) out->Dacl = ULongToPtr( sd->Dacl );
114 return out;
117 static inline OBJECT_ATTRIBUTES *objattr_32to64( struct object_attr64 *out, const OBJECT_ATTRIBUTES32 *in )
119 memset( out, 0, sizeof(*out) );
120 if (!in) return NULL;
121 if (in->Length != sizeof(*in)) return &out->attr;
123 out->attr.Length = sizeof(out->attr);
124 out->attr.RootDirectory = LongToHandle( in->RootDirectory );
125 out->attr.Attributes = in->Attributes;
126 out->attr.ObjectName = unicode_str_32to64( &out->str, ULongToPtr( in->ObjectName ));
127 out->attr.SecurityQualityOfService = ULongToPtr( in->SecurityQualityOfService );
128 out->attr.SecurityDescriptor = secdesc_32to64( &out->sd, ULongToPtr( in->SecurityDescriptor ));
129 return &out->attr;
132 static inline void set_last_error32( DWORD err )
134 TEB *teb = NtCurrentTeb();
135 TEB32 *teb32 = (TEB32 *)((char *)teb + teb->WowTebOffset);
136 teb32->LastErrorValue = err;
139 #endif /* __WOW64WIN_PRIVATE_H */