Re: compiling wineserver under cygwin - thread context

2002-11-28 Thread David Fraser
David Fraser wrote:


The significant compilation problem is in server/context_i386.c: You 
must implement get/set_thread_context for your platform.
Basically there's some code that does the threading stuff which is 
platform-specific. There are Linux and BSD and Sun variants, none of 
which work under cygwin ... Basically sys/ptrace.h is what's missing.
This lets the process interrupt a child process and get/set its 
registers. Does anyone have any idea what the best way to write a 
replacement for cygwin would be? Maybe I need to ask the cygwin list. 

After some more investigating ... Dimi added a request for ptrace 
support in cygwin in November 2000:
http://cygwin.com//cgi-bin/cygwin-todo.cgi?20001120.094813
But I can't see anything that's been done about it. So I thought I would 
clarify here exactly what should
be done before trying to do it...

The platform-specific bits define the functions get_thread_context and 
set_thread_context
which each use ptrace (in the existing platforms) to get / set registers 
for that thread.
The requests given to ptrace are:
PTRACE_PEEKUSER / PTRACE_POKEUSER   (for getting / setting debugging 
registers)
PTRACE_GETREGS / PTRACE_SETREGS   (for getting / setting general registers)
PTRACE_GETFPREGS   (for getting / setting floating point registers)
so it's fairly simple...
As far as I can see the only places get_thread_context and 
set_thread_context are used is in
scheduler/thread.c, to implement WINAPI GetThreadContext and 
SetThreadContext

Now from reading through the sources Wine uses clone() to create 
threads, using its own implementation
of clone for linux if not available that looks like it wouldn't work 
with cygwin...
Cygwin has a pthreads implementation that maps onto the Windows Thread 
functions.

So part of the question is, in order to get Wine to function properly on 
Cygwin, what is the right
threading approach to take? Am I right in thinking that the current code 
wouldn't work on Cygwin?

Approach 1 would be to simply call the Windows Thread functions from 
Wine if compiled on Cygwin
That would involve the nastiness of including the w32api headers...

Approach 2 would be to just use the Windows 
GetThreadContext/SetThreadContext functions,
since they're just looking at registers etc. These could then be wrapped 
up in an (incomplete) ptrace
implementation for cygwin, which we would call.

Approach 3 would be to reimplement the appropriate parts of ptrace for 
cygwin in some other way.

I'm guessing Approach 2 is right.
Anyway any advice would be appreciated

David





Re: compiling wineserver under cygwin - thread context

2002-11-28 Thread Dimitrie O. Paun
On November 28, 2002 09:51 am, David Fraser wrote:
 So part of the question is, in order to get Wine to function properly on
 Cygwin, what is the right
 threading approach to take? Am I right in thinking that the current code
 wouldn't work on Cygwin?

I say, let's get the compiling and linking working, and then worry about
actually running it... :)

 As far as I can see the only places get_thread_context and 
 set_thread_context are used is in
 scheduler/thread.c, to implement WINAPI GetThreadContext and 
 SetThreadContext

So actually a first approximation for [sg]et_thread_context for
Cygwin would be one that does nothing. Then we can try submitting
patches to Cygwin (Approach 2), so that other apps can make use
of ptrace, if necessary.

-- 
Dimi.





Re: compiling wineserver under cygwin - thread context

2002-11-28 Thread David Fraser
Dimitrie O. Paun wrote:


On November 28, 2002 09:51 am, David Fraser wrote:
 

So part of the question is, in order to get Wine to function properly on
Cygwin, what is the right
threading approach to take? Am I right in thinking that the current code
wouldn't work on Cygwin?
   


I say, let's get the compiling and linking working, and then worry about
actually running it... :)

 

As far as I can see the only places get_thread_context and 
set_thread_context are used is in
scheduler/thread.c, to implement WINAPI GetThreadContext and 
SetThreadContext
   


So actually a first approximation for [sg]et_thread_context for
Cygwin would be one that does nothing. Then we can try submitting
patches to Cygwin (Approach 2), so that other apps can make use
of ptrace, if necessary.

 

OK, done that. So now wineserver.exe actually links :-) And it runs too!
However can't yet see whether its going to do anything as in order to 
actually run programs
it looks like we need tolink miscemu/main.c
Problem here being that it wants to link with ntdll, which doesn't build 
yet.
That still needs a lot more work... In the mean time a very simple patch 
that
does nothing for context_i386.c is below in case anyone else wants to try...
David

Index: server/context_i386.c
===
RCS file: /home/wine/wine/server/context_i386.c,v
retrieving revision 1.24
diff -u -r1.24 context_i386.c
--- server/context_i386.c   8 Nov 2002 18:55:31 -   1.24
+++ server/context_i386.c   28 Nov 2002 15:48:01 -
@@ -76,7 +76,24 @@
#define PTRACE_SETDBREGS PT_SETDBREGS
#endif

-#ifdef linux
+#if defined(__CYGWIN__)
+
+/* retrieve a thread context */
+static void get_thread_context( struct thread *thread, unsigned int 
flags, CONTEXT *context )
+{
+/* FIXME: implement this */
+file_set_error();
+}
+
+
+/* set a thread context */
+static void set_thread_context( struct thread *thread, unsigned int 
flags, const CONTEXT *context )
+{
+/* FIXME: implement this */
+file_set_error();
+}
+
+#elif defined(linux)
#ifdef HAVE_SYS_USER_H
# include sys/user.h
#endif