Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
2bcc9d45
Commit
2bcc9d45
authored
May 24, 2011
by
Piotr Caban
Committed by
Alexandre Julliard
May 25, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
msvcrt: Close thread handle when _beginthread is used.
parent
ee5a3216
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
18 deletions
+44
-18
main.c
dlls/msvcrt/main.c
+1
-0
msvcrt.h
dlls/msvcrt/msvcrt.h
+2
-0
thread.c
dlls/msvcrt/thread.c
+41
-18
No files found.
dlls/msvcrt/main.c
View file @
2bcc9d45
...
...
@@ -66,6 +66,7 @@ static inline void msvcrt_free_tls_mem(void)
thread_data_t
*
tls
=
TlsGetValue
(
msvcrt_tls_index
);
if
(
tls
)
{
CloseHandle
(
tls
->
handle
);
HeapFree
(
GetProcessHeap
(),
0
,
tls
->
efcvt_buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
tls
->
asctime_buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
tls
->
wasctime_buffer
);
...
...
dlls/msvcrt/msvcrt.h
View file @
2bcc9d45
...
...
@@ -107,6 +107,8 @@ struct MSVCRT_tm {
extern
DWORD
msvcrt_tls_index
;
struct
__thread_data
{
DWORD
tid
;
HANDLE
handle
;
int
thread_errno
;
MSVCRT_ulong
thread_doserrno
;
unsigned
int
random_seed
;
/* seed for rand() */
...
...
dlls/msvcrt/thread.c
View file @
2bcc9d45
...
...
@@ -25,6 +25,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
/********************************************************************/
typedef
struct
{
HANDLE
is_ready
,
thread
;
MSVCRT__beginthread_start_routine_t
start_address
;
void
*
arglist
;
}
_beginthread_trampoline_t
;
...
...
@@ -44,6 +45,8 @@ thread_data_t *msvcrt_get_thread_data(void)
if
(
!
(
ptr
=
HeapAlloc
(
GetProcessHeap
(),
HEAP_ZERO_MEMORY
,
sizeof
(
*
ptr
)
)))
_amsg_exit
(
_RT_THREAD
);
if
(
!
TlsSetValue
(
msvcrt_tls_index
,
ptr
))
_amsg_exit
(
_RT_THREAD
);
ptr
->
tid
=
GetCurrentThreadId
();
ptr
->
handle
=
INVALID_HANDLE_VALUE
;
ptr
->
random_seed
=
1
;
}
SetLastError
(
err
);
...
...
@@ -56,13 +59,19 @@ thread_data_t *msvcrt_get_thread_data(void)
*/
static
DWORD
CALLBACK
_beginthread_trampoline
(
LPVOID
arg
)
{
_beginthread_trampoline_t
local_trampoline
;
_beginthread_trampoline_t
local_trampoline
,
*
trampoline
=
arg
;
thread_data_t
*
data
=
msvcrt_get_thread_data
();
if
(
!
DuplicateHandle
(
GetCurrentProcess
(),
GetCurrentThread
(),
GetCurrentProcess
(),
&
trampoline
->
thread
,
0
,
TRUE
,
DUPLICATE_SAME_ACCESS
))
{
trampoline
->
thread
=
NULL
;
SetEvent
(
&
trampoline
->
is_ready
);
return
0
;
}
/* Maybe it's just being paranoid, but freeing arg right
* away seems safer.
*/
memcpy
(
&
local_trampoline
,
arg
,
sizeof
(
local_trampoline
));
MSVCRT_free
(
arg
);
memcpy
(
&
local_trampoline
,
trampoline
,
sizeof
(
local_trampoline
));
data
->
handle
=
local_trampoline
.
thread
;
SetEvent
(
trampoline
->
is_ready
);
local_trampoline
.
start_address
(
local_trampoline
.
arglist
);
return
0
;
...
...
@@ -76,21 +85,35 @@ MSVCRT_uintptr_t CDECL _beginthread(
unsigned
int
stack_size
,
/* [in] Stack size for new thread or 0 */
void
*
arglist
)
/* [in] Argument list to be passed to new thread or NULL */
{
_beginthread_trampoline_t
*
trampoline
;
_beginthread_trampoline_t
trampoline
;
HANDLE
thread
;
TRACE
(
"(%p, %d, %p)
\n
"
,
start_address
,
stack_size
,
arglist
);
/* Allocate the trampoline here so that it is still valid when the thread
* starts... typically after this function has returned.
* _beginthread_trampoline is responsible for freeing the trampoline
*/
trampoline
=
MSVCRT_malloc
(
sizeof
(
*
trampoline
));
trampoline
->
start_address
=
start_address
;
trampoline
->
arglist
=
arglist
;
/* FIXME */
return
(
MSVCRT_uintptr_t
)
CreateThread
(
NULL
,
stack_size
,
_beginthread_trampoline
,
trampoline
,
0
,
NULL
);
trampoline
.
is_ready
=
CreateEventW
(
NULL
,
FALSE
,
FALSE
,
NULL
);
if
(
!
trampoline
.
is_ready
)
{
*
MSVCRT__errno
()
=
MSVCRT_EAGAIN
;
return
-
1
;
}
trampoline
.
start_address
=
start_address
;
trampoline
.
arglist
=
arglist
;
thread
=
CreateThread
(
NULL
,
stack_size
,
_beginthread_trampoline
,
&
trampoline
,
0
,
NULL
);
if
(
!
thread
)
{
*
MSVCRT__errno
()
=
MSVCRT_EAGAIN
;
return
-
1
;
}
CloseHandle
(
thread
);
WaitForSingleObject
(
trampoline
.
is_ready
,
INFINITE
);
CloseHandle
(
trampoline
.
is_ready
);
if
(
!
trampoline
.
thread
)
{
*
MSVCRT__errno
()
=
MSVCRT_EAGAIN
;
return
-
1
;
}
return
(
MSVCRT_uintptr_t
)
trampoline
.
thread
;
}
/*********************************************************************
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment