@@ -138,13 +138,39 @@ pub(in crate::windows) struct ChildParams {
138
138
// TODO: upstream to winapi: https://github.com/retep998/winapi-rs/pull/933/
139
139
const MAGIC_PROC_THREAD_ATTRIBUTE_SECURITY_CAPABILITIES : usize = 131081 ;
140
140
141
+ struct AlignedMemBlock ( * mut u8 , usize ) ;
142
+
143
+ impl AlignedMemBlock {
144
+ fn layout ( cnt : usize ) -> std:: alloc:: Layout {
145
+ assert ! ( cnt > 0 ) ;
146
+ std:: alloc:: Layout :: from_size_align ( cnt, 8 ) . unwrap ( )
147
+ }
148
+
149
+ fn new ( cnt : usize ) -> AlignedMemBlock {
150
+ let ptr = unsafe { std:: alloc:: alloc_zeroed ( Self :: layout ( cnt) ) } ;
151
+ AlignedMemBlock ( ptr, cnt)
152
+ }
153
+
154
+ fn ptr ( & self ) -> * mut u8 {
155
+ self . 0
156
+ }
157
+ }
158
+
159
+ impl Drop for AlignedMemBlock {
160
+ fn drop ( & mut self ) {
161
+ unsafe {
162
+ std:: alloc:: dealloc ( self . 0 , Self :: layout ( self . 1 ) ) ;
163
+ }
164
+ }
165
+ }
166
+
141
167
pub ( in crate :: windows) fn spawn (
142
168
sandbox : & WindowsSandbox ,
143
169
stdio : Stdio ,
144
170
params : ChildParams ,
145
171
) -> Result < PROCESS_INFORMATION , Error > {
146
- let mut proc_thread_attr_list_storage: Vec < u64 > ;
147
- let mut security_capabilities: ( ) ;
172
+ let mut proc_thread_attr_list_storage;
173
+ let mut security_capabilities;
148
174
let mut startup_info = unsafe {
149
175
let mut startup_info: STARTUPINFOEXW = std:: mem:: zeroed ( ) ;
150
176
let mut proc_thread_attr_list_len = 0 ;
@@ -160,26 +186,28 @@ pub(in crate::windows) fn spawn(
160
186
return Err ( Error :: last ( ) ) ;
161
187
}
162
188
}
163
- proc_thread_attr_list_storage = Vec :: with_capacity ( ( proc_thread_attr_list_len - 1 ) / 8 + 1 ) ;
164
- let proc_thread_attr_list: * mut u8 = proc_thread_attr_list_storage. as_mut_ptr ( ) . cast ( ) ;
165
- proc_thread_attr_list. write_bytes ( 0 , proc_thread_attr_list_len) ;
189
+ proc_thread_attr_list_storage = AlignedMemBlock :: new ( proc_thread_attr_list_len) ;
190
+ let proc_thread_attr_list = proc_thread_attr_list_storage. ptr ( ) ;
166
191
startup_info. lpAttributeList = proc_thread_attr_list. cast ( ) ;
167
192
Cvt :: nonzero ( InitializeProcThreadAttributeList (
168
193
startup_info. lpAttributeList ,
169
194
1 ,
170
195
0 ,
171
196
& mut proc_thread_attr_list_len,
172
197
) ) ?;
173
- /* security_capabilities = sandbox.profile.get_security_capabilities();
198
+ security_capabilities = sandbox. profile . get_security_capabilities ( ) ;
174
199
Cvt :: nonzero ( UpdateProcThreadAttribute (
175
200
startup_info. lpAttributeList ,
201
+ // reserved
176
202
0 ,
177
203
MAGIC_PROC_THREAD_ATTRIBUTE_SECURITY_CAPABILITIES ,
178
204
( & mut security_capabilities as * mut SECURITY_CAPABILITIES ) . cast ( ) ,
179
205
std:: mem:: size_of :: < SECURITY_ATTRIBUTES > ( ) ,
206
+ // reserved
180
207
std:: ptr:: null_mut ( ) ,
208
+ // reserved
181
209
std:: ptr:: null_mut ( ) ,
182
- ))?;*/
210
+ ) ) ?;
183
211
184
212
startup_info. StartupInfo . cb = size_of :: < STARTUPINFOEXW > ( ) as u32 ;
185
213
startup_info. StartupInfo . dwFlags = STARTF_USESTDHANDLES ;
@@ -211,13 +239,12 @@ pub(in crate::windows) fn spawn(
211
239
// inherit handles
212
240
TRUE ,
213
241
creation_flags,
214
- // TEMP DEBUG
215
- std:: ptr:: null_mut ( ) ,
216
- //env.as_mut_ptr().cast(),
242
+ env. as_mut_ptr ( ) . cast ( ) ,
217
243
cwd. as_ptr ( ) ,
218
244
( & mut startup_info as * mut STARTUPINFOEXW ) . cast ( ) ,
219
245
& mut info,
220
246
) ) ?;
247
+ DeleteProcThreadAttributeList ( startup_info. lpAttributeList ) ;
221
248
}
222
249
Ok ( info)
223
250
}
0 commit comments