4 * Copyright 1996, 2003 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
24 #include <sys/types.h>
26 #define NONAMELESSUNION
28 #define WIN32_NO_STATUS
30 #include "wine/debug.h"
31 #include "ntdll_misc.h"
33 #include "wine/exception.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(thread
);
36 WINE_DECLARE_DEBUG_CHANNEL(relay
);
37 WINE_DECLARE_DEBUG_CHANNEL(pid
);
38 WINE_DECLARE_DEBUG_CHANNEL(timestamp
);
40 struct _KUSER_SHARED_DATA
*user_shared_data
= (void *)0x7ffe0000;
44 unsigned int str_pos
; /* current position in strings buffer */
45 unsigned int out_pos
; /* current position in output buffer */
46 char strings
[1020]; /* buffer for temporary strings */
47 char output
[1020]; /* current output line */
50 C_ASSERT( sizeof(struct debug_info
) == 0x800 );
52 static int nb_debug_options
;
53 static struct __wine_debug_channel
*debug_options
;
55 static inline struct debug_info
*get_info(void)
58 return (struct debug_info
*)((TEB32
*)((char *)NtCurrentTeb() + 0x2000) + 1);
60 return (struct debug_info
*)(NtCurrentTeb() + 1);
64 static void init_options(void)
66 unsigned int offset
= page_size
* (sizeof(void *) / 4);
68 debug_options
= (struct __wine_debug_channel
*)((char *)NtCurrentTeb()->Peb
+ offset
);
69 while (debug_options
[nb_debug_options
].name
[0]) nb_debug_options
++;
72 /* add a string to the output buffer */
73 static int append_output( struct debug_info
*info
, const char *str
, size_t len
)
75 if (len
>= sizeof(info
->output
) - info
->out_pos
)
77 __wine_dbg_write( info
->output
, info
->out_pos
);
79 ERR_(thread
)( "debug buffer overflow:\n" );
80 __wine_dbg_write( str
, len
);
81 RtlRaiseStatus( STATUS_BUFFER_OVERFLOW
);
83 memcpy( info
->output
+ info
->out_pos
, str
, len
);
88 /***********************************************************************
89 * __wine_dbg_get_channel_flags (NTDLL.@)
91 * Get the flags to use for a given channel, possibly setting them too in case of lazy init
93 unsigned char __cdecl
__wine_dbg_get_channel_flags( struct __wine_debug_channel
*channel
)
95 int min
, max
, pos
, res
;
96 unsigned char default_flags
;
98 if (!debug_options
) init_options();
101 max
= nb_debug_options
- 1;
104 pos
= (min
+ max
) / 2;
105 res
= strcmp( channel
->name
, debug_options
[pos
].name
);
106 if (!res
) return debug_options
[pos
].flags
;
107 if (res
< 0) max
= pos
- 1;
110 /* no option for this channel */
111 default_flags
= debug_options
[nb_debug_options
].flags
;
112 if (channel
->flags
& (1 << __WINE_DBCL_INIT
)) channel
->flags
= default_flags
;
113 return default_flags
;
116 /***********************************************************************
117 * __wine_dbg_strdup (NTDLL.@)
119 const char * __cdecl
__wine_dbg_strdup( const char *str
)
121 struct debug_info
*info
= get_info();
122 unsigned int pos
= info
->str_pos
;
123 size_t n
= strlen( str
) + 1;
125 assert( n
<= sizeof(info
->strings
) );
126 if (pos
+ n
> sizeof(info
->strings
)) pos
= 0;
127 info
->str_pos
= pos
+ n
;
128 return memcpy( info
->strings
+ pos
, str
, n
);
131 /***********************************************************************
132 * __wine_dbg_header (NTDLL.@)
134 int __cdecl
__wine_dbg_header( enum __wine_debug_class cls
, struct __wine_debug_channel
*channel
,
135 const char *function
)
137 static const char * const classes
[] = { "fixme", "err", "warn", "trace" };
138 struct debug_info
*info
= get_info();
139 char *pos
= info
->output
;
141 if (!(__wine_dbg_get_channel_flags( channel
) & (1 << cls
))) return -1;
143 /* only print header if we are at the beginning of the line */
144 if (info
->out_pos
) return 0;
146 if (TRACE_ON(timestamp
))
148 ULONG ticks
= NtGetTickCount();
149 pos
+= sprintf( pos
, "%3lu.%03lu:", ticks
/ 1000, ticks
% 1000 );
151 if (TRACE_ON(pid
)) pos
+= sprintf( pos
, "%04lx:", GetCurrentProcessId() );
152 pos
+= sprintf( pos
, "%04lx:", GetCurrentThreadId() );
153 if (function
&& cls
< ARRAY_SIZE( classes
))
154 pos
+= snprintf( pos
, sizeof(info
->output
) - (pos
- info
->output
), "%s:%s:%s ",
155 classes
[cls
], channel
->name
, function
);
156 info
->out_pos
= pos
- info
->output
;
157 return info
->out_pos
;
160 /***********************************************************************
161 * __wine_dbg_output (NTDLL.@)
163 int __cdecl
__wine_dbg_output( const char *str
)
165 struct debug_info
*info
= get_info();
166 const char *end
= strrchr( str
, '\n' );
171 ret
+= append_output( info
, str
, end
+ 1 - str
);
172 __wine_dbg_write( info
->output
, info
->out_pos
);
176 if (*str
) ret
+= append_output( info
, str
, strlen( str
));
181 /***********************************************************************
182 * set_native_thread_name
184 void set_native_thread_name( DWORD tid
, const char *name
)
186 THREAD_NAME_INFORMATION info
;
187 HANDLE h
= GetCurrentThread();
192 OBJECT_ATTRIBUTES attr
;
195 attr
.Length
= sizeof(attr
);
196 attr
.RootDirectory
= 0;
198 attr
.ObjectName
= NULL
;
199 attr
.SecurityDescriptor
= NULL
;
200 attr
.SecurityQualityOfService
= NULL
;
202 cid
.UniqueProcess
= 0;
203 cid
.UniqueThread
= ULongToHandle( tid
);
205 if (NtOpenThread( &h
, THREAD_QUERY_LIMITED_INFORMATION
, &attr
, &cid
)) return;
210 mbstowcs( nameW
, name
, ARRAY_SIZE(nameW
) );
211 nameW
[ARRAY_SIZE(nameW
) - 1] = '\0';
218 RtlInitUnicodeString( &info
.ThreadName
, nameW
);
219 NtSetInformationThread( h
, ThreadWineNativeThreadName
, &info
, sizeof(info
) );
221 if (h
!= GetCurrentThread())
226 /***********************************************************************
227 * RtlExitUserThread (NTDLL.@)
229 void WINAPI
RtlExitUserThread( ULONG status
)
233 NtQueryInformationThread( GetCurrentThread(), ThreadAmILastThread
, &last
, sizeof(last
), NULL
);
234 if (last
) RtlExitUserProcess( status
);
236 for (;;) NtTerminateThread( GetCurrentThread(), status
);
240 /***********************************************************************
241 * RtlUserThreadStart (NTDLL.@)
244 __ASM_STDCALL_FUNC( RtlUserThreadStart
, 8,
245 "movl %ebx,8(%esp)\n\t" /* arg */
246 "movl %eax,4(%esp)\n\t" /* entry */
247 "jmp " __ASM_NAME("call_thread_func") )
249 /* wrapper to call BaseThreadInitThunk */
250 extern void DECLSPEC_NORETURN
call_thread_func_wrapper( void *thunk
, PRTL_THREAD_START_ROUTINE entry
, void *arg
);
251 __ASM_GLOBAL_FUNC( call_thread_func_wrapper
,
253 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
254 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
256 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
258 "andl $~0xf,%esp\n\t"
260 "movl 12(%ebp),%edx\n\t"
261 "movl 16(%ebp),%eax\n\t"
262 "movl %eax,(%esp)\n\t"
265 void DECLSPEC_HIDDEN
call_thread_func( PRTL_THREAD_START_ROUTINE entry
, void *arg
)
269 TRACE_(relay
)( "\1Starting thread proc %p (arg=%p)\n", entry
, arg
);
270 call_thread_func_wrapper( pBaseThreadInitThunk
, entry
, arg
);
272 __EXCEPT(call_unhandled_exception_filter
)
274 NtTerminateProcess( GetCurrentProcess(), GetExceptionCode() );
281 void WINAPI
RtlUserThreadStart( PRTL_THREAD_START_ROUTINE entry
, void *arg
)
285 TRACE_(relay
)( "\1Starting thread proc %p (arg=%p)\n", entry
, arg
);
286 pBaseThreadInitThunk( 0, (LPTHREAD_START_ROUTINE
)entry
, arg
);
288 __EXCEPT(call_unhandled_exception_filter
)
290 NtTerminateProcess( GetCurrentProcess(), GetExceptionCode() );
295 #endif /* __i386__ */
298 /***********************************************************************
299 * RtlCreateUserThread (NTDLL.@)
301 NTSTATUS WINAPI
RtlCreateUserThread( HANDLE process
, SECURITY_DESCRIPTOR
*descr
,
302 BOOLEAN suspended
, ULONG zero_bits
,
303 SIZE_T stack_reserve
, SIZE_T stack_commit
,
304 PRTL_THREAD_START_ROUTINE start
, void *param
,
305 HANDLE
*handle_ptr
, CLIENT_ID
*id
)
307 ULONG flags
= suspended
? THREAD_CREATE_FLAGS_CREATE_SUSPENDED
: 0;
308 ULONG_PTR buffer
[offsetof( PS_ATTRIBUTE_LIST
, Attributes
[2] ) / sizeof(ULONG_PTR
)];
309 PS_ATTRIBUTE_LIST
*attr_list
= (PS_ATTRIBUTE_LIST
*)buffer
;
310 HANDLE handle
, actctx
;
315 OBJECT_ATTRIBUTES attr
;
317 attr_list
->TotalLength
= sizeof(buffer
);
318 attr_list
->Attributes
[0].Attribute
= PS_ATTRIBUTE_CLIENT_ID
;
319 attr_list
->Attributes
[0].Size
= sizeof(client_id
);
320 attr_list
->Attributes
[0].ValuePtr
= &client_id
;
321 attr_list
->Attributes
[0].ReturnLength
= NULL
;
322 attr_list
->Attributes
[1].Attribute
= PS_ATTRIBUTE_TEB_ADDRESS
;
323 attr_list
->Attributes
[1].Size
= sizeof(teb
);
324 attr_list
->Attributes
[1].ValuePtr
= &teb
;
325 attr_list
->Attributes
[1].ReturnLength
= NULL
;
327 InitializeObjectAttributes( &attr
, NULL
, 0, NULL
, descr
);
329 RtlGetActiveActivationContext( &actctx
);
330 if (actctx
) flags
|= THREAD_CREATE_FLAGS_CREATE_SUSPENDED
;
332 status
= NtCreateThreadEx( &handle
, THREAD_ALL_ACCESS
, &attr
, process
, start
, param
,
333 flags
, zero_bits
, stack_commit
, stack_reserve
, attr_list
);
339 RtlActivateActivationContextEx( 0, teb
, actctx
, &cookie
);
340 if (!suspended
) NtResumeThread( handle
, &ret
);
342 if (id
) *id
= client_id
;
343 if (handle_ptr
) *handle_ptr
= handle
;
344 else NtClose( handle
);
346 if (actctx
) RtlReleaseActivationContext( actctx
);
351 /**********************************************************************
352 * RtlCreateUserStack (NTDLL.@)
354 NTSTATUS WINAPI
RtlCreateUserStack( SIZE_T commit
, SIZE_T reserve
, ULONG zero_bits
,
355 SIZE_T commit_align
, SIZE_T reserve_align
, INITIAL_TEB
*stack
)
357 PROCESS_STACK_ALLOCATION_INFORMATION alloc
;
360 TRACE("commit %#Ix, reserve %#Ix, zero_bits %lu, commit_align %#Ix, reserve_align %#Ix, stack %p\n",
361 commit
, reserve
, zero_bits
, commit_align
, reserve_align
, stack
);
363 if (!commit_align
|| !reserve_align
)
364 return STATUS_INVALID_PARAMETER
;
366 if (!commit
|| !reserve
)
368 IMAGE_NT_HEADERS
*nt
= RtlImageNtHeader( NtCurrentTeb()->Peb
->ImageBaseAddress
);
369 if (!reserve
) reserve
= nt
->OptionalHeader
.SizeOfStackReserve
;
370 if (!commit
) commit
= nt
->OptionalHeader
.SizeOfStackCommit
;
373 reserve
= (reserve
+ reserve_align
- 1) & ~(reserve_align
- 1);
374 commit
= (commit
+ commit_align
- 1) & ~(commit_align
- 1);
376 if (reserve
< commit
) reserve
= commit
;
377 if (reserve
< 0x100000) reserve
= 0x100000;
378 reserve
= (reserve
+ 0xffff) & ~0xffff; /* round to 64K boundary */
380 alloc
.ReserveSize
= reserve
;
381 alloc
.ZeroBits
= zero_bits
;
382 status
= NtSetInformationProcess( GetCurrentProcess(), ProcessThreadStackAllocation
,
383 &alloc
, sizeof(alloc
) );
386 void *addr
= alloc
.StackBase
;
387 SIZE_T size
= page_size
;
389 NtAllocateVirtualMemory( GetCurrentProcess(), &addr
, 0, &size
, MEM_COMMIT
, PAGE_NOACCESS
);
390 addr
= (char *)alloc
.StackBase
+ page_size
;
391 NtAllocateVirtualMemory( GetCurrentProcess(), &addr
, 0, &size
, MEM_COMMIT
, PAGE_READWRITE
| PAGE_GUARD
);
392 addr
= (char *)alloc
.StackBase
+ 2 * page_size
;
393 size
= reserve
- 2 * page_size
;
394 NtAllocateVirtualMemory( GetCurrentProcess(), &addr
, 0, &size
, MEM_COMMIT
, PAGE_READWRITE
);
396 /* note: limit is lower than base since the stack grows down */
397 stack
->OldStackBase
= 0;
398 stack
->OldStackLimit
= 0;
399 stack
->DeallocationStack
= alloc
.StackBase
;
400 stack
->StackBase
= (char *)alloc
.StackBase
+ reserve
;
401 stack
->StackLimit
= (char *)alloc
.StackBase
+ 2 * page_size
;
407 /**********************************************************************
408 * RtlFreeUserStack (NTDLL.@)
410 void WINAPI
RtlFreeUserStack( void *stack
)
414 TRACE("stack %p\n", stack
);
416 NtFreeVirtualMemory( NtCurrentProcess(), &stack
, &size
, MEM_RELEASE
);
420 /******************************************************************************
421 * RtlGetNtGlobalFlags (NTDLL.@)
423 ULONG WINAPI
RtlGetNtGlobalFlags(void)
425 return NtCurrentTeb()->Peb
->NtGlobalFlag
;
429 /******************************************************************************
430 * RtlPushFrame (NTDLL.@)
432 void WINAPI
RtlPushFrame( TEB_ACTIVE_FRAME
*frame
)
434 frame
->Previous
= NtCurrentTeb()->ActiveFrame
;
435 NtCurrentTeb()->ActiveFrame
= frame
;
439 /******************************************************************************
440 * RtlPopFrame (NTDLL.@)
442 void WINAPI
RtlPopFrame( TEB_ACTIVE_FRAME
*frame
)
444 NtCurrentTeb()->ActiveFrame
= frame
->Previous
;
448 /******************************************************************************
449 * RtlGetFrame (NTDLL.@)
451 TEB_ACTIVE_FRAME
* WINAPI
RtlGetFrame(void)
453 return NtCurrentTeb()->ActiveFrame
;
457 /***********************************************************************
459 ***********************************************************************/
462 static GLOBAL_FLS_DATA fls_data
= { { NULL
}, { &fls_data
.fls_list_head
, &fls_data
.fls_list_head
} };
464 static RTL_CRITICAL_SECTION fls_section
;
465 static RTL_CRITICAL_SECTION_DEBUG fls_critsect_debug
=
468 { &fls_critsect_debug
.ProcessLocksList
, &fls_critsect_debug
.ProcessLocksList
},
469 0, 0, { (DWORD_PTR
)(__FILE__
": fls_section") }
471 static RTL_CRITICAL_SECTION fls_section
= { &fls_critsect_debug
, -1, 0, 0, 0, 0 };
473 #define MAX_FLS_DATA_COUNT 0xff0
475 static void lock_fls_data(void)
477 RtlEnterCriticalSection( &fls_section
);
480 static void unlock_fls_data(void)
482 RtlLeaveCriticalSection( &fls_section
);
485 static unsigned int fls_chunk_size( unsigned int chunk_index
)
487 return 0x10 << chunk_index
;
490 static unsigned int fls_index_from_chunk_index( unsigned int chunk_index
, unsigned int index
)
492 return 0x10 * ((1 << chunk_index
) - 1) + index
;
495 static unsigned int fls_chunk_index_from_index( unsigned int index
, unsigned int *index_in_chunk
)
497 unsigned int chunk_index
= 0;
499 while (index
>= fls_chunk_size( chunk_index
))
500 index
-= fls_chunk_size( chunk_index
++ );
502 *index_in_chunk
= index
;
506 TEB_FLS_DATA
*fls_alloc_data(void)
510 if (!(fls
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*fls
) )))
514 InsertTailList( &fls_data
.fls_list_head
, &fls
->fls_list_entry
);
521 /***********************************************************************
522 * RtlFlsAlloc (NTDLL.@)
524 NTSTATUS WINAPI DECLSPEC_HOTPATCH
RtlFlsAlloc( PFLS_CALLBACK_FUNCTION callback
, ULONG
*ret_index
)
526 unsigned int chunk_index
, index
, i
;
527 FLS_INFO_CHUNK
*chunk
;
530 if (!(fls
= NtCurrentTeb()->FlsSlots
)
531 && !(NtCurrentTeb()->FlsSlots
= fls
= fls_alloc_data()))
532 return STATUS_NO_MEMORY
;
535 for (i
= 0; i
< ARRAY_SIZE(fls_data
.fls_callback_chunks
); ++i
)
537 if (!fls_data
.fls_callback_chunks
[i
] || fls_data
.fls_callback_chunks
[i
]->count
< fls_chunk_size( i
))
541 if ((chunk_index
= i
) == ARRAY_SIZE(fls_data
.fls_callback_chunks
))
544 return STATUS_NO_MEMORY
;
547 if ((chunk
= fls_data
.fls_callback_chunks
[chunk_index
]))
549 for (index
= 0; index
< fls_chunk_size( chunk_index
); ++index
)
550 if (!chunk
->callbacks
[index
].callback
)
552 assert( index
< fls_chunk_size( chunk_index
));
556 fls_data
.fls_callback_chunks
[chunk_index
] = chunk
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
,
557 offsetof(FLS_INFO_CHUNK
, callbacks
) + sizeof(*chunk
->callbacks
) * fls_chunk_size( chunk_index
));
561 return STATUS_NO_MEMORY
;
570 chunk
->count
= 1; /* FLS index 0 is prohibited. */
571 chunk
->callbacks
[0].callback
= (void *)~(ULONG_PTR
)0;
577 chunk
->callbacks
[index
].callback
= callback
? callback
: (PFLS_CALLBACK_FUNCTION
)~(ULONG_PTR
)0;
579 if ((*ret_index
= fls_index_from_chunk_index( chunk_index
, index
)) > fls_data
.fls_high_index
)
580 fls_data
.fls_high_index
= *ret_index
;
584 return STATUS_SUCCESS
;
588 /***********************************************************************
589 * RtlFlsFree (NTDLL.@)
591 NTSTATUS WINAPI DECLSPEC_HOTPATCH
RtlFlsFree( ULONG index
)
593 PFLS_CALLBACK_FUNCTION callback
;
594 unsigned int chunk_index
, idx
;
595 FLS_INFO_CHUNK
*chunk
;
600 if (!index
|| index
> fls_data
.fls_high_index
)
603 return STATUS_INVALID_PARAMETER
;
606 chunk_index
= fls_chunk_index_from_index( index
, &idx
);
607 if (!(chunk
= fls_data
.fls_callback_chunks
[chunk_index
])
608 || !(callback
= chunk
->callbacks
[idx
].callback
))
611 return STATUS_INVALID_PARAMETER
;
614 for (entry
= fls_data
.fls_list_head
.Flink
; entry
!= &fls_data
.fls_list_head
; entry
= entry
->Flink
)
616 TEB_FLS_DATA
*fls
= CONTAINING_RECORD(entry
, TEB_FLS_DATA
, fls_list_entry
);
618 if (fls
->fls_data_chunks
[chunk_index
] && fls
->fls_data_chunks
[chunk_index
][idx
+ 1])
620 if (callback
!= (void *)~(ULONG_PTR
)0)
622 TRACE_(relay
)("Calling FLS callback %p, arg %p.\n", callback
,
623 fls
->fls_data_chunks
[chunk_index
][idx
+ 1]);
625 callback( fls
->fls_data_chunks
[chunk_index
][idx
+ 1] );
627 fls
->fls_data_chunks
[chunk_index
][idx
+ 1] = NULL
;
632 chunk
->callbacks
[idx
].callback
= NULL
;
635 return STATUS_SUCCESS
;
639 /***********************************************************************
640 * RtlFlsSetValue (NTDLL.@)
642 NTSTATUS WINAPI DECLSPEC_HOTPATCH
RtlFlsSetValue( ULONG index
, void *data
)
644 unsigned int chunk_index
, idx
;
647 if (!index
|| index
>= MAX_FLS_DATA_COUNT
)
648 return STATUS_INVALID_PARAMETER
;
650 if (!(fls
= NtCurrentTeb()->FlsSlots
)
651 && !(NtCurrentTeb()->FlsSlots
= fls
= fls_alloc_data()))
652 return STATUS_NO_MEMORY
;
654 chunk_index
= fls_chunk_index_from_index( index
, &idx
);
656 if (!fls
->fls_data_chunks
[chunk_index
] &&
657 !(fls
->fls_data_chunks
[chunk_index
] = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
,
658 (fls_chunk_size( chunk_index
) + 1) * sizeof(*fls
->fls_data_chunks
[chunk_index
]) )))
659 return STATUS_NO_MEMORY
;
661 fls
->fls_data_chunks
[chunk_index
][idx
+ 1] = data
;
663 return STATUS_SUCCESS
;
667 /***********************************************************************
668 * RtlFlsGetValue (NTDLL.@)
670 NTSTATUS WINAPI DECLSPEC_HOTPATCH
RtlFlsGetValue( ULONG index
, void **data
)
672 unsigned int chunk_index
, idx
;
675 if (!index
|| index
>= MAX_FLS_DATA_COUNT
|| !(fls
= NtCurrentTeb()->FlsSlots
))
676 return STATUS_INVALID_PARAMETER
;
678 chunk_index
= fls_chunk_index_from_index( index
, &idx
);
680 *data
= fls
->fls_data_chunks
[chunk_index
] ? fls
->fls_data_chunks
[chunk_index
][idx
+ 1] : NULL
;
681 return STATUS_SUCCESS
;
685 /***********************************************************************
686 * RtlProcessFlsData (NTDLL.@)
688 void WINAPI DECLSPEC_HOTPATCH
RtlProcessFlsData( void *teb_fls_data
, ULONG flags
)
690 TEB_FLS_DATA
*fls
= teb_fls_data
;
691 unsigned int i
, index
;
693 TRACE_(thread
)( "teb_fls_data %p, flags %#lx.\n", teb_fls_data
, flags
);
696 FIXME_(thread
)( "Unknown flags %#lx.\n", flags
);
704 for (i
= 0; i
< ARRAY_SIZE(fls
->fls_data_chunks
); ++i
)
706 if (!fls
->fls_data_chunks
[i
] || !fls_data
.fls_callback_chunks
[i
]
707 || !fls_data
.fls_callback_chunks
[i
]->count
)
710 for (index
= 0; index
< fls_chunk_size( i
); ++index
)
712 PFLS_CALLBACK_FUNCTION callback
= fls_data
.fls_callback_chunks
[i
]->callbacks
[index
].callback
;
714 if (!fls
->fls_data_chunks
[i
][index
+ 1])
717 if (callback
&& callback
!= (void *)~(ULONG_PTR
)0)
719 TRACE_(relay
)("Calling FLS callback %p, arg %p.\n", callback
,
720 fls
->fls_data_chunks
[i
][index
+ 1]);
722 callback( fls
->fls_data_chunks
[i
][index
+ 1] );
724 fls
->fls_data_chunks
[i
][index
+ 1] = NULL
;
727 /* Not using RemoveEntryList() as Windows does not zero list entry here. */
728 fls
->fls_list_entry
.Flink
->Blink
= fls
->fls_list_entry
.Blink
;
729 fls
->fls_list_entry
.Blink
->Flink
= fls
->fls_list_entry
.Flink
;
735 for (i
= 0; i
< ARRAY_SIZE(fls
->fls_data_chunks
); ++i
)
736 RtlFreeHeap( GetProcessHeap(), 0, fls
->fls_data_chunks
[i
] );
738 RtlFreeHeap( GetProcessHeap(), 0, fls
);