server: Implement NtMakeTemporaryObject and NtQueryObject(ObjectBasicInformation) [dir_object #6]

Vitaliy Margolen wine-patch at kievinfo.com
Wed Nov 2 17:14:07 CST 2005


NtMakeTemporaryObject required to properly handle permanent objects.
ObjectBasicInformation is really useful in finding handle count leaks.

Vitaliy Margolen

changelog:
  server
  - Implement NtMakeTemporaryObject
  - Implement NtQueryObject(ObjectBasicInformation)
-------------- next part --------------
diff -up -x '*.o' wine-rtest/server/object.c wine-dbg/server/object.c
--- server/object.c	2005-11-02 12:02:46.000000000 -0700
+++ server/object.c	2005-11-02 15:54:10.000000000 -0700
@@ -31,9 +31,12 @@
 #include "winternl.h"
 
 #include "file.h"
+#include "handle.h"
+#include "request.h"
 #include "thread.h"
 #include "unicode.h"
 
+#define OBJ_QUERY (0x0001)
 
 struct namespace
 {
@@ -318,3 +321,35 @@ int no_close_handle( struct object *obj,
 void no_destroy( struct object *obj )
 {
 }
+
+DECL_HANDLER(make_temporary_object)
+{
+    struct object *obj = get_handle_obj( current->process, req->handle, DELETE, NULL );
+    if (obj) make_temporary_obj( obj );
+}
+
+DECL_HANDLER(query_object)
+{
+    POBJECT_BASIC_INFORMATION info;
+    struct object *obj = get_handle_obj( current->process, req->handle, OBJ_QUERY, NULL );
+    if (!obj) return;
+
+    if (get_reply_max_size() != sizeof(*info))
+    {
+        release_object( obj );
+        set_error( STATUS_INFO_LENGTH_MISMATCH );
+        return;
+    }
+    info = set_reply_data_size( sizeof(*info) );
+
+    memset( info, 0, sizeof(*info) );
+    info->Attributes               = obj->flags;
+    info->GrantedAccess            = get_handle_access( current->process, req->handle );
+    info->HandleCount              = obj->handlecount;
+    info->PointerCount             = obj->refcount;
+    info->NonPagedPoolUsage        = obj->ops->size;
+    get_object_name( obj, (size_t*) &info->NameInformationLength );
+
+    release_object( obj );
+}
+
diff -up -x '*.o' wine-rtest/server/protocol.def wine-dbg/server/protocol.def
--- server/protocol.def	2005-11-02 14:01:47.000000000 -0700
+++ server/protocol.def	2005-11-02 15:55:43.000000000 -0700
@@ -2505,3 +2506,16 @@ enum message_type
     unsigned int   next_msgsize;
 @END
 #define MAILSLOT_SET_READ_TIMEOUT  1
+
+
+/* Make object temporary */
+ at REQ(make_temporary_object)
+    obj_handle_t   handle;        /* any object handle */
+ at END
+
+/* Query basic object info */
+ at REQ(query_object)
+    obj_handle_t   handle;        /* handle to the object */
+ at REPLY
+    VARARG(info,bytes);           /* OBJECT_BASIC_INFORMATION */
+ at END
Index: dlls/ntdll/om.c
===================================================================
RCS file: /home/wine/wine/dlls/ntdll/om.c,v
retrieving revision 1.36
diff -u -p -r1.36 om.c
--- dlls/ntdll/om.c	28 Oct 2005 16:42:12 -0000	1.36
+++ dlls/ntdll/om.c	2 Nov 2005 22:58:56 -0000
@@ -60,6 +60,25 @@ NTSTATUS WINAPI NtQueryObject(IN HANDLE 
 
     switch (info_class)
     {
+    case ObjectBasicInformation:
+        {
+            POBJECT_BASIC_INFORMATION p = (POBJECT_BASIC_INFORMATION)ptr;
+
+            if (len != sizeof(*p)) return STATUS_INFO_LENGTH_MISMATCH;
+
+            SERVER_START_REQ( query_object )
+            {
+                req->handle = handle;
+                wine_server_set_reply( req, p, len );
+                if (!(status = wine_server_call( req )))
+                {
+                    size_t len = wine_server_reply_size(reply);
+                    if (used_len) *used_len = len;
+                }
+            }
+            SERVER_END_REQ;
+            break;
+        }
     case ObjectDataInformation:
         {
             OBJECT_DATA_INFORMATION* p = (OBJECT_DATA_INFORMATION*)ptr;
@@ -341,6 +360,33 @@ NTSTATUS WINAPI NtClose( HANDLE Handle )
     return ret;
 }
 
+/**************************************************************************
+ *                 NtMakeTemporaryObject		[NTDLL.@]
+ *                 ZwMakeTemporaryObject		[NTDLL.@]
+ *
+ * Make any object temporary if it was created as permanent.
+ * 
+ * PARAMS
+ *  Handle [I] handle an object
+ *
+ * RETURNS
+ *  Success: ERROR_SUCCESS.
+ *  Failure: An NTSTATUS error code.
+ */
+NTSTATUS WINAPI NtMakeTemporaryObject( HANDLE Handle )
+{
+    NTSTATUS ret;
+    TRACE("(%p): \n", Handle);
+
+    SERVER_START_REQ( make_temporary_object )
+    {
+        req->handle = Handle;
+        ret = wine_server_call( req );
+    }
+    SERVER_END_REQ;
+    return ret;
+}
+
 /*
  *	Directory functions
  */
Index: dlls/ntdll/ntdll.spec
===================================================================
RCS file: /home/wine/wine/dlls/ntdll/ntdll.spec,v
retrieving revision 1.200
diff -u -p -r1.200 ntdll.spec
--- dlls/ntdll/ntdll.spec	27 Oct 2005 10:25:41 -0000	1.200
+++ dlls/ntdll/ntdll.spec	2 Nov 2005 23:13:41 -0000
@@ -195,7 +195,7 @@
 # @ stub NtLockRegistryKey
 @ stdcall NtLockVirtualMemory(long ptr ptr long)
 # @ stub NtMakePermanentObject
-@ stub NtMakeTemporaryObject
+@ stdcall NtMakeTemporaryObject(long)
 # @ stub NtMapUserPhysicalPages
 # @ stub NtMapUserPhysicalPagesScatter
 @ stdcall NtMapViewOfSection(long long ptr long long ptr ptr long long long)
@@ -1036,7 +1036,7 @@
 # @ stub ZwLockRegistryKey
 @ stdcall ZwLockVirtualMemory(long ptr ptr long) NtLockVirtualMemory
 # @ stub ZwMakePermanentObject
-@ stub ZwMakeTemporaryObject
+@ stdcall ZwMakeTemporaryObject(long) NtMakeTemporaryObject
 # @ stub ZwMapUserPhysicalPages
 # @ stub ZwMapUserPhysicalPagesScatter
 @ stdcall ZwMapViewOfSection(long long ptr long long ptr ptr long long long) NtMapViewOfSection


More information about the wine-patches mailing list