comctl32/treeview: Fix TVS_SINGLEEXPAND notifications order.
[wine] / dlls / ntdll / nt.c
1 /*
2  * NT basis DLL
3  *
4  * This file contains the Nt* API functions of NTDLL.DLL.
5  * In the original ntdll.dll they all seem to just call int 0x2e (down to the NTOSKRNL)
6  *
7  * Copyright 1996-1998 Marcus Meissner
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #include "config.h"
25 #include "wine/port.h"
26
27 #ifdef HAVE_SYS_PARAM_H
28 # include <sys/param.h>
29 #endif
30 #ifdef HAVE_SYS_SYSCTL_H
31 # include <sys/sysctl.h>
32 #endif
33 #ifdef HAVE_MACHINE_CPU_H
34 # include <machine/cpu.h>
35 #endif
36 #ifdef HAVE_MACH_MACHINE_H
37 # include <mach/machine.h>
38 #endif
39
40 #include <ctype.h>
41 #include <string.h>
42 #include <stdarg.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #ifdef HAVE_SYS_TIME_H
46 # include <sys/time.h>
47 #endif
48 #include <time.h>
49
50 #define NONAMELESSUNION
51 #include "ntstatus.h"
52 #define WIN32_NO_STATUS
53 #include "wine/debug.h"
54 #include "wine/unicode.h"
55 #include "windef.h"
56 #include "winternl.h"
57 #include "ntdll_misc.h"
58 #include "wine/server.h"
59 #include "ddk/wdm.h"
60
61 #ifdef __APPLE__
62 #include <mach/mach_init.h>
63 #include <mach/mach_host.h>
64 #include <mach/vm_map.h>
65 #endif
66
67 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
68
69 /*
70  *      Token
71  */
72
73 /******************************************************************************
74  *  NtDuplicateToken            [NTDLL.@]
75  *  ZwDuplicateToken            [NTDLL.@]
76  */
77 NTSTATUS WINAPI NtDuplicateToken(
78         IN HANDLE ExistingToken,
79         IN ACCESS_MASK DesiredAccess,
80         IN POBJECT_ATTRIBUTES ObjectAttributes,
81         IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
82         IN TOKEN_TYPE TokenType,
83         OUT PHANDLE NewToken)
84 {
85     NTSTATUS status;
86
87     TRACE("(%p,0x%08x,%s,0x%08x,0x%08x,%p)\n",
88           ExistingToken, DesiredAccess, debugstr_ObjectAttributes(ObjectAttributes),
89           ImpersonationLevel, TokenType, NewToken);
90
91     if (ObjectAttributes && ObjectAttributes->SecurityQualityOfService)
92     {
93         SECURITY_QUALITY_OF_SERVICE *SecurityQOS = ObjectAttributes->SecurityQualityOfService;
94         TRACE("ObjectAttributes->SecurityQualityOfService = {%d, %d, %d, %s}\n",
95             SecurityQOS->Length, SecurityQOS->ImpersonationLevel,
96             SecurityQOS->ContextTrackingMode,
97             SecurityQOS->EffectiveOnly ? "TRUE" : "FALSE");
98         ImpersonationLevel = SecurityQOS->ImpersonationLevel;
99     }
100
101     SERVER_START_REQ( duplicate_token )
102     {
103         req->handle              = wine_server_obj_handle( ExistingToken );
104         req->access              = DesiredAccess;
105         req->attributes          = ObjectAttributes ? ObjectAttributes->Attributes : 0;
106         req->primary             = (TokenType == TokenPrimary);
107         req->impersonation_level = ImpersonationLevel;
108         status = wine_server_call( req );
109         if (!status) *NewToken = wine_server_ptr_handle( reply->new_handle );
110     }
111     SERVER_END_REQ;
112
113     return status;
114 }
115
116 /******************************************************************************
117  *  NtOpenProcessToken          [NTDLL.@]
118  *  ZwOpenProcessToken          [NTDLL.@]
119  */
120 NTSTATUS WINAPI NtOpenProcessToken(
121         HANDLE ProcessHandle,
122         DWORD DesiredAccess,
123         HANDLE *TokenHandle)
124 {
125     return NtOpenProcessTokenEx( ProcessHandle, DesiredAccess, 0, TokenHandle );
126 }
127
128 /******************************************************************************
129  *  NtOpenProcessTokenEx   [NTDLL.@]
130  *  ZwOpenProcessTokenEx   [NTDLL.@]
131  */
132 NTSTATUS WINAPI NtOpenProcessTokenEx( HANDLE process, DWORD access, DWORD attributes,
133                                       HANDLE *handle )
134 {
135     NTSTATUS ret;
136
137     TRACE("(%p,0x%08x,0x%08x,%p)\n", process, access, attributes, handle);
138
139     SERVER_START_REQ( open_token )
140     {
141         req->handle     = wine_server_obj_handle( process );
142         req->access     = access;
143         req->attributes = attributes;
144         req->flags      = 0;
145         ret = wine_server_call( req );
146         if (!ret) *handle = wine_server_ptr_handle( reply->token );
147     }
148     SERVER_END_REQ;
149     return ret;
150 }
151
152 /******************************************************************************
153  *  NtOpenThreadToken           [NTDLL.@]
154  *  ZwOpenThreadToken           [NTDLL.@]
155  */
156 NTSTATUS WINAPI NtOpenThreadToken(
157         HANDLE ThreadHandle,
158         DWORD DesiredAccess,
159         BOOLEAN OpenAsSelf,
160         HANDLE *TokenHandle)
161 {
162     return NtOpenThreadTokenEx( ThreadHandle, DesiredAccess, OpenAsSelf, 0, TokenHandle );
163 }
164
165 /******************************************************************************
166  *  NtOpenThreadTokenEx   [NTDLL.@]
167  *  ZwOpenThreadTokenEx   [NTDLL.@]
168  */
169 NTSTATUS WINAPI NtOpenThreadTokenEx( HANDLE thread, DWORD access, BOOLEAN as_self, DWORD attributes,
170                                      HANDLE *handle )
171 {
172     NTSTATUS ret;
173
174     TRACE("(%p,0x%08x,%u,0x%08x,%p)\n", thread, access, as_self, attributes, handle );
175
176     SERVER_START_REQ( open_token )
177     {
178         req->handle     = wine_server_obj_handle( thread );
179         req->access     = access;
180         req->attributes = attributes;
181         req->flags      = OPEN_TOKEN_THREAD;
182         if (as_self) req->flags |= OPEN_TOKEN_AS_SELF;
183         ret = wine_server_call( req );
184         if (!ret) *handle = wine_server_ptr_handle( reply->token );
185     }
186     SERVER_END_REQ;
187
188     return ret;
189 }
190
191 /******************************************************************************
192  *  NtAdjustPrivilegesToken             [NTDLL.@]
193  *  ZwAdjustPrivilegesToken             [NTDLL.@]
194  *
195  * FIXME: parameters unsafe
196  */
197 NTSTATUS WINAPI NtAdjustPrivilegesToken(
198         IN HANDLE TokenHandle,
199         IN BOOLEAN DisableAllPrivileges,
200         IN PTOKEN_PRIVILEGES NewState,
201         IN DWORD BufferLength,
202         OUT PTOKEN_PRIVILEGES PreviousState,
203         OUT PDWORD ReturnLength)
204 {
205     NTSTATUS ret;
206
207     TRACE("(%p,0x%08x,%p,0x%08x,%p,%p)\n",
208         TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
209
210     SERVER_START_REQ( adjust_token_privileges )
211     {
212         req->handle = wine_server_obj_handle( TokenHandle );
213         req->disable_all = DisableAllPrivileges;
214         req->get_modified_state = (PreviousState != NULL);
215         if (!DisableAllPrivileges)
216         {
217             wine_server_add_data( req, NewState->Privileges,
218                                   NewState->PrivilegeCount * sizeof(NewState->Privileges[0]) );
219         }
220         if (PreviousState && BufferLength >= FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
221             wine_server_set_reply( req, PreviousState->Privileges,
222                                    BufferLength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
223         ret = wine_server_call( req );
224         if (PreviousState)
225         {
226             *ReturnLength = reply->len + FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges );
227             PreviousState->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
228         }
229     }
230     SERVER_END_REQ;
231
232     return ret;
233 }
234
235 /******************************************************************************
236 *  NtQueryInformationToken              [NTDLL.@]
237 *  ZwQueryInformationToken              [NTDLL.@]
238 *
239 * NOTES
240 *  Buffer for TokenUser:
241 *   0x00 TOKEN_USER the PSID field points to the SID
242 *   0x08 SID
243 *
244 */
245 NTSTATUS WINAPI NtQueryInformationToken(
246         HANDLE token,
247         TOKEN_INFORMATION_CLASS tokeninfoclass,
248         PVOID tokeninfo,
249         ULONG tokeninfolength,
250         PULONG retlen )
251 {
252     ULONG len;
253     NTSTATUS status = STATUS_SUCCESS;
254
255     TRACE("(%p,%d,%p,%d,%p)\n",
256           token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
257
258     switch (tokeninfoclass)
259     {
260     case TokenSource:
261         len = sizeof(TOKEN_SOURCE);
262         break;
263     case TokenType:
264         len = sizeof (TOKEN_TYPE);
265         break;
266     case TokenImpersonationLevel:
267         len = sizeof(SECURITY_IMPERSONATION_LEVEL);
268         break;
269     case TokenStatistics:
270         len = sizeof(TOKEN_STATISTICS);
271         break;
272     default:
273         len = 0;
274     }
275
276     if (retlen) *retlen = len;
277
278     if (tokeninfolength < len)
279         return STATUS_BUFFER_TOO_SMALL;
280
281     switch (tokeninfoclass)
282     {
283     case TokenUser:
284         SERVER_START_REQ( get_token_sid )
285         {
286             TOKEN_USER * tuser = tokeninfo;
287             PSID sid = tuser + 1;
288             DWORD sid_len = tokeninfolength < sizeof(TOKEN_USER) ? 0 : tokeninfolength - sizeof(TOKEN_USER);
289
290             req->handle = wine_server_obj_handle( token );
291             req->which_sid = tokeninfoclass;
292             wine_server_set_reply( req, sid, sid_len );
293             status = wine_server_call( req );
294             if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_USER);
295             if (status == STATUS_SUCCESS)
296             {
297                 tuser->User.Sid = sid;
298                 tuser->User.Attributes = 0;
299             }
300         }
301         SERVER_END_REQ;
302         break;
303     case TokenGroups:
304     {
305         char stack_buffer[256];
306         unsigned int server_buf_len = sizeof(stack_buffer);
307         void *buffer = stack_buffer;
308         BOOLEAN need_more_memory;
309
310         /* we cannot work out the size of the server buffer required for the
311          * input size, since there are two factors affecting how much can be
312          * stored in the buffer - number of groups and lengths of sids */
313         do
314         {
315             need_more_memory = FALSE;
316
317             SERVER_START_REQ( get_token_groups )
318             {
319                 TOKEN_GROUPS *groups = tokeninfo;
320
321                 req->handle = wine_server_obj_handle( token );
322                 wine_server_set_reply( req, buffer, server_buf_len );
323                 status = wine_server_call( req );
324                 if (status == STATUS_BUFFER_TOO_SMALL)
325                 {
326                     if (buffer == stack_buffer)
327                         buffer = RtlAllocateHeap(GetProcessHeap(), 0, reply->user_len);
328                     else
329                         buffer = RtlReAllocateHeap(GetProcessHeap(), 0, buffer, reply->user_len);
330                     if (!buffer) return STATUS_NO_MEMORY;
331
332                     server_buf_len = reply->user_len;
333                     need_more_memory = TRUE;
334                 }
335                 else if (status == STATUS_SUCCESS)
336                 {
337                     struct token_groups *tg = buffer;
338                     unsigned int *attr = (unsigned int *)(tg + 1);
339                     ULONG i;
340                     const int non_sid_portion = (sizeof(struct token_groups) + tg->count * sizeof(unsigned int));
341                     SID *sids = (SID *)((char *)tokeninfo + FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ));
342                     ULONG needed_bytes = FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ) +
343                         reply->user_len - non_sid_portion;
344
345                     if (retlen) *retlen = needed_bytes;
346
347                     if (needed_bytes <= tokeninfolength)
348                     {
349                         groups->GroupCount = tg->count;
350                         memcpy( sids, (char *)buffer + non_sid_portion,
351                                 reply->user_len - non_sid_portion );
352
353                         for (i = 0; i < tg->count; i++)
354                         {
355                             groups->Groups[i].Attributes = attr[i];
356                             groups->Groups[i].Sid = sids;
357                             sids = (SID *)((char *)sids + RtlLengthSid(sids));
358                         }
359                     }
360                     else status = STATUS_BUFFER_TOO_SMALL;
361                 }
362                 else if (retlen) *retlen = 0;
363             }
364             SERVER_END_REQ;
365         } while (need_more_memory);
366         if (buffer != stack_buffer) RtlFreeHeap(GetProcessHeap(), 0, buffer);
367         break;
368     }
369     case TokenPrimaryGroup:
370         SERVER_START_REQ( get_token_sid )
371         {
372             TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
373             PSID sid = tgroup + 1;
374             DWORD sid_len = tokeninfolength < sizeof(TOKEN_PRIMARY_GROUP) ? 0 : tokeninfolength - sizeof(TOKEN_PRIMARY_GROUP);
375
376             req->handle = wine_server_obj_handle( token );
377             req->which_sid = tokeninfoclass;
378             wine_server_set_reply( req, sid, sid_len );
379             status = wine_server_call( req );
380             if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_PRIMARY_GROUP);
381             if (status == STATUS_SUCCESS)
382                 tgroup->PrimaryGroup = sid;
383         }
384         SERVER_END_REQ;
385         break;
386     case TokenPrivileges:
387         SERVER_START_REQ( get_token_privileges )
388         {
389             TOKEN_PRIVILEGES *tpriv = tokeninfo;
390             req->handle = wine_server_obj_handle( token );
391             if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
392                 wine_server_set_reply( req, tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
393             status = wine_server_call( req );
394             if (retlen) *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
395             if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
396         }
397         SERVER_END_REQ;
398         break;
399     case TokenOwner:
400         SERVER_START_REQ( get_token_sid )
401         {
402             TOKEN_OWNER *towner = tokeninfo;
403             PSID sid = towner + 1;
404             DWORD sid_len = tokeninfolength < sizeof(TOKEN_OWNER) ? 0 : tokeninfolength - sizeof(TOKEN_OWNER);
405
406             req->handle = wine_server_obj_handle( token );
407             req->which_sid = tokeninfoclass;
408             wine_server_set_reply( req, sid, sid_len );
409             status = wine_server_call( req );
410             if (retlen) *retlen = reply->sid_len + sizeof(TOKEN_OWNER);
411             if (status == STATUS_SUCCESS)
412                 towner->Owner = sid;
413         }
414         SERVER_END_REQ;
415         break;
416     case TokenImpersonationLevel:
417         SERVER_START_REQ( get_token_impersonation_level )
418         {
419             SECURITY_IMPERSONATION_LEVEL *impersonation_level = tokeninfo;
420             req->handle = wine_server_obj_handle( token );
421             status = wine_server_call( req );
422             if (status == STATUS_SUCCESS)
423                 *impersonation_level = reply->impersonation_level;
424         }
425         SERVER_END_REQ;
426         break;
427     case TokenStatistics:
428         SERVER_START_REQ( get_token_statistics )
429         {
430             TOKEN_STATISTICS *statistics = tokeninfo;
431             req->handle = wine_server_obj_handle( token );
432             status = wine_server_call( req );
433             if (status == STATUS_SUCCESS)
434             {
435                 statistics->TokenId.LowPart  = reply->token_id.low_part;
436                 statistics->TokenId.HighPart = reply->token_id.high_part;
437                 statistics->AuthenticationId.LowPart  = 0; /* FIXME */
438                 statistics->AuthenticationId.HighPart = 0; /* FIXME */
439                 statistics->ExpirationTime.u.HighPart = 0x7fffffff;
440                 statistics->ExpirationTime.u.LowPart  = 0xffffffff;
441                 statistics->TokenType = reply->primary ? TokenPrimary : TokenImpersonation;
442                 statistics->ImpersonationLevel = reply->impersonation_level;
443
444                 /* kernel information not relevant to us */
445                 statistics->DynamicCharged = 0;
446                 statistics->DynamicAvailable = 0;
447
448                 statistics->GroupCount = reply->group_count;
449                 statistics->PrivilegeCount = reply->privilege_count;
450                 statistics->ModifiedId.LowPart  = reply->modified_id.low_part;
451                 statistics->ModifiedId.HighPart = reply->modified_id.high_part;
452             }
453         }
454         SERVER_END_REQ;
455         break;
456     case TokenType:
457         SERVER_START_REQ( get_token_statistics )
458         {
459             TOKEN_TYPE *token_type = tokeninfo;
460             req->handle = wine_server_obj_handle( token );
461             status = wine_server_call( req );
462             if (status == STATUS_SUCCESS)
463                 *token_type = reply->primary ? TokenPrimary : TokenImpersonation;
464         }
465         SERVER_END_REQ;
466         break;
467     case TokenDefaultDacl:
468         SERVER_START_REQ( get_token_default_dacl )
469         {
470             TOKEN_DEFAULT_DACL *default_dacl = tokeninfo;
471             ACL *acl = (ACL *)(default_dacl + 1);
472             DWORD acl_len;
473
474             if (tokeninfolength < sizeof(TOKEN_DEFAULT_DACL)) acl_len = 0;
475             else acl_len = tokeninfolength - sizeof(TOKEN_DEFAULT_DACL);
476
477             req->handle = wine_server_obj_handle( token );
478             wine_server_set_reply( req, acl, acl_len );
479             status = wine_server_call( req );
480
481             if (retlen) *retlen = reply->acl_len + sizeof(TOKEN_DEFAULT_DACL);
482             if (status == STATUS_SUCCESS)
483             {
484                 if (reply->acl_len)
485                     default_dacl->DefaultDacl = acl;
486                 else
487                     default_dacl->DefaultDacl = NULL;
488             }
489         }
490         SERVER_END_REQ;
491         break;
492     default:
493         {
494             ERR("Unhandled Token Information class %d!\n", tokeninfoclass);
495             return STATUS_NOT_IMPLEMENTED;
496         }
497     }
498     return status;
499 }
500
501 /******************************************************************************
502 *  NtSetInformationToken                [NTDLL.@]
503 *  ZwSetInformationToken                [NTDLL.@]
504 */
505 NTSTATUS WINAPI NtSetInformationToken(
506         HANDLE TokenHandle,
507         TOKEN_INFORMATION_CLASS TokenInformationClass,
508         PVOID TokenInformation,
509         ULONG TokenInformationLength)
510 {
511     NTSTATUS ret = STATUS_NOT_IMPLEMENTED;
512
513     TRACE("%p %d %p %u\n", TokenHandle, TokenInformationClass,
514            TokenInformation, TokenInformationLength);
515
516     switch (TokenInformationClass)
517     {
518     case TokenDefaultDacl:
519         if (TokenInformationLength < sizeof(TOKEN_DEFAULT_DACL))
520         {
521             ret = STATUS_INFO_LENGTH_MISMATCH;
522             break;
523         }
524         if (!TokenInformation)
525         {
526             ret = STATUS_ACCESS_VIOLATION;
527             break;
528         }
529         SERVER_START_REQ( set_token_default_dacl )
530         {
531             ACL *acl = ((TOKEN_DEFAULT_DACL *)TokenInformation)->DefaultDacl;
532             WORD size;
533
534             if (acl) size = acl->AclSize;
535             else size = 0;
536
537             req->handle = wine_server_obj_handle( TokenHandle );
538             wine_server_add_data( req, acl, size );
539             ret = wine_server_call( req );
540         }
541         SERVER_END_REQ;
542         break;
543     default:
544         FIXME("unimplemented class %u\n", TokenInformationClass);
545         break;
546     }
547
548     return ret;
549 }
550
551 /******************************************************************************
552 *  NtAdjustGroupsToken          [NTDLL.@]
553 *  ZwAdjustGroupsToken          [NTDLL.@]
554 */
555 NTSTATUS WINAPI NtAdjustGroupsToken(
556         HANDLE TokenHandle,
557         BOOLEAN ResetToDefault,
558         PTOKEN_GROUPS NewState,
559         ULONG BufferLength,
560         PTOKEN_GROUPS PreviousState,
561         PULONG ReturnLength)
562 {
563     FIXME("%p %d %p %u %p %p\n", TokenHandle, ResetToDefault,
564           NewState, BufferLength, PreviousState, ReturnLength);
565     return STATUS_NOT_IMPLEMENTED;
566 }
567
568 /******************************************************************************
569 *  NtPrivilegeCheck             [NTDLL.@]
570 *  ZwPrivilegeCheck             [NTDLL.@]
571 */
572 NTSTATUS WINAPI NtPrivilegeCheck(
573     HANDLE ClientToken,
574     PPRIVILEGE_SET RequiredPrivileges,
575     PBOOLEAN Result)
576 {
577     NTSTATUS status;
578     SERVER_START_REQ( check_token_privileges )
579     {
580         req->handle = wine_server_obj_handle( ClientToken );
581         req->all_required = ((RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) ? TRUE : FALSE);
582         wine_server_add_data( req, RequiredPrivileges->Privilege,
583             RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
584         wine_server_set_reply( req, RequiredPrivileges->Privilege,
585             RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
586
587         status = wine_server_call( req );
588
589         if (status == STATUS_SUCCESS)
590             *Result = (reply->has_privileges ? TRUE : FALSE);
591     }
592     SERVER_END_REQ;
593     return status;
594 }
595
596 /*
597  *      Section
598  */
599
600 /******************************************************************************
601  *  NtQuerySection      [NTDLL.@]
602  */
603 NTSTATUS WINAPI NtQuerySection(
604         IN HANDLE SectionHandle,
605         IN SECTION_INFORMATION_CLASS SectionInformationClass,
606         OUT PVOID SectionInformation,
607         IN ULONG Length,
608         OUT PULONG ResultLength)
609 {
610         FIXME("(%p,%d,%p,0x%08x,%p) stub!\n",
611         SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
612         return 0;
613 }
614
615 /*
616  *      ports
617  */
618
619 /******************************************************************************
620  *  NtCreatePort                [NTDLL.@]
621  *  ZwCreatePort                [NTDLL.@]
622  */
623 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
624                              ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
625 {
626   FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle,ObjectAttributes,
627         MaxConnectInfoLength,MaxDataLength,reserved);
628   return STATUS_NOT_IMPLEMENTED;
629 }
630
631 /******************************************************************************
632  *  NtConnectPort               [NTDLL.@]
633  *  ZwConnectPort               [NTDLL.@]
634  */
635 NTSTATUS WINAPI NtConnectPort(
636         PHANDLE PortHandle,
637         PUNICODE_STRING PortName,
638         PSECURITY_QUALITY_OF_SERVICE SecurityQos,
639         PLPC_SECTION_WRITE WriteSection,
640         PLPC_SECTION_READ ReadSection,
641         PULONG MaximumMessageLength,
642         PVOID ConnectInfo,
643         PULONG pConnectInfoLength)
644 {
645     FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
646           PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
647           WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
648           pConnectInfoLength);
649     if (ConnectInfo && pConnectInfoLength)
650         TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
651     return STATUS_NOT_IMPLEMENTED;
652 }
653
654 /******************************************************************************
655  *  NtSecureConnectPort                (NTDLL.@)
656  *  ZwSecureConnectPort                (NTDLL.@)
657  */
658 NTSTATUS WINAPI NtSecureConnectPort(
659         PHANDLE PortHandle,
660         PUNICODE_STRING PortName,
661         PSECURITY_QUALITY_OF_SERVICE SecurityQos,
662         PLPC_SECTION_WRITE WriteSection,
663         PSID pSid,
664         PLPC_SECTION_READ ReadSection,
665         PULONG MaximumMessageLength,
666         PVOID ConnectInfo,
667         PULONG pConnectInfoLength)
668 {
669     FIXME("(%p,%s,%p,%p,%p,%p,%p,%p,%p),stub!\n",
670           PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
671           WriteSection,pSid,ReadSection,MaximumMessageLength,ConnectInfo,
672           pConnectInfoLength);
673     return STATUS_NOT_IMPLEMENTED;
674 }
675
676 /******************************************************************************
677  *  NtListenPort                [NTDLL.@]
678  *  ZwListenPort                [NTDLL.@]
679  */
680 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
681 {
682   FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
683   return STATUS_NOT_IMPLEMENTED;
684 }
685
686 /******************************************************************************
687  *  NtAcceptConnectPort [NTDLL.@]
688  *  ZwAcceptConnectPort [NTDLL.@]
689  */
690 NTSTATUS WINAPI NtAcceptConnectPort(
691         PHANDLE PortHandle,
692         ULONG PortIdentifier,
693         PLPC_MESSAGE pLpcMessage,
694         BOOLEAN Accept,
695         PLPC_SECTION_WRITE WriteSection,
696         PLPC_SECTION_READ ReadSection)
697 {
698   FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
699         PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
700   return STATUS_NOT_IMPLEMENTED;
701 }
702
703 /******************************************************************************
704  *  NtCompleteConnectPort       [NTDLL.@]
705  *  ZwCompleteConnectPort       [NTDLL.@]
706  */
707 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
708 {
709   FIXME("(%p),stub!\n",PortHandle);
710   return STATUS_NOT_IMPLEMENTED;
711 }
712
713 /******************************************************************************
714  *  NtRegisterThreadTerminatePort       [NTDLL.@]
715  *  ZwRegisterThreadTerminatePort       [NTDLL.@]
716  */
717 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
718 {
719   FIXME("(%p),stub!\n",PortHandle);
720   return STATUS_NOT_IMPLEMENTED;
721 }
722
723 /******************************************************************************
724  *  NtRequestWaitReplyPort              [NTDLL.@]
725  *  ZwRequestWaitReplyPort              [NTDLL.@]
726  */
727 NTSTATUS WINAPI NtRequestWaitReplyPort(
728         HANDLE PortHandle,
729         PLPC_MESSAGE pLpcMessageIn,
730         PLPC_MESSAGE pLpcMessageOut)
731 {
732   FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
733   if(pLpcMessageIn)
734   {
735     TRACE("Message to send:\n");
736     TRACE("\tDataSize            = %u\n",pLpcMessageIn->DataSize);
737     TRACE("\tMessageSize         = %u\n",pLpcMessageIn->MessageSize);
738     TRACE("\tMessageType         = %u\n",pLpcMessageIn->MessageType);
739     TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
740     TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
741     TRACE("\tClientId.UniqueThread  = %p\n",pLpcMessageIn->ClientId.UniqueThread);
742     TRACE("\tMessageId           = %lu\n",pLpcMessageIn->MessageId);
743     TRACE("\tSectionSize         = %lu\n",pLpcMessageIn->SectionSize);
744     TRACE("\tData                = %s\n",
745       debugstr_an((const char*)pLpcMessageIn->Data,pLpcMessageIn->DataSize));
746   }
747   return STATUS_NOT_IMPLEMENTED;
748 }
749
750 /******************************************************************************
751  *  NtReplyWaitReceivePort      [NTDLL.@]
752  *  ZwReplyWaitReceivePort      [NTDLL.@]
753  */
754 NTSTATUS WINAPI NtReplyWaitReceivePort(
755         HANDLE PortHandle,
756         PULONG PortIdentifier,
757         PLPC_MESSAGE ReplyMessage,
758         PLPC_MESSAGE Message)
759 {
760   FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
761   return STATUS_NOT_IMPLEMENTED;
762 }
763
764 /*
765  *      Misc
766  */
767
768  /******************************************************************************
769  *  NtSetIntervalProfile        [NTDLL.@]
770  *  ZwSetIntervalProfile        [NTDLL.@]
771  */
772 NTSTATUS WINAPI NtSetIntervalProfile(
773         ULONG Interval,
774         KPROFILE_SOURCE Source)
775 {
776     FIXME("%u,%d\n", Interval, Source);
777     return STATUS_SUCCESS;
778 }
779
780 static  SYSTEM_CPU_INFORMATION cached_sci;
781 static  ULONGLONG cpuHz = 1000000000; /* default to a 1GHz */
782
783 #define AUTH    0x68747541      /* "Auth" */
784 #define ENTI    0x69746e65      /* "enti" */
785 #define CAMD    0x444d4163      /* "cAMD" */
786
787 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
788  * We are compiled with -fPIC, so we can't clobber ebx.
789  */
790 static inline void do_cpuid(unsigned int ax, unsigned int *p)
791 {
792 #ifdef __i386__
793         __asm__("pushl %%ebx\n\t"
794                 "cpuid\n\t"
795                 "movl %%ebx, %%esi\n\t"
796                 "popl %%ebx"
797                 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
798                 :  "0" (ax));
799 #endif
800 }
801
802 /* From xf86info havecpuid.c 1.11 */
803 static inline int have_cpuid(void)
804 {
805 #ifdef __i386__
806         unsigned int f1, f2;
807         __asm__("pushfl\n\t"
808                 "pushfl\n\t"
809                 "popl %0\n\t"
810                 "movl %0,%1\n\t"
811                 "xorl %2,%0\n\t"
812                 "pushl %0\n\t"
813                 "popfl\n\t"
814                 "pushfl\n\t"
815                 "popl %0\n\t"
816                 "popfl"
817                 : "=&r" (f1), "=&r" (f2)
818                 : "ir" (0x00200000));
819         return ((f1^f2) & 0x00200000) != 0;
820 #else
821         return 0;
822 #endif
823 }
824
825 static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
826 {
827     unsigned int regs[4], regs2[4];
828
829     if (!have_cpuid()) return;
830
831     do_cpuid(0x00000000, regs);  /* get standard cpuid level and vendor name */
832     if (regs[0]>=0x00000001)   /* Check for supported cpuid version */
833     {
834         do_cpuid(0x00000001, regs2); /* get cpu features */
835         switch ((regs2[0] >> 8) & 0xf)  /* cpu family */
836         {
837         case 3: info->Level = 3;        break;
838         case 4: info->Level = 4;        break;
839         case 5: info->Level = 5;        break;
840         case 15: /* PPro/2/3/4 has same info as P1 */
841         case 6: info->Level = 6;         break;
842         default:
843             FIXME("unknown cpu family %d, please report! (-> setting to 386)\n",
844                   (regs2[0] >> 8)&0xf);
845             info->Level = 3;
846             break;
847         }
848         user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED]       = !(regs2[3] & 1);
849         user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE]   = (regs2[3] & (1 << 4 )) >> 4;
850         user_shared_data->ProcessorFeatures[PF_PAE_ENABLED]                   = (regs2[3] & (1 << 6 )) >> 6;
851         user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE]       = (regs2[3] & (1 << 8 )) >> 8;
852         user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE]    = (regs2[3] & (1 << 23)) >> 23;
853         user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE]   = (regs2[3] & (1 << 25)) >> 25;
854         user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 26)) >> 26;
855
856         if (regs[1] == AUTH && regs[3] == ENTI && regs[2] == CAMD)
857         {
858             do_cpuid(0x80000000, regs);  /* get vendor cpuid level */
859             if (regs[0] >= 0x80000001)
860             {
861                 do_cpuid(0x80000001, regs2);  /* get vendor features */
862                 user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 31 )) >> 31;
863             }
864         }
865     }
866 }
867
868 /******************************************************************
869  *              fill_cpu_info
870  *
871  * inits a couple of places with CPU related information:
872  * - cached_sci & cpuHZ in this file
873  * - Peb->NumberOfProcessors
874  * - SharedUserData->ProcessFeatures[] array
875  *
876  * It creates a registry subhierarchy, looking like:
877  * "\HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\Identifier (CPU x86)".
878  * Note that there is a hierarchy for every processor installed, so this
879  * supports multiprocessor systems. This is done like Win95 does it, I think.
880  *
881  * It creates some registry entries in the environment part:
882  * "\HKLM\System\CurrentControlSet\Control\Session Manager\Environment". These are
883  * always present. When deleted, Windows will add them again.
884  */
885 void fill_cpu_info(void)
886 {
887     memset(&cached_sci, 0, sizeof(cached_sci));
888     /* choose sensible defaults ...
889      * FIXME: perhaps overridable with precompiler flags?
890      */
891 #ifdef __i386__
892     cached_sci.Architecture     = PROCESSOR_ARCHITECTURE_INTEL;
893     cached_sci.Level            = 5; /* 586 */
894 #elif defined(__x86_64__)
895     cached_sci.Architecture     = PROCESSOR_ARCHITECTURE_AMD64;
896 #elif defined(__powerpc__)
897     cached_sci.Architecture     = PROCESSOR_ARCHITECTURE_PPC;
898 #elif defined(__ALPHA__)
899     cached_sci.Architecture     = PROCESSOR_ARCHITECTURE_ALPHA;
900 #else
901 #error Unknown CPU
902 #endif
903     cached_sci.Revision         = 0;
904     cached_sci.Reserved         = 0;
905     cached_sci.FeatureSet       = 0x1fff; /* FIXME: set some sensible defaults out of ProcessFeatures[] */
906
907     NtCurrentTeb()->Peb->NumberOfProcessors = 1;
908
909     /* Hmm, reasonable processor feature defaults? */
910
911 #ifdef linux
912     {
913         char line[200];
914         FILE *f = fopen ("/proc/cpuinfo", "r");
915
916         if (!f)
917                 return;
918         while (fgets(line,200,f) != NULL)
919         {
920             char        *s,*value;
921
922             /* NOTE: the ':' is the only character we can rely on */
923             if (!(value = strchr(line,':')))
924                 continue;
925
926             /* terminate the valuename */
927             s = value - 1;
928             while ((s >= line) && ((*s == ' ') || (*s == '\t'))) s--;
929             *(s + 1) = '\0';
930
931             /* and strip leading spaces from value */
932             value += 1;
933             while (*value==' ') value++;
934             if ((s = strchr(value,'\n')))
935                 *s='\0';
936
937             if (!strcasecmp(line, "processor"))
938             {
939                 /* processor number counts up... */
940                 unsigned int x;
941
942                 if (sscanf(value, "%d",&x))
943                     if (x + 1 > NtCurrentTeb()->Peb->NumberOfProcessors)
944                         NtCurrentTeb()->Peb->NumberOfProcessors = x + 1;
945
946                 continue;
947             }
948             if (!strcasecmp(line, "model"))
949             {
950                 /* First part of Revision */
951                 int     x;
952
953                 if (sscanf(value, "%d",&x))
954                     cached_sci.Revision = cached_sci.Revision | (x << 8);
955
956                 continue;
957             }
958
959             /* 2.1 method */
960             if (!strcasecmp(line, "cpu family"))
961             {
962                 if (isdigit(value[0]))
963                 {
964                     cached_sci.Level = atoi(value);
965                 }
966                 continue;
967             }
968             /* old 2.0 method */
969             if (!strcasecmp(line, "cpu"))
970             {
971                 if (isdigit(value[0]) && value[1] == '8' && value[2] == '6' && value[3] == 0)
972                 {
973                     switch (cached_sci.Level = value[0] - '0')
974                     {
975                     case 3:
976                     case 4:
977                     case 5:
978                     case 6:
979                         break;
980                     default:
981                         FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value);
982                         cached_sci.Level = 3;
983                         break;
984                     }
985                 }
986                 continue;
987             }
988             if (!strcasecmp(line, "stepping"))
989             {
990                 /* Second part of Revision */
991                 int     x;
992
993                 if (sscanf(value, "%d",&x))
994                     cached_sci.Revision = cached_sci.Revision | x;
995                 continue;
996             }
997             if (!strcasecmp(line, "cpu MHz"))
998             {
999                 double cmz;
1000                 if (sscanf( value, "%lf", &cmz ) == 1)
1001                 {
1002                     /* SYSTEMINFO doesn't have a slot for cpu speed, so store in a global */
1003                     cpuHz = cmz * 1000 * 1000;
1004                 }
1005                 continue;
1006             }
1007             if (!strcasecmp(line, "fdiv_bug"))
1008             {
1009                 if (!strncasecmp(value, "yes",3))
1010                     user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
1011                 continue;
1012             }
1013             if (!strcasecmp(line, "fpu"))
1014             {
1015                 if (!strncasecmp(value, "no",2))
1016                     user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1017                 continue;
1018             }
1019             if (!strcasecmp(line, "flags") || !strcasecmp(line, "features"))
1020             {
1021                 if (strstr(value, "cx8"))
1022                     user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1023                 if (strstr(value, "mmx"))
1024                     user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1025                 if (strstr(value, "tsc"))
1026                     user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1027                 if (strstr(value, "3dnow"))
1028                     user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
1029                 /* This will also catch sse2, but we have sse itself
1030                  * if we have sse2, so no problem */
1031                 if (strstr(value, "sse"))
1032                     user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
1033                 if (strstr(value, "sse2"))
1034                     user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
1035                 if (strstr(value, "pae"))
1036                     user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = TRUE;
1037
1038                 continue;
1039             }
1040         }
1041         fclose(f);
1042     }
1043 #elif defined (__NetBSD__)
1044     {
1045         int mib[2];
1046         int value;
1047         size_t val_len;
1048         char model[256];
1049         char *cpuclass;
1050         FILE *f = fopen("/var/run/dmesg.boot", "r");
1051
1052         /* first deduce as much as possible from the sysctls */
1053         mib[0] = CTL_MACHDEP;
1054 #ifdef CPU_FPU_PRESENT
1055         mib[1] = CPU_FPU_PRESENT;
1056         val_len = sizeof(value);
1057         if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1058             user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = !value;
1059 #endif
1060 #ifdef CPU_SSE
1061         mib[1] = CPU_SSE;   /* this should imply MMX */
1062         val_len = sizeof(value);
1063         if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1064             if (value) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1065 #endif
1066 #ifdef CPU_SSE2
1067         mib[1] = CPU_SSE2;  /* this should imply MMX */
1068         val_len = sizeof(value);
1069         if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1070             if (value) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1071 #endif
1072         mib[0] = CTL_HW;
1073         mib[1] = HW_NCPU;
1074         val_len = sizeof(value);
1075         if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
1076             if (value > NtCurrentTeb()->Peb->NumberOfProcessors)
1077                 NtCurrentTeb()->Peb->NumberOfProcessors = value;
1078         mib[1] = HW_MODEL;
1079         val_len = sizeof(model)-1;
1080         if (sysctl(mib, 2, model, &val_len, NULL, 0) >= 0)
1081         {
1082             model[val_len] = '\0'; /* just in case */
1083             cpuclass = strstr(model, "-class");
1084             if (cpuclass != NULL) {
1085                 while(cpuclass > model && cpuclass[0] != '(') cpuclass--;
1086                 if (!strncmp(cpuclass+1, "386", 3))
1087                 {
1088                     cached_sci.Level= 3;
1089                 }
1090                 if (!strncmp(cpuclass+1, "486", 3))
1091                 {
1092                     cached_sci.Level= 4;
1093                 }
1094                 if (!strncmp(cpuclass+1, "586", 3))
1095                 {
1096                     cached_sci.Level= 5;
1097                 }
1098                 if (!strncmp(cpuclass+1, "686", 3))
1099                 {
1100                     cached_sci.Level= 6;
1101                     /* this should imply MMX */
1102                     user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1103                 }
1104             }
1105         }
1106
1107         /* it may be worth reading from /var/run/dmesg.boot for
1108            additional information such as CX8, MMX and TSC
1109            (however this information should be considered less
1110            reliable than that from the sysctl calls) */
1111         if (f != NULL)
1112         {
1113             while (fgets(model, 255, f) != NULL)
1114             {
1115                 int cpu, features;
1116                 if (sscanf(model, "cpu%d: features %x<", &cpu, &features) == 2)
1117                 {
1118                     /* we could scan the string but it is easier
1119                        to test the bits directly */
1120                     if (features & 0x1)
1121                         user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1122                     if (features & 0x10)
1123                         user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1124                     if (features & 0x100)
1125                         user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1126                     if (features & 0x800000)
1127                         user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1128
1129                     break;
1130                 }
1131             }
1132             fclose(f);
1133         }
1134     }
1135 #elif defined(__FreeBSD__)
1136     {
1137         int ret, num;
1138         size_t len;
1139
1140         get_cpuinfo( &cached_sci );
1141
1142         /* Check for OS support of SSE -- Is this used, and should it be sse1 or sse2? */
1143         /*len = sizeof(num);
1144           ret = sysctlbyname("hw.instruction_sse", &num, &len, NULL, 0);
1145           if (!ret)
1146           user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = num;*/
1147
1148         len = sizeof(num);
1149         ret = sysctlbyname("hw.ncpu", &num, &len, NULL, 0);
1150         if (!ret)
1151             NtCurrentTeb()->Peb->NumberOfProcessors = num;
1152
1153         len = sizeof(num);
1154         if (!sysctlbyname("dev.cpu.0.freq", &num, &len, NULL, 0))
1155             cpuHz = num * 1000 * 1000;
1156     }
1157 #elif defined(__sun)
1158     {
1159         int num = sysconf( _SC_NPROCESSORS_ONLN );
1160
1161         if (num == -1) num = 1;
1162         get_cpuinfo( &cached_sci );
1163         NtCurrentTeb()->Peb->NumberOfProcessors = num;
1164     }
1165 #elif defined (__OpenBSD__)
1166     {
1167         int mib[2], num;
1168         size_t len;
1169
1170         mib[0] = CTL_HW;
1171         mib[1] = HW_NCPU;
1172         len = sizeof(num);
1173
1174         num = sysctl(mib, 2, &num, &len, NULL, 0);
1175         NtCurrentTeb()->Peb->NumberOfProcessors = num;
1176     }
1177 #elif defined (__APPLE__)
1178     {
1179         size_t valSize;
1180         unsigned long long longVal;
1181         int value;
1182         int cputype;
1183         char buffer[256];
1184
1185         valSize = sizeof(int);
1186         if (sysctlbyname ("hw.optional.floatingpoint", &value, &valSize, NULL, 0) == 0)
1187         {
1188             if (value)
1189                 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = FALSE;
1190             else
1191                 user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
1192         }
1193         valSize = sizeof(int);
1194         if (sysctlbyname ("hw.ncpu", &value, &valSize, NULL, 0) == 0)
1195             NtCurrentTeb()->Peb->NumberOfProcessors = value;
1196
1197         /* FIXME: we don't use the "hw.activecpu" value... but the cached one */
1198
1199         valSize = sizeof(int);
1200         if (sysctlbyname ("hw.cputype", &cputype, &valSize, NULL, 0) == 0)
1201         {
1202             switch (cputype)
1203             {
1204             case CPU_TYPE_POWERPC:
1205                 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_PPC;
1206                 valSize = sizeof(int);
1207                 if (sysctlbyname ("hw.cpusubtype", &value, &valSize, NULL, 0) == 0)
1208                 {
1209                     switch (value)
1210                     {
1211                     case CPU_SUBTYPE_POWERPC_601:
1212                     case CPU_SUBTYPE_POWERPC_602:       cached_sci.Level = 1;   break;
1213                     case CPU_SUBTYPE_POWERPC_603:       cached_sci.Level = 3;   break;
1214                     case CPU_SUBTYPE_POWERPC_603e:
1215                     case CPU_SUBTYPE_POWERPC_603ev:     cached_sci.Level = 6;   break;
1216                     case CPU_SUBTYPE_POWERPC_604:       cached_sci.Level = 4;   break;
1217                     case CPU_SUBTYPE_POWERPC_604e:      cached_sci.Level = 9;   break;
1218                     case CPU_SUBTYPE_POWERPC_620:       cached_sci.Level = 20;  break;
1219                     case CPU_SUBTYPE_POWERPC_750:       /* G3/G4 derive from 603 so ... */
1220                     case CPU_SUBTYPE_POWERPC_7400:
1221                     case CPU_SUBTYPE_POWERPC_7450:      cached_sci.Level = 6;   break;
1222                     case CPU_SUBTYPE_POWERPC_970:       cached_sci.Level = 9;
1223                         /* :o) user_shared_data->ProcessorFeatures[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
1224                         break;
1225                     default: break;
1226                     }
1227                 }
1228                 break; /* CPU_TYPE_POWERPC */
1229             case CPU_TYPE_I386:
1230                 cached_sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
1231                 valSize = sizeof(int);
1232                 if (sysctlbyname ("machdep.cpu.family", &value, &valSize, NULL, 0) == 0)
1233                 {
1234                     cached_sci.Level = value;
1235                 }
1236                 valSize = sizeof(int);
1237                 if (sysctlbyname ("machdep.cpu.model", &value, &valSize, NULL, 0) == 0)
1238                     cached_sci.Revision = (value << 8);
1239                 valSize = sizeof(int);
1240                 if (sysctlbyname ("machdep.cpu.stepping", &value, &valSize, NULL, 0) == 0)
1241                     cached_sci.Revision |= value;
1242                 valSize = sizeof(buffer);
1243                 if (sysctlbyname ("machdep.cpu.features", buffer, &valSize, NULL, 0) == 0)
1244                 {
1245                     cached_sci.Revision |= value;
1246                     if (strstr(buffer, "CX8"))   user_shared_data->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
1247                     if (strstr(buffer, "MMX"))   user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
1248                     if (strstr(buffer, "TSC"))   user_shared_data->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
1249                     if (strstr(buffer, "3DNOW")) user_shared_data->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
1250                     if (strstr(buffer, "SSE"))   user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
1251                     if (strstr(buffer, "SSE2"))  user_shared_data->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
1252                     if (strstr(buffer, "PAE"))   user_shared_data->ProcessorFeatures[PF_PAE_ENABLED] = TRUE;
1253                 }
1254                 break; /* CPU_TYPE_I386 */
1255             default: break;
1256             } /* switch (cputype) */
1257         }
1258         valSize = sizeof(longVal);
1259         if (!sysctlbyname("hw.cpufrequency", &longVal, &valSize, NULL, 0))
1260             cpuHz = longVal;
1261     }
1262 #else
1263     FIXME("not yet supported on this system\n");
1264 #endif
1265     TRACE("<- CPU arch %d, level %d, rev %d, features 0x%x\n",
1266           cached_sci.Architecture, cached_sci.Level, cached_sci.Revision, cached_sci.FeatureSet);
1267 }
1268
1269 /******************************************************************************
1270  * NtQuerySystemInformation [NTDLL.@]
1271  * ZwQuerySystemInformation [NTDLL.@]
1272  *
1273  * ARGUMENTS:
1274  *  SystemInformationClass      Index to a certain information structure
1275  *      SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
1276  *      SystemCacheInformation          SYSTEM_CACHE_INFORMATION
1277  *      SystemConfigurationInformation  CONFIGURATION_INFORMATION
1278  *      observed (class/len):
1279  *              0x0/0x2c
1280  *              0x12/0x18
1281  *              0x2/0x138
1282  *              0x8/0x600
1283  *              0x25/0xc
1284  *  SystemInformation   caller supplies storage for the information structure
1285  *  Length              size of the structure
1286  *  ResultLength        Data written
1287  */
1288 NTSTATUS WINAPI NtQuerySystemInformation(
1289         IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
1290         OUT PVOID SystemInformation,
1291         IN ULONG Length,
1292         OUT PULONG ResultLength)
1293 {
1294     NTSTATUS    ret = STATUS_SUCCESS;
1295     ULONG       len = 0;
1296
1297     TRACE("(0x%08x,%p,0x%08x,%p)\n",
1298           SystemInformationClass,SystemInformation,Length,ResultLength);
1299
1300     switch (SystemInformationClass)
1301     {
1302     case SystemBasicInformation:
1303         {
1304             SYSTEM_BASIC_INFORMATION sbi;
1305
1306             virtual_get_system_info( &sbi );
1307             len = sizeof(sbi);
1308
1309             if ( Length == len)
1310             {
1311                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1312                 else memcpy( SystemInformation, &sbi, len);
1313             }
1314             else ret = STATUS_INFO_LENGTH_MISMATCH;
1315         }
1316         break;
1317     case SystemCpuInformation:
1318         if (Length >= (len = sizeof(cached_sci)))
1319         {
1320             if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1321             else memcpy(SystemInformation, &cached_sci, len);
1322         }
1323         else ret = STATUS_INFO_LENGTH_MISMATCH;
1324         break;
1325     case SystemPerformanceInformation:
1326         {
1327             SYSTEM_PERFORMANCE_INFORMATION spi;
1328             static BOOL fixme_written = FALSE;
1329
1330             memset(&spi, 0 , sizeof(spi));
1331             len = sizeof(spi);
1332
1333             spi.Reserved3 = 0x7fffffff; /* Available paged pool memory? */
1334
1335             if (Length >= len)
1336             {
1337                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1338                 else memcpy( SystemInformation, &spi, len);
1339             }
1340             else ret = STATUS_INFO_LENGTH_MISMATCH;
1341             if(!fixme_written) {
1342                 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
1343                 fixme_written = TRUE;
1344             }
1345         }
1346         break;
1347     case SystemTimeOfDayInformation:
1348         {
1349             SYSTEM_TIMEOFDAY_INFORMATION sti;
1350
1351             memset(&sti, 0 , sizeof(sti));
1352
1353             /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
1354             sti.liKeBootTime.QuadPart = server_start_time;
1355
1356             if (Length <= sizeof(sti))
1357             {
1358                 len = Length;
1359                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1360                 else memcpy( SystemInformation, &sti, Length);
1361             }
1362             else ret = STATUS_INFO_LENGTH_MISMATCH;
1363         }
1364         break;
1365     case SystemProcessInformation:
1366         {
1367             SYSTEM_PROCESS_INFORMATION* spi = SystemInformation;
1368             SYSTEM_PROCESS_INFORMATION* last = NULL;
1369             HANDLE hSnap = 0;
1370             WCHAR procname[1024];
1371             WCHAR* exename;
1372             DWORD wlen = 0;
1373             DWORD procstructlen = 0;
1374
1375             SERVER_START_REQ( create_snapshot )
1376             {
1377                 req->flags      = SNAP_PROCESS | SNAP_THREAD;
1378                 req->attributes = 0;
1379                 if (!(ret = wine_server_call( req )))
1380                     hSnap = wine_server_ptr_handle( reply->handle );
1381             }
1382             SERVER_END_REQ;
1383             len = 0;
1384             while (ret == STATUS_SUCCESS)
1385             {
1386                 SERVER_START_REQ( next_process )
1387                 {
1388                     req->handle = wine_server_obj_handle( hSnap );
1389                     req->reset = (len == 0);
1390                     wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
1391                     if (!(ret = wine_server_call( req )))
1392                     {
1393                         /* Make sure procname is 0 terminated */
1394                         procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
1395
1396                         /* Get only the executable name, not the path */
1397                         if ((exename = strrchrW(procname, '\\')) != NULL) exename++;
1398                         else exename = procname;
1399
1400                         wlen = (strlenW(exename) + 1) * sizeof(WCHAR);
1401
1402                         procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
1403
1404                         if (Length >= len + procstructlen)
1405                         {
1406                             /* ftCreationTime, ftUserTime, ftKernelTime;
1407                              * vmCounters, ioCounters
1408                              */
1409  
1410                             memset(spi, 0, sizeof(*spi));
1411
1412                             spi->NextEntryOffset = procstructlen - wlen;
1413                             spi->dwThreadCount = reply->threads;
1414
1415                             /* spi->pszProcessName will be set later on */
1416
1417                             spi->dwBasePriority = reply->priority;
1418                             spi->UniqueProcessId = UlongToHandle(reply->pid);
1419                             spi->ParentProcessId = UlongToHandle(reply->ppid);
1420                             spi->HandleCount = reply->handles;
1421
1422                             /* spi->ti will be set later on */
1423
1424                             len += procstructlen;
1425                         }
1426                         else ret = STATUS_INFO_LENGTH_MISMATCH;
1427                     }
1428                 }
1429                 SERVER_END_REQ;
1430  
1431                 if (ret != STATUS_SUCCESS)
1432                 {
1433                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1434                     break;
1435                 }
1436                 else /* Length is already checked for */
1437                 {
1438                     int     i, j;
1439
1440                     /* set thread info */
1441                     i = j = 0;
1442                     while (ret == STATUS_SUCCESS)
1443                     {
1444                         SERVER_START_REQ( next_thread )
1445                         {
1446                             req->handle = wine_server_obj_handle( hSnap );
1447                             req->reset = (j == 0);
1448                             if (!(ret = wine_server_call( req )))
1449                             {
1450                                 j++;
1451                                 if (UlongToHandle(reply->pid) == spi->UniqueProcessId)
1452                                 {
1453                                     /* ftKernelTime, ftUserTime, ftCreateTime;
1454                                      * dwTickCount, dwStartAddress
1455                                      */
1456
1457                                     memset(&spi->ti[i], 0, sizeof(spi->ti));
1458
1459                                     spi->ti[i].CreateTime.QuadPart = 0xdeadbeef;
1460                                     spi->ti[i].ClientId.UniqueProcess = UlongToHandle(reply->pid);
1461                                     spi->ti[i].ClientId.UniqueThread  = UlongToHandle(reply->tid);
1462                                     spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
1463                                     spi->ti[i].dwBasePriority = reply->base_pri;
1464                                     i++;
1465                                 }
1466                             }
1467                         }
1468                         SERVER_END_REQ;
1469                     }
1470                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
1471
1472                     /* now append process name */
1473                     spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->NextEntryOffset);
1474                     spi->ProcessName.Length = wlen - sizeof(WCHAR);
1475                     spi->ProcessName.MaximumLength = wlen;
1476                     memcpy( spi->ProcessName.Buffer, exename, wlen );
1477                     spi->NextEntryOffset += wlen;
1478
1479                     last = spi;
1480                     spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->NextEntryOffset);
1481                 }
1482             }
1483             if (ret == STATUS_SUCCESS && last) last->NextEntryOffset = 0;
1484             if (hSnap) NtClose(hSnap);
1485         }
1486         break;
1487     case SystemProcessorPerformanceInformation:
1488         {
1489             SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
1490             unsigned int cpus = 0;
1491             int out_cpus = Length / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1492
1493             if (out_cpus == 0)
1494             {
1495                 len = 0;
1496                 ret = STATUS_INFO_LENGTH_MISMATCH;
1497                 break;
1498             }
1499             else
1500 #ifdef __APPLE__
1501             {
1502                 processor_cpu_load_info_data_t *pinfo;
1503                 mach_msg_type_number_t info_count;
1504
1505                 if (host_processor_info (mach_host_self (),
1506                                          PROCESSOR_CPU_LOAD_INFO,
1507                                          &cpus,
1508                                          (processor_info_array_t*)&pinfo,
1509                                          &info_count) == 0)
1510                 {
1511                     int i;
1512                     cpus = min(cpus,out_cpus);
1513                     len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
1514                     sppi = RtlAllocateHeap(GetProcessHeap(), 0,len);
1515                     for (i = 0; i < cpus; i++)
1516                     {
1517                         sppi[i].IdleTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_IDLE];
1518                         sppi[i].KernelTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_SYSTEM];
1519                         sppi[i].UserTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_USER];
1520                     }
1521                     vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count * sizeof(natural_t));
1522                 }
1523             }
1524 #else
1525             {
1526                 FILE *cpuinfo = fopen("/proc/stat", "r");
1527                 if (cpuinfo)
1528                 {
1529                     unsigned usr,nice,sys;
1530                     unsigned long idle;
1531                     int count;
1532                     char name[10];
1533                     char line[255];
1534
1535                     /* first line is combined usage */
1536                     if (fgets(line,255,cpuinfo))
1537                         count = sscanf(line, "%s %u %u %u %lu", name, &usr, &nice,
1538                                        &sys, &idle);
1539                     else
1540                         count = 0;
1541                     /* we set this up in the for older non-smp enabled kernels */
1542                     if (count == 5 && strcmp(name, "cpu") == 0)
1543                     {
1544                         sppi = RtlAllocateHeap(GetProcessHeap(), 0,
1545                                                sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1546                         sppi->IdleTime.QuadPart = idle;
1547                         sppi->KernelTime.QuadPart = sys;
1548                         sppi->UserTime.QuadPart = usr;
1549                         cpus = 1;
1550                         len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1551                     }
1552
1553                     do
1554                     {
1555                         if (fgets(line, 255, cpuinfo))
1556                             count = sscanf(line, "%s %u %u %u %lu", name, &usr,
1557                                            &nice, &sys, &idle);
1558                         else
1559                             count = 0;
1560                         if (count == 5 && strncmp(name, "cpu", 3)==0)
1561                         {
1562                             out_cpus --;
1563                             if (name[3]=='0') /* first cpu */
1564                             {
1565                                 sppi->IdleTime.QuadPart = idle;
1566                                 sppi->KernelTime.QuadPart = sys;
1567                                 sppi->UserTime.QuadPart = usr;
1568                             }
1569                             else /* new cpu */
1570                             {
1571                                 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * (cpus+1);
1572                                 sppi = RtlReAllocateHeap(GetProcessHeap(), 0, sppi, len);
1573                                 sppi[cpus].IdleTime.QuadPart = idle;
1574                                 sppi[cpus].KernelTime.QuadPart = sys;
1575                                 sppi[cpus].UserTime.QuadPart = usr;
1576                                 cpus++;
1577                             }
1578                         }
1579                         else
1580                             break;
1581                     } while (out_cpus > 0);
1582                     fclose(cpuinfo);
1583                 }
1584             }
1585 #endif
1586
1587             if (cpus == 0)
1588             {
1589                 static int i = 1;
1590
1591                 sppi = RtlAllocateHeap(GetProcessHeap(),0,sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1592
1593                 memset(sppi, 0 , sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1594                 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
1595
1596                 /* many programs expect these values to change so fake change */
1597                 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1598                 sppi->KernelTime.QuadPart = 1 * i;
1599                 sppi->UserTime.QuadPart = 2 * i;
1600                 sppi->IdleTime.QuadPart = 3 * i;
1601                 i++;
1602             }
1603
1604             if (Length >= len)
1605             {
1606                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1607                 else memcpy( SystemInformation, sppi, len);
1608             }
1609             else ret = STATUS_INFO_LENGTH_MISMATCH;
1610
1611             RtlFreeHeap(GetProcessHeap(),0,sppi);
1612         }
1613         break;
1614     case SystemModuleInformation:
1615         /* FIXME: should be system-wide */
1616         if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1617         else ret = LdrQueryProcessModuleInformation( SystemInformation, Length, &len );
1618         break;
1619     case SystemHandleInformation:
1620         {
1621             SYSTEM_HANDLE_INFORMATION shi;
1622
1623             memset(&shi, 0, sizeof(shi));
1624             len = sizeof(shi);
1625
1626             if ( Length >= len)
1627             {
1628                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1629                 else memcpy( SystemInformation, &shi, len);
1630             }
1631             else ret = STATUS_INFO_LENGTH_MISMATCH;
1632             FIXME("info_class SYSTEM_HANDLE_INFORMATION\n");
1633         }
1634         break;
1635     case SystemCacheInformation:
1636         {
1637             SYSTEM_CACHE_INFORMATION sci;
1638
1639             memset(&sci, 0, sizeof(sci)); /* FIXME */
1640             len = sizeof(sci);
1641
1642             if ( Length >= len)
1643             {
1644                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1645                 else memcpy( SystemInformation, &sci, len);
1646             }
1647             else ret = STATUS_INFO_LENGTH_MISMATCH;
1648             FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
1649         }
1650         break;
1651     case SystemInterruptInformation:
1652         {
1653             SYSTEM_INTERRUPT_INFORMATION sii;
1654
1655             memset(&sii, 0, sizeof(sii));
1656             len = sizeof(sii);
1657
1658             if ( Length >= len)
1659             {
1660                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1661                 else memcpy( SystemInformation, &sii, len);
1662             }
1663             else ret = STATUS_INFO_LENGTH_MISMATCH;
1664             FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
1665         }
1666         break;
1667     case SystemKernelDebuggerInformation:
1668         {
1669             SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
1670
1671             skdi.DebuggerEnabled = FALSE;
1672             skdi.DebuggerNotPresent = TRUE;
1673             len = sizeof(skdi);
1674
1675             if ( Length >= len)
1676             {
1677                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1678                 else memcpy( SystemInformation, &skdi, len);
1679             }
1680             else ret = STATUS_INFO_LENGTH_MISMATCH;
1681         }
1682         break;
1683     case SystemRegistryQuotaInformation:
1684         {
1685             /* Something to do with the size of the registry             *
1686              * Since we don't have a size limitation, fake it            *
1687              * This is almost certainly wrong.                           *
1688              * This sets each of the three words in the struct to 32 MB, *
1689              * which is enough to make the IE 5 installer happy.         */
1690             SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
1691
1692             srqi.RegistryQuotaAllowed = 0x2000000;
1693             srqi.RegistryQuotaUsed = 0x200000;
1694             srqi.Reserved1 = (void*)0x200000;
1695             len = sizeof(srqi);
1696
1697             if ( Length >= len)
1698             {
1699                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1700                 else
1701                 {
1702                     FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
1703                     memcpy( SystemInformation, &srqi, len);
1704                 }
1705             }
1706             else ret = STATUS_INFO_LENGTH_MISMATCH;
1707         }
1708         break;
1709     default:
1710         FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
1711               SystemInformationClass,SystemInformation,Length,ResultLength);
1712
1713         /* Several Information Classes are not implemented on Windows and return 2 different values 
1714          * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
1715          * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
1716         */
1717         ret = STATUS_INVALID_INFO_CLASS;
1718     }
1719
1720     if (ResultLength) *ResultLength = len;
1721
1722     return ret;
1723 }
1724
1725 /******************************************************************************
1726  * NtSetSystemInformation [NTDLL.@]
1727  * ZwSetSystemInformation [NTDLL.@]
1728  */
1729 NTSTATUS WINAPI NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG Length)
1730 {
1731     FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass,SystemInformation,Length);
1732     return STATUS_SUCCESS;
1733 }
1734
1735 /******************************************************************************
1736  *  NtCreatePagingFile          [NTDLL.@]
1737  *  ZwCreatePagingFile          [NTDLL.@]
1738  */
1739 NTSTATUS WINAPI NtCreatePagingFile(
1740         PUNICODE_STRING PageFileName,
1741         PLARGE_INTEGER MinimumSize,
1742         PLARGE_INTEGER MaximumSize,
1743         PLARGE_INTEGER ActualSize)
1744 {
1745     FIXME("(%p %p %p %p) stub\n", PageFileName, MinimumSize, MaximumSize, ActualSize);
1746     return STATUS_SUCCESS;
1747 }
1748
1749 /******************************************************************************
1750  *  NtDisplayString                             [NTDLL.@]
1751  *
1752  * writes a string to the nt-textmode screen eg. during startup
1753  */
1754 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
1755 {
1756     STRING stringA;
1757     NTSTATUS ret;
1758
1759     if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
1760     {
1761         MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
1762         RtlFreeAnsiString( &stringA );
1763     }
1764     return ret;
1765 }
1766
1767 /******************************************************************************
1768  *  NtInitiatePowerAction                       [NTDLL.@]
1769  *
1770  */
1771 NTSTATUS WINAPI NtInitiatePowerAction(
1772         IN POWER_ACTION SystemAction,
1773         IN SYSTEM_POWER_STATE MinSystemState,
1774         IN ULONG Flags,
1775         IN BOOLEAN Asynchronous)
1776 {
1777         FIXME("(%d,%d,0x%08x,%d),stub\n",
1778                 SystemAction,MinSystemState,Flags,Asynchronous);
1779         return STATUS_NOT_IMPLEMENTED;
1780 }
1781         
1782
1783 /******************************************************************************
1784  *  NtPowerInformation                          [NTDLL.@]
1785  *
1786  */
1787 NTSTATUS WINAPI NtPowerInformation(
1788         IN POWER_INFORMATION_LEVEL InformationLevel,
1789         IN PVOID lpInputBuffer,
1790         IN ULONG nInputBufferSize,
1791         IN PVOID lpOutputBuffer,
1792         IN ULONG nOutputBufferSize)
1793 {
1794         TRACE("(%d,%p,%d,%p,%d)\n",
1795                 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
1796         switch(InformationLevel) {
1797                 case SystemPowerCapabilities: {
1798                         PSYSTEM_POWER_CAPABILITIES PowerCaps = lpOutputBuffer;
1799                         FIXME("semi-stub: SystemPowerCapabilities\n");
1800                         if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
1801                                 return STATUS_BUFFER_TOO_SMALL;
1802                         /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
1803                         PowerCaps->PowerButtonPresent = TRUE;
1804                         PowerCaps->SleepButtonPresent = FALSE;
1805                         PowerCaps->LidPresent = FALSE;
1806                         PowerCaps->SystemS1 = TRUE;
1807                         PowerCaps->SystemS2 = FALSE;
1808                         PowerCaps->SystemS3 = FALSE;
1809                         PowerCaps->SystemS4 = TRUE;
1810                         PowerCaps->SystemS5 = TRUE;
1811                         PowerCaps->HiberFilePresent = TRUE;
1812                         PowerCaps->FullWake = TRUE;
1813                         PowerCaps->VideoDimPresent = FALSE;
1814                         PowerCaps->ApmPresent = FALSE;
1815                         PowerCaps->UpsPresent = FALSE;
1816                         PowerCaps->ThermalControl = FALSE;
1817                         PowerCaps->ProcessorThrottle = FALSE;
1818                         PowerCaps->ProcessorMinThrottle = 100;
1819                         PowerCaps->ProcessorMaxThrottle = 100;
1820                         PowerCaps->DiskSpinDown = TRUE;
1821                         PowerCaps->SystemBatteriesPresent = FALSE;
1822                         PowerCaps->BatteriesAreShortTerm = FALSE;
1823                         PowerCaps->BatteryScale[0].Granularity = 0;
1824                         PowerCaps->BatteryScale[0].Capacity = 0;
1825                         PowerCaps->BatteryScale[1].Granularity = 0;
1826                         PowerCaps->BatteryScale[1].Capacity = 0;
1827                         PowerCaps->BatteryScale[2].Granularity = 0;
1828                         PowerCaps->BatteryScale[2].Capacity = 0;
1829                         PowerCaps->AcOnLineWake = PowerSystemUnspecified;
1830                         PowerCaps->SoftLidWake = PowerSystemUnspecified;
1831                         PowerCaps->RtcWake = PowerSystemSleeping1;
1832                         PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
1833                         PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
1834                         return STATUS_SUCCESS;
1835                 }
1836                 case SystemExecutionState: {
1837                         PULONG ExecutionState = lpOutputBuffer;
1838                         WARN("semi-stub: SystemExecutionState\n"); /* Needed for .NET Framework, but using a FIXME is really noisy. */
1839                         if (lpInputBuffer != NULL)
1840                                 return STATUS_INVALID_PARAMETER;
1841                         /* FIXME: The actual state should be the value set by SetThreadExecutionState which is not currently implemented. */
1842                         *ExecutionState = ES_USER_PRESENT;
1843                         return STATUS_SUCCESS;
1844                 }
1845                 case ProcessorInformation: {
1846                         PPROCESSOR_POWER_INFORMATION cpu_power = lpOutputBuffer;
1847
1848                         WARN("semi-stub: ProcessorInformation\n");
1849                         if (nOutputBufferSize < sizeof(PROCESSOR_POWER_INFORMATION))
1850                                 return STATUS_BUFFER_TOO_SMALL;
1851                         cpu_power->Number = NtCurrentTeb()->Peb->NumberOfProcessors;
1852                         cpu_power->MaxMhz = cpuHz / 1000000;
1853                         cpu_power->CurrentMhz = cpuHz / 1000000;
1854                         cpu_power->MhzLimit = cpuHz / 1000000;
1855                         cpu_power->MaxIdleState = 0; /* FIXME */
1856                         cpu_power->CurrentIdleState = 0; /* FIXME */
1857                         return STATUS_SUCCESS;
1858                 }
1859                 default:
1860                         /* FIXME: Needed by .NET Framework */
1861                         WARN("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
1862                         return STATUS_NOT_IMPLEMENTED;
1863         }
1864 }
1865
1866 /******************************************************************************
1867  *  NtShutdownSystem                            [NTDLL.@]
1868  *
1869  */
1870 NTSTATUS WINAPI NtShutdownSystem(SHUTDOWN_ACTION Action)
1871 {
1872     FIXME("%d\n",Action);
1873     return STATUS_SUCCESS;
1874 }
1875
1876 /******************************************************************************
1877  *  NtAllocateLocallyUniqueId (NTDLL.@)
1878  */
1879 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
1880 {
1881     NTSTATUS status;
1882
1883     TRACE("%p\n", Luid);
1884
1885     if (!Luid)
1886         return STATUS_ACCESS_VIOLATION;
1887
1888     SERVER_START_REQ( allocate_locally_unique_id )
1889     {
1890         status = wine_server_call( req );
1891         if (!status)
1892         {
1893             Luid->LowPart = reply->luid.low_part;
1894             Luid->HighPart = reply->luid.high_part;
1895         }
1896     }
1897     SERVER_END_REQ;
1898
1899     return status;
1900 }
1901
1902 /******************************************************************************
1903  *        VerSetConditionMask   (NTDLL.@)
1904  */
1905 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
1906                                       BYTE dwConditionMask)
1907 {
1908     if(dwTypeBitMask == 0)
1909         return dwlConditionMask;
1910     dwConditionMask &= 0x07;
1911     if(dwConditionMask == 0)
1912         return dwlConditionMask;
1913
1914     if(dwTypeBitMask & VER_PRODUCT_TYPE)
1915         dwlConditionMask |= dwConditionMask << 7*3;
1916     else if (dwTypeBitMask & VER_SUITENAME)
1917         dwlConditionMask |= dwConditionMask << 6*3;
1918     else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
1919         dwlConditionMask |= dwConditionMask << 5*3;
1920     else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
1921         dwlConditionMask |= dwConditionMask << 4*3;
1922     else if (dwTypeBitMask & VER_PLATFORMID)
1923         dwlConditionMask |= dwConditionMask << 3*3;
1924     else if (dwTypeBitMask & VER_BUILDNUMBER)
1925         dwlConditionMask |= dwConditionMask << 2*3;
1926     else if (dwTypeBitMask & VER_MAJORVERSION)
1927         dwlConditionMask |= dwConditionMask << 1*3;
1928     else if (dwTypeBitMask & VER_MINORVERSION)
1929         dwlConditionMask |= dwConditionMask << 0*3;
1930     return dwlConditionMask;
1931 }
1932
1933 /******************************************************************************
1934  *  NtAccessCheckAndAuditAlarm   (NTDLL.@)
1935  *  ZwAccessCheckAndAuditAlarm   (NTDLL.@)
1936  */
1937 NTSTATUS WINAPI NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName, HANDLE HandleId, PUNICODE_STRING ObjectTypeName,
1938                                            PUNICODE_STRING ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor,
1939                                            ACCESS_MASK DesiredAccess, PGENERIC_MAPPING GenericMapping, BOOLEAN ObjectCreation,
1940                                            PACCESS_MASK GrantedAccess, PBOOLEAN AccessStatus, PBOOLEAN GenerateOnClose)
1941 {
1942     FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName), HandleId,
1943           debugstr_us(ObjectTypeName), SecurityDescriptor, DesiredAccess, GenericMapping, ObjectCreation,
1944           GrantedAccess, AccessStatus, GenerateOnClose);
1945
1946     return STATUS_NOT_IMPLEMENTED;
1947 }
1948
1949 /******************************************************************************
1950  *  NtSystemDebugControl   (NTDLL.@)
1951  *  ZwSystemDebugControl   (NTDLL.@)
1952  */
1953 NTSTATUS WINAPI NtSystemDebugControl(SYSDBG_COMMAND command, PVOID inbuffer, ULONG inbuflength, PVOID outbuffer,
1954                                      ULONG outbuflength, PULONG retlength)
1955 {
1956     FIXME("(%d, %p, %d, %p, %d, %p), stub\n", command, inbuffer, inbuflength, outbuffer, outbuflength, retlength);
1957
1958     return STATUS_NOT_IMPLEMENTED;
1959 }