From 8c50f607d19234b421ecc5278cb007b45b1d4df2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Wed, 8 Mar 2017 03:32:43 +0100
Subject: server: Register types during startup.

---
 server/completion.c |  3 +--
 server/directory.c  |  6 ++----
 server/event.c      |  6 ++----
 server/file.c       |  3 +--
 server/mailslot.c   |  3 +--
 server/main.c       |  1 +
 server/mapping.c    |  3 +--
 server/mutex.c      |  3 +--
 server/named_pipe.c |  3 +--
 server/object.c     | 36 ++++++++++++++++++++++++++++++++++++
 server/object.h     | 24 ++++++++++++++++++++++++
 server/process.c    |  6 ++----
 server/registry.c   |  3 +--
 server/semaphore.c  |  3 +--
 server/symlink.c    |  3 +--
 server/thread.c     |  3 +--
 server/timer.c      |  3 +--
 server/token.c      |  3 +--
 server/winstation.c |  6 ++----
 19 files changed, 81 insertions(+), 40 deletions(-)

diff --git a/server/completion.c b/server/completion.c
index 8b8983a1..b4c97b01 100644
--- a/server/completion.c
+++ b/server/completion.c
@@ -109,8 +109,7 @@ static void completion_dump( struct object *obj, int verbose )
 
 static struct object_type *completion_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'I','o','C','o','m','p','l','e','t','i','o','n'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_IoCompletion, sizeof(type_IoCompletion) };
     return get_object_type( &str );
 }
 
diff --git a/server/directory.c b/server/directory.c
index 6e22a741..65a77a89 100644
--- a/server/directory.c
+++ b/server/directory.c
@@ -119,8 +119,7 @@ static void object_type_dump( struct object *obj, int verbose )
 
 static struct object_type *object_type_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'O','b','j','e','c','t','T','y','p','e'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_ObjectType, sizeof(type_ObjectType) };
     return get_object_type( &str );
 }
 
@@ -131,8 +130,7 @@ static void directory_dump( struct object *obj, int verbose )
 
 static struct object_type *directory_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'D','i','r','e','c','t','o','r','y'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_Directory, sizeof(type_Directory) };
     return get_object_type( &str );
 }
 
diff --git a/server/event.c b/server/event.c
index cfc0f6af..f30faa9b 100644
--- a/server/event.c
+++ b/server/event.c
@@ -159,8 +159,7 @@ static void event_dump( struct object *obj, int verbose )
 
 static struct object_type *event_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'E','v','e','n','t'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_Event, sizeof(type_Event) };
     return get_object_type( &str );
 }
 
@@ -229,8 +228,7 @@ static void keyed_event_dump( struct object *obj, int verbose )
 
 static struct object_type *keyed_event_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'K','e','y','e','d','E','v','e','n','t'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_KeyedEvent, sizeof(type_KeyedEvent) };
     return get_object_type( &str );
 }
 
diff --git a/server/file.c b/server/file.c
index 7ca650f9..61bbd846 100644
--- a/server/file.c
+++ b/server/file.c
@@ -270,8 +270,7 @@ static void file_dump( struct object *obj, int verbose )
 
 struct object_type *file_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'F','i','l','e'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_File, sizeof(type_File) };
     return get_object_type( &str );
 }
 
diff --git a/server/mailslot.c b/server/mailslot.c
index 75a397db..6c998656 100644
--- a/server/mailslot.c
+++ b/server/mailslot.c
@@ -350,8 +350,7 @@ static void mailslot_device_dump( struct object *obj, int verbose )
 
 static struct object_type *mailslot_device_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'D','e','v','i','c','e'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    const struct unicode_str str = { type_Device, sizeof(type_Device) };
     return get_object_type( &str );
 }
 
diff --git a/server/main.c b/server/main.c
index f984bfc1..9739e3ac 100644
--- a/server/main.c
+++ b/server/main.c
@@ -146,6 +146,7 @@ int main( int argc, char *argv[] )
     init_directories();
     init_registry();
     init_shared_memory();
+    init_types();
     main_loop();
     return 0;
 }
diff --git a/server/mapping.c b/server/mapping.c
index 2a9c45ad..c3e99c86 100644
--- a/server/mapping.c
+++ b/server/mapping.c
@@ -970,8 +970,7 @@ static void mapping_dump( struct object *obj, int verbose )
 
 static struct object_type *mapping_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'S','e','c','t','i','o','n'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_Section, sizeof(type_Section) };
     return get_object_type( &str );
 }
 
