Alexandre Julliard : server: Move ldt_copy to the init_process_done request and make it a client_ptr_t.

Alexandre Julliard julliard at winehq.org
Fri Jan 2 08:25:29 CST 2009


Module: wine
Branch: master
Commit: 2cf868c0be353362e94186442f23d210beccdae7
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=2cf868c0be353362e94186442f23d210beccdae7

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Dec 30 22:47:48 2008 +0100

server: Move ldt_copy to the init_process_done request and make it a client_ptr_t.

---

 dlls/ntdll/server.c            |   10 ++++++----
 include/wine/server_protocol.h |    5 +++--
 server/mach.c                  |    5 ++---
 server/process.c               |    4 +++-
 server/process.h               |    2 +-
 server/procfs.c                |   11 ++++++++---
 server/protocol.def            |    3 ++-
 server/ptrace.c                |    4 ++--
 server/thread.c                |    3 +--
 server/trace.c                 |    5 ++++-
 10 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c
index 04d9c21..95bba73 100644
--- a/dlls/ntdll/server.c
+++ b/dlls/ntdll/server.c
@@ -993,9 +993,12 @@ NTSTATUS server_init_process_done(void)
     /* Signal the parent process to continue */
     SERVER_START_REQ( init_process_done )
     {
-        req->module = wine_server_client_ptr( peb->ImageBaseAddress );
-        req->entry  = (char *)peb->ImageBaseAddress + nt->OptionalHeader.AddressOfEntryPoint;
-        req->gui    = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CUI);
+        req->module   = wine_server_client_ptr( peb->ImageBaseAddress );
+#ifdef __i386__
+        req->ldt_copy = wine_server_client_ptr( &wine_ldt_copy );
+#endif
+        req->entry    = (char *)peb->ImageBaseAddress + nt->OptionalHeader.AddressOfEntryPoint;
+        req->gui      = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CUI);
         status = wine_server_call( req );
     }
     SERVER_END_REQ;
@@ -1048,7 +1051,6 @@ size_t server_init_thread( int unix_pid, int unix_tid, void *entry_point )
         req->teb         = NtCurrentTeb();
         req->peb         = NtCurrentTeb()->Peb;
         req->entry       = entry_point;
-        req->ldt_copy    = &wine_ldt_copy;
         req->reply_fd    = reply_pipe[1];
         req->wait_fd     = ntdll_get_thread_data()->wait_fd[1];
         req->debug_level = (TRACE_ON(server) != 0);
diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h
index 1b34cf3..1a8f0de 100644
--- a/include/wine/server_protocol.h
+++ b/include/wine/server_protocol.h
@@ -542,6 +542,7 @@ struct init_process_done_request
     struct request_header __header;
     int          gui;
     mod_handle_t module;
+    client_ptr_t ldt_copy;
     void*        entry;
 };
 struct init_process_done_reply
@@ -560,7 +561,7 @@ struct init_thread_request
     void*        teb;
     void*        peb;
     void*        entry;
-    void*        ldt_copy;
+    int          unused;
     int          reply_fd;
     int          wait_fd;
 };
@@ -5061,6 +5062,6 @@ union generic_reply
     struct set_window_layered_info_reply set_window_layered_info_reply;
 };
 
-#define SERVER_PROTOCOL_VERSION 373
+#define SERVER_PROTOCOL_VERSION 374
 
 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */
