Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
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-winehq
Commits
91befe1d
Commit
91befe1d
authored
Feb 01, 2003
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made process and thread ids small integers instead of pointers.
parent
bb2210bc
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
166 additions
and
76 deletions
+166
-76
process.c
server/process.c
+83
-7
process.h
server/process.h
+7
-2
ptrace.c
server/ptrace.c
+7
-7
request.c
server/request.c
+6
-5
thread.c
server/thread.c
+20
-13
thread.h
server/thread.h
+2
-1
trace.c
server/trace.c
+39
-39
make_requests
tools/make_requests
+2
-2
No files found.
server/process.c
View file @
91befe1d
...
...
@@ -114,6 +114,79 @@ static const struct object_ops startup_info_ops =
};
struct
ptid_entry
{
void
*
ptr
;
/* entry ptr */
unsigned
int
next
;
/* next free entry */
};
static
struct
ptid_entry
*
ptid_entries
;
/* array of ptid entries */
static
unsigned
int
used_ptid_entries
;
/* number of entries in use */
static
unsigned
int
alloc_ptid_entries
;
/* number of allocated entries */
static
unsigned
int
next_free_ptid
;
/* next free entry */
static
unsigned
int
last_free_ptid
;
/* last free entry */
#define PTID_OFFSET 8
/* offset for first ptid value */
/* allocate a new process or thread id */
unsigned
int
alloc_ptid
(
void
*
ptr
)
{
struct
ptid_entry
*
entry
;
unsigned
int
id
;
if
(
used_ptid_entries
<
alloc_ptid_entries
)
{
id
=
used_ptid_entries
+
PTID_OFFSET
;
entry
=
&
ptid_entries
[
used_ptid_entries
++
];
}
else
if
(
next_free_ptid
)
{
id
=
next_free_ptid
;
entry
=
&
ptid_entries
[
id
-
PTID_OFFSET
];
if
(
!
(
next_free_ptid
=
entry
->
next
))
last_free_ptid
=
0
;
}
else
/* need to grow the array */
{
unsigned
int
count
=
alloc_ptid_entries
+
(
alloc_ptid_entries
/
2
);
if
(
!
count
)
count
=
64
;
if
(
!
(
entry
=
realloc
(
ptid_entries
,
count
*
sizeof
(
*
entry
)
)))
{
set_error
(
STATUS_NO_MEMORY
);
return
0
;
}
ptid_entries
=
entry
;
alloc_ptid_entries
=
count
;
id
=
used_ptid_entries
+
PTID_OFFSET
;
entry
=
&
ptid_entries
[
used_ptid_entries
++
];
}
entry
->
ptr
=
ptr
;
return
id
;
}
/* free a process or thread id */
void
free_ptid
(
unsigned
int
id
)
{
struct
ptid_entry
*
entry
=
&
ptid_entries
[
id
-
PTID_OFFSET
];
entry
->
ptr
=
NULL
;
entry
->
next
=
0
;
/* append to end of free list so that we don't reuse it too early */
if
(
last_free_ptid
)
ptid_entries
[
last_free_ptid
-
PTID_OFFSET
].
next
=
id
;
else
next_free_ptid
=
id
;
last_free_ptid
=
id
;
}
/* retrieve the pointer corresponding to a process or thread id */
void
*
get_ptid_entry
(
unsigned
int
id
)
{
if
(
id
<
PTID_OFFSET
)
return
NULL
;
if
(
id
-
PTID_OFFSET
>=
used_ptid_entries
)
return
NULL
;
return
ptid_entries
[
id
-
PTID_OFFSET
].
ptr
;
}
/* set the state of the process startup info */
static
void
set_process_startup_state
(
struct
process
*
process
,
enum
startup_state
state
)
{
...
...
@@ -225,6 +298,8 @@ struct thread *create_process( int fd )
if
((
process
->
next
=
first_process
)
!=
NULL
)
process
->
next
->
prev
=
process
;
first_process
=
process
;
if
(
!
(
process
->
id
=
alloc_ptid
(
process
)))
goto
error
;
/* create the main thread */
if
(
pipe
(
request_pipe
)
==
-
1
)
{
...
...
@@ -339,6 +414,7 @@ static void process_destroy( struct object *obj )
if
(
process
->
atom_table
)
release_object
(
process
->
atom_table
);
if
(
process
->
exe
.
file
)
release_object
(
process
->
exe
.
file
);
if
(
process
->
exe
.
filename
)
free
(
process
->
exe
.
filename
);
if
(
process
->
id
)
free_ptid
(
process
->
id
);
}
/* dump a process on stdout for debugging purposes */
...
...
@@ -347,8 +423,8 @@ static void process_dump( struct object *obj, int verbose )
struct
process
*
process
=
(
struct
process
*
)
obj
;
assert
(
obj
->
ops
==
&
process_ops
);
fprintf
(
stderr
,
"Process next=%p prev=%p handles=%p
\n
"
,
process
->
next
,
process
->
prev
,
process
->
handles
);
fprintf
(
stderr
,
"Process
id=%04x
next=%p prev=%p handles=%p
\n
"
,
process
->
id
,
process
->
next
,
process
->
prev
,
process
->
handles
);
}
static
int
process_signaled
(
struct
object
*
obj
,
struct
thread
*
thread
)
...
...
@@ -400,11 +476,11 @@ static int startup_info_signaled( struct object *obj, struct thread *thread )
/* get a process from an id (and increment the refcount) */
struct
process
*
get_process_from_id
(
process_id_t
id
)
{
struct
process
*
p
=
first_process
;
while
(
p
&&
(
get_process_id
(
p
)
!=
id
))
p
=
p
->
next
;
if
(
p
)
grab_object
(
p
);
else
set_error
(
STATUS_INVALID_PARAMETER
);
return
p
;
struct
object
*
obj
=
get_ptid_entry
(
id
)
;
if
(
obj
&&
obj
->
ops
==
&
process_ops
)
return
(
struct
process
*
)
grab_object
(
obj
);
set_error
(
STATUS_INVALID_PARAMETER
);
return
NULL
;
}
/* get a process from a handle (and increment the refcount) */
...
...
server/process.h
View file @
91befe1d
...
...
@@ -56,6 +56,8 @@ struct process
struct
thread
*
thread_list
;
/* head of the thread list */
struct
thread
*
debugger
;
/* thread debugging this process */
struct
handle_table
*
handles
;
/* handle entries */
process_id_t
id
;
/* id of the process */
process_id_t
group_id
;
/* group id of the process */
int
exit_code
;
/* process exit code */
int
running_threads
;
/* number of threads running in this process */
struct
timeval
start_time
;
/* absolute time at process start */
...
...
@@ -73,7 +75,6 @@ struct process
struct
process_dll
exe
;
/* main exe file */
void
*
ldt_copy
;
/* pointer to LDT copy in client addr space */
void
*
ldt_flags
;
/* pointer to LDT flags in client addr space */
process_id_t
group_id
;
/* group ID of the process */
};
struct
process_snapshot
...
...
@@ -94,6 +95,9 @@ struct module_snapshot
/* process functions */
extern
unsigned
int
alloc_ptid
(
void
*
ptr
);
extern
void
free_ptid
(
unsigned
int
id
);
extern
void
*
get_ptid_entry
(
unsigned
int
id
);
extern
struct
thread
*
create_process
(
int
fd
);
extern
struct
process
*
get_process_from_id
(
process_id_t
id
);
extern
struct
process
*
get_process_from_handle
(
obj_handle_t
handle
,
unsigned
int
access
);
...
...
@@ -115,7 +119,8 @@ extern struct process_snapshot *process_snap( int *count );
extern
struct
module_snapshot
*
module_snap
(
struct
process
*
process
,
int
*
count
);
extern
void
enum_processes
(
int
(
*
cb
)(
struct
process
*
,
void
*
),
void
*
user
);
inline
static
process_id_t
get_process_id
(
struct
process
*
process
)
{
return
(
process_id_t
)
process
;
}
inline
static
process_id_t
get_process_id
(
struct
process
*
process
)
{
return
process
->
id
;
}
inline
static
int
is_process_init_done
(
struct
process
*
process
)
{
return
process
->
startup_state
==
STARTUP_DONE
;
...
...
server/ptrace.c
View file @
91befe1d
...
...
@@ -75,7 +75,7 @@ static int handle_child_status( struct thread *thread, int pid, int status )
{
int
sig
=
WSTOPSIG
(
status
);
if
(
debug_level
&&
thread
)
fprintf
(
stderr
,
"%0
8x: *signal* signal=%d
\n
"
,
(
unsigned
int
)
threa
d
,
sig
);
fprintf
(
stderr
,
"%0
4x: *signal* signal=%d
\n
"
,
thread
->
i
d
,
sig
);
switch
(
sig
)
{
case
SIGSTOP
:
/* continue at once if not suspended */
...
...
@@ -97,11 +97,11 @@ static int handle_child_status( struct thread *thread, int pid, int status )
if
(
debug_level
)
{
if
(
WIFSIGNALED
(
status
))
fprintf
(
stderr
,
"%0
8
x: *exited* signal=%d
\n
"
,
(
unsigned
int
)
threa
d
,
WTERMSIG
(
status
)
);
fprintf
(
stderr
,
"%0
4
x: *exited* signal=%d
\n
"
,
thread
->
i
d
,
WTERMSIG
(
status
)
);
else
fprintf
(
stderr
,
"%0
8
x: *exited* status=%d
\n
"
,
(
unsigned
int
)
threa
d
,
WEXITSTATUS
(
status
)
);
fprintf
(
stderr
,
"%0
4
x: *exited* status=%d
\n
"
,
thread
->
i
d
,
WEXITSTATUS
(
status
)
);
}
}
return
0
;
...
...
@@ -146,7 +146,7 @@ static int attach_thread( struct thread *thread )
if
(
errno
==
ESRCH
)
thread
->
unix_pid
=
0
;
/* process got killed */
return
0
;
}
if
(
debug_level
)
fprintf
(
stderr
,
"%0
8x: *attached*
\n
"
,
(
unsigned
int
)
threa
d
);
if
(
debug_level
)
fprintf
(
stderr
,
"%0
4x: *attached*
\n
"
,
thread
->
i
d
);
thread
->
attached
=
1
;
wait4_thread
(
thread
,
SIGSTOP
);
return
1
;
...
...
@@ -161,7 +161,7 @@ void detach_thread( struct thread *thread, int sig )
/* make sure it is stopped */
suspend_thread
(
thread
,
0
);
if
(
sig
)
kill
(
thread
->
unix_pid
,
sig
);
if
(
debug_level
)
fprintf
(
stderr
,
"%0
8x: *detached*
\n
"
,
(
unsigned
int
)
threa
d
);
if
(
debug_level
)
fprintf
(
stderr
,
"%0
4x: *detached*
\n
"
,
thread
->
i
d
);
ptrace
(
PTRACE_DETACH
,
thread
->
unix_pid
,
(
caddr_t
)
1
,
sig
);
thread
->
suspend
=
0
;
/* detach makes it continue */
thread
->
attached
=
0
;
...
...
server/request.c
View file @
91befe1d
...
...
@@ -351,15 +351,15 @@ int receive_fd( struct process *process )
if
(
!
thread
||
thread
->
process
!=
process
||
thread
->
state
==
TERMINATED
)
{
if
(
debug_level
)
fprintf
(
stderr
,
"%0
8
x: *fd* %d <- %d bad thread id
\n
"
,
(
unsigned
int
)
data
.
tid
,
data
.
fd
,
fd
);
fprintf
(
stderr
,
"%0
4
x: *fd* %d <- %d bad thread id
\n
"
,
data
.
tid
,
data
.
fd
,
fd
);
close
(
fd
);
}
else
{
if
(
debug_level
)
fprintf
(
stderr
,
"%0
8
x: *fd* %d <- %d
\n
"
,
(
unsigned
int
)
threa
d
,
data
.
fd
,
fd
);
fprintf
(
stderr
,
"%0
4
x: *fd* %d <- %d
\n
"
,
thread
->
i
d
,
data
.
fd
,
fd
);
thread_add_inflight_fd
(
thread
,
data
.
fd
,
fd
);
}
if
(
thread
)
release_object
(
thread
);
...
...
@@ -391,7 +391,8 @@ int send_client_fd( struct process *process, int fd, obj_handle_t handle )
int
ret
;
if
(
debug_level
)
fprintf
(
stderr
,
"%08x: *fd* %p -> %d
\n
"
,
(
unsigned
int
)
current
,
handle
,
fd
);
fprintf
(
stderr
,
"%04x: *fd* %p -> %d
\n
"
,
current
?
current
->
id
:
process
->
id
,
handle
,
fd
);
#ifdef HAVE_MSGHDR_ACCRIGHTS
msghdr
.
msg_accrightslen
=
sizeof
(
fd
);
...
...
server/thread.c
View file @
91befe1d
...
...
@@ -167,6 +167,12 @@ struct thread *create_thread( int fd, struct process *process )
if
((
thread
->
next
=
first_thread
)
!=
NULL
)
thread
->
next
->
prev
=
thread
;
first_thread
=
thread
;
if
(
!
(
thread
->
id
=
alloc_ptid
(
thread
)))
{
release_object
(
thread
);
return
NULL
;
}
set_select_events
(
&
thread
->
obj
,
POLLIN
);
/* start listening to events */
add_process_thread
(
thread
->
process
,
thread
);
return
thread
;
...
...
@@ -236,6 +242,7 @@ static void destroy_thread( struct object *obj )
if
(
thread
->
info
)
release_object
(
thread
->
info
);
cleanup_thread
(
thread
);
release_object
(
thread
->
process
);
if
(
thread
->
id
)
free_ptid
(
thread
->
id
);
}
/* dump a thread on stdout for debugging purposes */
...
...
@@ -244,8 +251,8 @@ static void dump_thread( struct object *obj, int verbose )
struct
thread
*
thread
=
(
struct
thread
*
)
obj
;
assert
(
obj
->
ops
==
&
thread_ops
);
fprintf
(
stderr
,
"Thread pid=%d teb=%p state=%d
\n
"
,
thread
->
unix_pid
,
thread
->
teb
,
thread
->
state
);
fprintf
(
stderr
,
"Thread
id=%04x unix
pid=%d teb=%p state=%d
\n
"
,
thread
->
id
,
thread
->
unix_pid
,
thread
->
teb
,
thread
->
state
);
}
static
int
thread_signaled
(
struct
object
*
obj
,
struct
thread
*
thread
)
...
...
@@ -257,11 +264,11 @@ static int thread_signaled( struct object *obj, struct thread *thread )
/* get a thread pointer from a thread id (and increment the refcount) */
struct
thread
*
get_thread_from_id
(
thread_id_t
id
)
{
struct
thread
*
t
=
first_thread
;
while
(
t
&&
(
get_thread_id
(
t
)
!=
id
))
t
=
t
->
next
;
if
(
t
)
grab_object
(
t
);
else
set_error
(
STATUS_INVALID_PARAMETER
);
return
t
;
struct
object
*
obj
=
get_ptid_entry
(
id
)
;
if
(
obj
&&
obj
->
ops
==
&
thread_ops
)
return
(
struct
thread
*
)
grab_object
(
obj
);
set_error
(
STATUS_INVALID_PARAMETER
);
return
NULL
;
}
/* get a thread from a handle (and increment the refcount) */
...
...
@@ -465,8 +472,8 @@ static int wake_thread( struct thread *thread )
if
((
signaled
=
check_wait
(
thread
))
==
-
1
)
break
;
cookie
=
thread
->
wait
->
cookie
;
if
(
debug_level
)
fprintf
(
stderr
,
"%0
8
x: *wakeup* signaled=%d cookie=%p
\n
"
,
(
unsigned
int
)
threa
d
,
signaled
,
cookie
);
if
(
debug_level
)
fprintf
(
stderr
,
"%0
4
x: *wakeup* signaled=%d cookie=%p
\n
"
,
thread
->
i
d
,
signaled
,
cookie
);
end_wait
(
thread
);
if
(
send_thread_wakeup
(
thread
,
cookie
,
signaled
)
==
-
1
)
/* error */
break
;
...
...
@@ -484,8 +491,8 @@ static void thread_timeout( void *ptr )
wait
->
user
=
NULL
;
if
(
thread
->
wait
!=
wait
)
return
;
/* not the top-level wait, ignore it */
if
(
debug_level
)
fprintf
(
stderr
,
"%0
8
x: *wakeup* signaled=%d cookie=%p
\n
"
,
(
unsigned
int
)
threa
d
,
STATUS_TIMEOUT
,
cookie
);
if
(
debug_level
)
fprintf
(
stderr
,
"%0
4
x: *wakeup* signaled=%d cookie=%p
\n
"
,
thread
->
i
d
,
STATUS_TIMEOUT
,
cookie
);
end_wait
(
thread
);
if
(
send_thread_wakeup
(
thread
,
cookie
,
STATUS_TIMEOUT
)
==
-
1
)
return
;
/* check if other objects have become signaled in the meantime */
...
...
@@ -717,8 +724,8 @@ void kill_thread( struct thread *thread, int violent_death )
thread
->
exit_time
=
time
(
NULL
);
if
(
current
==
thread
)
current
=
NULL
;
if
(
debug_level
)
fprintf
(
stderr
,
"%0
8
x: *killed* exit_code=%d
\n
"
,
(
unsigned
int
)
threa
d
,
thread
->
exit_code
);
fprintf
(
stderr
,
"%0
4
x: *killed* exit_code=%d
\n
"
,
thread
->
i
d
,
thread
->
exit_code
);
if
(
thread
->
wait
)
{
while
(
thread
->
wait
)
end_wait
(
thread
);
...
...
server/thread.h
View file @
91befe1d
...
...
@@ -63,6 +63,7 @@ struct thread
struct
thread
*
proc_next
;
/* per-process thread list */
struct
thread
*
proc_prev
;
struct
process
*
process
;
thread_id_t
id
;
/* thread id */
struct
mutex
*
mutex
;
/* list of currently owned mutexes */
struct
debug_ctx
*
debug_ctx
;
/* debugger context if this thread is a debugger */
struct
debug_event
*
debug_event
;
/* debug event being sent to debugger */
...
...
@@ -143,6 +144,6 @@ static inline unsigned int get_error(void) { return current ? current->err
static
inline
void
set_error
(
unsigned
int
err
)
{
global_error
=
err
;
if
(
current
)
current
->
error
=
err
;
}
static
inline
void
clear_error
(
void
)
{
set_error
(
0
);
}
static
inline
thread_id_t
get_thread_id
(
struct
thread
*
thread
)
{
return
(
thread_id_t
)
threa
d
;
}
static
inline
thread_id_t
get_thread_id
(
struct
thread
*
thread
)
{
return
thread
->
i
d
;
}
#endif
/* __WINE_SERVER_THREAD_H */
server/trace.c
View file @
91befe1d
This diff is collapsed.
Click to expand it.
tools/make_requests
View file @
91befe1d
...
...
@@ -34,8 +34,8 @@
"obj_handle_t"
=>
"%p"
,
"atom_t"
=>
"%04x"
,
"user_handle_t"
=>
"%p"
,
"process_id_t"
=>
"%0
8
x"
,
"thread_id_t"
=>
"%0
8
x"
,
"process_id_t"
=>
"%0
4
x"
,
"thread_id_t"
=>
"%0
4
x"
,
"rectangle_t"
=>
"&dump_rectangle"
,
"char_info_t"
=>
"&dump_char_info"
,
);
...
...
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