diff --git a/server/mutex.c b/server/mutex.c
index d1887e4b..d458dc6f 100644
--- a/server/mutex.c
+++ b/server/mutex.c
@@ -141,8 +141,7 @@ static void mutex_dump( struct object *obj, int verbose )
 
 static struct object_type *mutex_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'M','u','t','a','n','t'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_Mutant, sizeof(type_Mutant) };
     return get_object_type( &str );
 }
 
diff --git a/server/named_pipe.c b/server/named_pipe.c
index 101ff632..ceb1a6cb 100644
--- a/server/named_pipe.c
+++ b/server/named_pipe.c
@@ -449,8 +449,7 @@ static void named_pipe_device_dump( struct object *obj, int verbose )
 
 static struct object_type *named_pipe_device_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'D','e','v','i','c','e'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    const struct unicode_str str = { type_Device, sizeof(type_Device) };
     return get_object_type( &str );
 }
 
diff --git a/server/object.c b/server/object.c
index 4455718a..8b4a8429 100644
--- a/server/object.c
+++ b/server/object.c
@@ -700,3 +700,39 @@ int no_close_handle( struct object *obj, struct process *process, obj_handle_t h
 void no_destroy( struct object *obj )
 {
 }
+
+static const struct unicode_str type_array[] =
+{
+    {type_ObjectType,    sizeof(type_ObjectType)},
+    {type_Directory,     sizeof(type_Directory)},
+    {type_SymbolicLink,  sizeof(type_SymbolicLink)},
+    {type_Token,         sizeof(type_Token)},
+    {type_Job,           sizeof(type_Job)},
+    {type_Process,       sizeof(type_Process)},
+    {type_Thread,        sizeof(type_Thread)},
+    {type_Event,         sizeof(type_Event)},
+    {type_Mutant,        sizeof(type_Mutant)},
+    {type_Semaphore,     sizeof(type_Semaphore)},
+    {type_Timer,         sizeof(type_Timer)},
+    {type_KeyedEvent,    sizeof(type_KeyedEvent)},
+    {type_WindowStation, sizeof(type_WindowStation)},
+    {type_Desktop,       sizeof(type_Desktop)},
+    {type_Device,        sizeof(type_Device)},
+    /* Driver */
+    {type_IoCompletion,  sizeof(type_IoCompletion)},
+    {type_File,          sizeof(type_File)},
+    {type_Section,       sizeof(type_Section)},
+    {type_Key,           sizeof(type_Key)},
+};
+
+void init_types(void)
+{
+    struct object_type *type;
+    unsigned int i;
+
+    for (i = 0; i < sizeof(type_array) / sizeof(type_array[0]); i++)
+    {
+        type = get_object_type(&type_array[i]);
+        if (type) release_object(type);
+    }
+}
diff --git a/server/object.h b/server/object.h
index b5c50e1c..f75ccc0c 100644
--- a/server/object.h
+++ b/server/object.h
@@ -233,6 +233,30 @@ extern struct object_type *get_object_type( const struct unicode_str *name );
 extern int directory_link_name( struct object *obj, struct object_name *name, struct object *parent );
 extern void init_directories(void);
 
+/* type functions */
+
+static const WCHAR type_Desktop[] =       {'D','e','s','k','t','o','p'};
+static const WCHAR type_Device[] =        {'D','e','v','i','c','e'};
+static const WCHAR type_Directory[] =     {'D','i','r','e','c','t','o','r','y'};
+static const WCHAR type_Event[] =         {'E','v','e','n','t'};
+static const WCHAR type_File[] =          {'F','i','l','e'};
+static const WCHAR type_IoCompletion[] =  {'I','o','C','o','m','p','l','e','t','i','o','n'};
+static const WCHAR type_Job[] =           {'J','o','b'};
+static const WCHAR type_Key[] =           {'K','e','y'};
+static const WCHAR type_KeyedEvent[] =    {'K','e','y','e','d','E','v','e','n','t'};
+static const WCHAR type_Mutant[] =        {'M','u','t','a','n','t'};
+static const WCHAR type_ObjectType[] =    {'O','b','j','e','c','t','T','y','p','e'};
+static const WCHAR type_Process[] =       {'P','r','o','c','e','s','s'};
+static const WCHAR type_Section[] =       {'S','e','c','t','i','o','n'};
+static const WCHAR type_Semaphore[] =     {'S','e','m','a','p','h','o','r','e'};
+static const WCHAR type_SymbolicLink[] =  {'S','y','m','b','o','l','i','c','L','i','n','k'};
+static const WCHAR type_Thread[] =        {'T','h','r','e','a','d'};
+static const WCHAR type_Timer[] =         {'T','i','m','e','r'};
+static const WCHAR type_Token[] =         {'T','o','k','e','n'};
+static const WCHAR type_WindowStation[] = {'W','i','n','d','o','w','S','t','a','t','i','o','n'};
+
+extern void init_types(void);
+
 /* symbolic link functions */
 
 extern struct object *create_obj_symlink( struct object *root, const struct unicode_str *name,
diff --git a/server/process.c b/server/process.c
index e24ac30c..d0307022 100644
--- a/server/process.c
+++ b/server/process.c
@@ -211,8 +211,7 @@ static struct job *get_job_obj( struct process *process, obj_handle_t handle, un
 
 static struct object_type *job_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'J','o','b'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_Job, sizeof(type_Job) };
     return get_object_type( &str );
 };
 
@@ -634,8 +633,7 @@ static void process_dump( struct object *obj, int verbose )
 
 static struct object_type *process_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'P','r','o','c','e','s','s'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_Job, sizeof(type_Job) };
     return get_object_type( &str );
 }
 
