wow64win: Set last error in 32-bit TEB in wow64 thunks.
[wine.git] / dlls / wow64win / wow64win_private.h
blobcf0b2b62e5f10037ea9593a85761d532fc246543
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 void * WINAPI Wow64AllocateTemp( SIZE_T size );
32 struct object_attr64
34 OBJECT_ATTRIBUTES attr;
35 UNICODE_STRING str;
36 SECURITY_DESCRIPTOR sd;
39 typedef struct
41 ULONG Length;
42 ULONG RootDirectory;
43 ULONG ObjectName;
44 ULONG Attributes;
45 ULONG SecurityDescriptor;
46 ULONG SecurityQualityOfService;
47 } OBJECT_ATTRIBUTES32;
49 static inline ULONG get_ulong( UINT **args ) { return *(*args)++; }
50 static inline HANDLE get_handle( UINT **args ) { return LongToHandle( *(*args)++ ); }
51 static inline void *get_ptr( UINT **args ) { return ULongToPtr( *(*args)++ ); }
53 static inline void **addr_32to64( void **addr, ULONG *addr32 )
55 if (!addr32) return NULL;
56 *addr = ULongToPtr( *addr32 );
57 return addr;
60 static inline SIZE_T *size_32to64( SIZE_T *size, ULONG *size32 )
62 if (!size32) return NULL;
63 *size = *size32;
64 return size;
67 static inline void put_addr( ULONG *addr32, void *addr )
69 if (addr32) *addr32 = PtrToUlong( addr );
72 static inline void put_size( ULONG *size32, SIZE_T size )
74 if (size32) *size32 = min( size, MAXDWORD );
77 static inline UNICODE_STRING *unicode_str_32to64( UNICODE_STRING *str, const UNICODE_STRING32 *str32 )
79 if (!str32) return NULL;
80 str->Length = str32->Length;
81 str->MaximumLength = str32->MaximumLength;
82 str->Buffer = ULongToPtr( str32->Buffer );
83 return str;
86 static inline SECURITY_DESCRIPTOR *secdesc_32to64( SECURITY_DESCRIPTOR *out, const SECURITY_DESCRIPTOR *in )
88 /* relative descr has the same layout for 32 and 64 */
89 const SECURITY_DESCRIPTOR_RELATIVE *sd = (const SECURITY_DESCRIPTOR_RELATIVE *)in;
91 if (!in) return NULL;
92 out->Revision = sd->Revision;
93 out->Sbz1 = sd->Sbz1;
94 out->Control = sd->Control & ~SE_SELF_RELATIVE;
95 if (sd->Control & SE_SELF_RELATIVE)
97 if (sd->Owner) out->Owner = (PSID)((BYTE *)sd + sd->Owner);
98 if (sd->Group) out->Group = (PSID)((BYTE *)sd + sd->Group);
99 if ((sd->Control & SE_SACL_PRESENT) && sd->Sacl) out->Sacl = (PSID)((BYTE *)sd + sd->Sacl);
100 if ((sd->Control & SE_DACL_PRESENT) && sd->Dacl) out->Dacl = (PSID)((BYTE *)sd + sd->Dacl);
102 else
104 out->Owner = ULongToPtr( sd->Owner );
105 out->Group = ULongToPtr( sd->Group );
106 if (sd->Control & SE_SACL_PRESENT) out->Sacl = ULongToPtr( sd->Sacl );
107 if (sd->Control & SE_DACL_PRESENT) out->Dacl = ULongToPtr( sd->Dacl );
109 return out;
112 static inline OBJECT_ATTRIBUTES *objattr_32to64( struct object_attr64 *out, const OBJECT_ATTRIBUTES32 *in )
114 memset( out, 0, sizeof(*out) );
115 if (!in) return NULL;
116 if (in->Length != sizeof(*in)) return &out->attr;
118 out->attr.Length = sizeof(out->attr);
119 out->attr.RootDirectory = LongToHandle( in->RootDirectory );
120 out->attr.Attributes = in->Attributes;
121 out->attr.ObjectName = unicode_str_32to64( &out->str, ULongToPtr( in->ObjectName ));
122 out->attr.SecurityQualityOfService = ULongToPtr( in->SecurityQualityOfService );
123 out->attr.SecurityDescriptor = secdesc_32to64( &out->sd, ULongToPtr( in->SecurityDescriptor ));
124 return &out->attr;
127 static inline void set_last_error32( DWORD err )
129 TEB *teb = NtCurrentTeb();
130 TEB32 *teb32 = (TEB32 *)((char *)teb + teb->WowTebOffset);
131 teb32->LastErrorValue = err;
134 #endif /* __WOW64WIN_PRIVATE_H */