diff --git a/server/mach.c b/server/mach.c
index 05652ab..fcc87a3 100644
--- a/server/mach.c
+++ b/server/mach.c
@@ -446,9 +446,8 @@ void get_selector_entry( struct thread *thread, int entry, unsigned int *base,
 
     if ((ret = task_suspend( process_port )) == KERN_SUCCESS)
     {
-        void *ptr = process->ldt_copy;
-        vm_offset_t offset = (unsigned long)ptr % page_size;
-        vm_address_t aligned_address = (vm_address_t)((char *)ptr - offset);
+        vm_offset_t offset = process->ldt_copy % page_size;
+        vm_address_t aligned_address = (vm_address_t)(process->ldt_copy - offset);
         vm_size_t aligned_size = (total_size + offset + page_size - 1) / page_size * page_size;
 
         ret = vm_read( process_port, aligned_address, aligned_size, &data, &bytes_read );
diff --git a/server/process.c b/server/process.c
index 208fb7d..a0c66ab 100644
--- a/server/process.c
+++ b/server/process.c
@@ -332,7 +332,7 @@ struct thread *create_process( int fd, struct thread *parent_thread, int inherit
     process->idle_event      = NULL;
     process->queue           = NULL;
     process->peb             = NULL;
-    process->ldt_copy        = NULL;
+    process->ldt_copy        = 0;
     process->winstation      = 0;
     process->desktop         = 0;
     process->token           = NULL;
@@ -1018,6 +1018,8 @@ DECL_HANDLER(init_process_done)
     list_remove( &dll->entry );
     list_add_head( &process->dlls, &dll->entry );
 
+    process->ldt_copy = req->ldt_copy;
+
     generate_startup_debug_events( process, req->entry );
     set_process_startup_state( process, STARTUP_DONE );
 
diff --git a/server/process.h b/server/process.h
index c8313ff..5d3b456 100644
--- a/server/process.h
+++ b/server/process.h
@@ -80,7 +80,7 @@ struct process
     struct token        *token;           /* security token associated with this process */
     struct list          dlls;            /* list of loaded dlls */
     void                *peb;             /* PEB address in client address space */
-    void                *ldt_copy;        /* pointer to LDT copy in client addr space */
+    client_ptr_t         ldt_copy;        /* pointer to LDT copy in client addr space */
     unsigned int         trace_data;      /* opaque data used by the process tracing mechanism */
 };
 
diff --git a/server/procfs.c b/server/procfs.c
index 8c789c5..28777d8 100644
--- a/server/procfs.c
+++ b/server/procfs.c
@@ -174,10 +174,15 @@ void get_selector_entry( struct thread *thread, int entry, unsigned int *base,
                          unsigned int *limit, unsigned char *flags )
 {
     ssize_t ret;
-    off_t pos = (off_t)thread->process->ldt_copy;
-    int fd = open_proc_as( thread->process, O_RDONLY );
+    off_t pos = thread->process->ldt_copy;
+    int fd;
 
-    if (fd == -1) return;
+    if (!pos)
+    {
+        set_error( STATUS_ACCESS_DENIED );
+        return 0;
+    }
+    if ((fd = open_proc_as( thread->process, O_RDONLY )) == -1) return;
 
     ret = pread( fd, base, sizeof(*base), pos + entry*sizeof(int) );
     if (ret != sizeof(*base)) goto error;
diff --git a/server/protocol.def b/server/protocol.def
index 83fc7b8..e5c9676 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -536,6 +536,7 @@ typedef union
 @REQ(init_process_done)
     int          gui;          /* is it a GUI process? */
     mod_handle_t module;       /* main module base address */
+    client_ptr_t ldt_copy;     /* address of LDT copy (in thread address space) */
     void*        entry;        /* process entry point */
 @END
 
@@ -548,7 +549,7 @@ typedef union
     void*        teb;          /* TEB of new thread (in thread address space) */
     void*        peb;          /* address of PEB (in thread address space) */
     void*        entry;        /* thread entry point (in thread address space) */
-    void*        ldt_copy;     /* address of LDT copy (in thread address space) */
+    int          unused;       /* was: ldt_copy */
     int          reply_fd;     /* fd for reply pipe */
     int          wait_fd;      /* fd for blocking calls pipe */
 @REPLY
diff --git a/server/ptrace.c b/server/ptrace.c
index accaf4d..b446de9 100644
--- a/server/ptrace.c
+++ b/server/ptrace.c
@@ -505,10 +505,10 @@ void get_selector_entry( struct thread *thread, int entry, unsigned int *base,
     if (suspend_for_ptrace( thread ))
     {
         unsigned char flags_buf[4];
-        int *addr = (int *)thread->process->ldt_copy + entry;
+        int *addr = (int *)(unsigned long)thread->process->ldt_copy + entry;
         if (read_thread_int( thread, addr, (int *)base ) == -1) goto done;
         if (read_thread_int( thread, addr + 8192, (int *)limit ) == -1) goto done;
-        addr = (int *)thread->process->ldt_copy + 2*8192 + (entry >> 2);
+        addr = (int *)(unsigned long)thread->process->ldt_copy + 2*8192 + (entry >> 2);
         if (read_thread_int( thread, addr, (int *)flags_buf ) == -1) goto done;
         *flags = flags_buf[entry & 3];
     done:
diff --git a/server/thread.c b/server/thread.c
index bc4e9e9..675deda 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -1032,7 +1032,7 @@ DECL_HANDLER(init_thread)
     if (!(current->wait_fd  = create_anonymous_fd( &thread_fd_ops, wait_fd, &current->obj, 0 )))
         return;
 
-    if (!is_valid_address(req->teb) || !is_valid_address(req->peb) || !is_valid_address(req->ldt_copy))
+    if (!is_valid_address(req->teb) || !is_valid_address(req->peb))
     {
         set_error( STATUS_INVALID_PARAMETER );
         return;
@@ -1046,7 +1046,6 @@ DECL_HANDLER(init_thread)
     {
         process->unix_pid = current->unix_pid;
         process->peb      = req->peb;
-        process->ldt_copy = req->ldt_copy;
         reply->info_size  = init_process( current );
     }
     else
diff --git a/server/trace.c b/server/trace.c
index b4ea418..db67b2a 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -971,6 +971,9 @@ static void dump_init_process_done_request( const struct init_process_done_reque
     fprintf( stderr, " module=" );
     dump_uint64( &req->module );
     fprintf( stderr, "," );
+    fprintf( stderr, " ldt_copy=" );
+    dump_uint64( &req->ldt_copy );
+    fprintf( stderr, "," );
     fprintf( stderr, " entry=%p", req->entry );
 }
 
@@ -982,7 +985,7 @@ static void dump_init_thread_request( const struct init_thread_request *req )
     fprintf( stderr, " teb=%p,", req->teb );
     fprintf( stderr, " peb=%p,", req->peb );
     fprintf( stderr, " entry=%p,", req->entry );
-    fprintf( stderr, " ldt_copy=%p,", req->ldt_copy );
+    fprintf( stderr, " unused=%d,", req->unused );
     fprintf( stderr, " reply_fd=%d,", req->reply_fd );
     fprintf( stderr, " wait_fd=%d", req->wait_fd );
 }




More information about the wine-cvs mailing list