diff --git a/server/registry.c b/server/registry.c
index dffa3acf..d3f252fc 100644
--- a/server/registry.c
+++ b/server/registry.c
@@ -305,8 +305,7 @@ static void key_dump( struct object *obj, int verbose )
 
 static struct object_type *key_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'K','e','y'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_Key, sizeof(type_Key) };
     return get_object_type( &str );
 }
 
diff --git a/server/semaphore.c b/server/semaphore.c
index 08ff1536..07010434 100644
--- a/server/semaphore.c
+++ b/server/semaphore.c
@@ -127,8 +127,7 @@ static void semaphore_dump( struct object *obj, int verbose )
 
 static struct object_type *semaphore_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'S','e','m','a','p','h','o','r','e'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_Semaphore, sizeof(type_Semaphore) };
     return get_object_type( &str );
 }
 
diff --git a/server/symlink.c b/server/symlink.c
index 9199bc55..eaceee77 100644
--- a/server/symlink.c
+++ b/server/symlink.c
@@ -86,8 +86,7 @@ static void symlink_dump( struct object *obj, int verbose )
 
 static struct object_type *symlink_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'S','y','m','b','o','l','i','c','L','i','n','k'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_SymbolicLink, sizeof(type_SymbolicLink) };
     return get_object_type( &str );
 }
 
diff --git a/server/thread.c b/server/thread.c
index 45c45c6d..aa714e25 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -373,8 +373,7 @@ static void dump_thread( struct object *obj, int verbose )
 
 static struct object_type *thread_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'T','h','r','e','a','d'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_Thread, sizeof(type_Thread) };
     return get_object_type( &str );
 }
 
diff --git a/server/timer.c b/server/timer.c
index 3a786fb4..c2a9728a 100644
--- a/server/timer.c
+++ b/server/timer.c
@@ -189,8 +189,7 @@ static void timer_dump( struct object *obj, int verbose )
 
 static struct object_type *timer_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'T','i','m','e','r'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_Timer, sizeof(type_Timer) };
     return get_object_type( &str );
 }
 
diff --git a/server/token.c b/server/token.c
index f236084b..a6cec249 100644
--- a/server/token.c
+++ b/server/token.c
@@ -172,8 +172,7 @@ static void token_dump( struct object *obj, int verbose )
 
 static struct object_type *token_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'T','o','k','e','n'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_Token, sizeof(type_Token) };
     return get_object_type( &str );
 }
 
diff --git a/server/winstation.c b/server/winstation.c
index a0be0586..dbd091e2 100644
--- a/server/winstation.c
+++ b/server/winstation.c
@@ -141,8 +141,7 @@ static void winstation_dump( struct object *obj, int verbose )
 
 static struct object_type *winstation_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'W','i','n','d','o','w','S','t','a','t','i','o','n'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_WindowStation, sizeof(type_WindowStation) };
     return get_object_type( &str );
 }
 
@@ -246,8 +245,7 @@ static void desktop_dump( struct object *obj, int verbose )
 
 static struct object_type *desktop_get_type( struct object *obj )
 {
-    static const WCHAR name[] = {'D','e','s','k','t','o','p'};
-    static const struct unicode_str str = { name, sizeof(name) };
+    static const struct unicode_str str = { type_Desktop, sizeof(type_Desktop) };
     return get_object_type( &str );
 }
 
-- 
2.20.1

