--- /dev/null
- <include>include/crt</include>
- <include>include/crt/mingw32</include>
+<?xml version="1.0"?>
+<!DOCTYPE group SYSTEM "tools/rbuild/project.dtd">
+<group xmlns:xi="http://www.w3.org/2001/XInclude">
+ <xi:include href="baseaddress.rbuild" />
+
+ <define name="__REACTOS__" />
+ <if property="DBG" value="1">
+ <define name="DBG">1</define>
+ <define name="_SEH_ENABLE_TRACE" />
+ <property name="DBG_OR_KDBG" value="true" />
+ </if>
+ <if property="KDBG" value="1">
+ <define name="KDBG">1</define>
+ <property name="DBG_OR_KDBG" value="true" />
+ </if>
+
+ <!-- The version target valid values are: Nt4 , NT5 , NT51 -->
+ <property name="VERSION_TARGET" value="NT52" />
+
+ <if property="VERSION_TARGET" value="NT4">
+ <define name="WINVER" overridable="true">0x400</define>
+ <define name="_WIN32_IE">0x600</define>
+ <define name="_WIN32_WINNT" overridable="true">0x400</define>
+ <define name="_WIN32_WINDOWS">0x400</define>
+ <define name="_SETUPAPI_VER">0x400</define>
+ </if>
+
+ <if property="VERSION_TARGET" value="NT5">
+ <define name="WINVER" overridable="true">0x500</define>
+ <define name="_WIN32_IE">0x600</define>
+ <define name="_WIN32_WINNT" overridable="true">0x500</define>
+ <define name="_WIN32_WINDOWS">0x500</define>
+ <define name="_SETUPAPI_VER">0x500</define>
+ </if>
+
+ <if property="VERSION_TARGET" value="NT51">
+ <define name="WINVER" overridable="true">0x501</define>
+ <define name="_WIN32_IE">0x600</define>
+ <define name="_WIN32_WINNT" overridable="true">0x501</define>
+ <define name="_WIN32_WINDOWS">0x501</define>
+ <define name="_SETUPAPI_VER">0x501</define>
+ </if>
+
+ <if property="VERSION_TARGET" value="NT52">
+ <define name="WINVER" overridable="true">0x502</define>
+ <define name="_WIN32_IE">0x600</define>
+ <define name="_WIN32_WINNT" overridable="true">0x502</define>
+ <define name="_WIN32_WINDOWS">0x502</define>
+ <define name="_SETUPAPI_VER">0x502</define>
+ </if>
+
+ <if property="VERSION_TARGET" value="NT6">
+ <define name="WINVER" overridable="true">0x600</define>
+ <define name="_WIN32_IE">0x600</define>
+ <define name="_WIN32_WINNT" overridable="true">0x600</define>
+ <define name="_WIN32_WINDOWS">0x600</define>
+ <define name="_SETUPAPI_VER">0x600</define>
+ </if>
+
+ <include>.</include>
+ <include>include</include>
+ <include root="intermediate">include</include>
+ <include>include/psdk</include>
+ <include root="intermediate">include/psdk</include>
+ <include>include/dxsdk</include>
+ <include root="intermediate">include/dxsdk</include>
++ <!--<include>include/crt</include>-->
++ <!--<include>include/crt/mingw32</include>-->
+ <include>include/ddk</include>
+ <include>include/GL</include>
+ <include>include/ndk</include>
+ <include>include/reactos</include>
+ <include root="intermediate">include/reactos</include>
+ <include root="intermediate">include/reactos/mc</include>
+ <include>include/reactos/libs</include>
+
+ <directory name="base">
+ <xi:include href="base/base.rbuild" />
+ </directory>
+ <directory name="boot">
+ <xi:include href="boot/boot.rbuild" />
+ </directory>
+ <directory name="dll">
+ <xi:include href="dll/dll.rbuild" />
+ </directory>
+ <directory name="drivers">
+ <xi:include href="drivers/drivers.rbuild" />
+ </directory>
+ <directory name="hal">
+ <xi:include href="hal/hal.rbuild" />
+ </directory>
+ <directory name="include">
+ <xi:include href="include/directory.rbuild" />
+ </directory>
+ <directory name="lib">
+ <xi:include href="lib/lib.rbuild" />
+ </directory>
+ <directory name="media">
+ <xi:include href="media/media.rbuild" />
+ </directory>
+ <directory name="modules">
+ <xi:include href="modules/directory.rbuild" />
+ </directory>
+ <directory name="ntoskrnl">
+ <xi:include href="ntoskrnl/ntoskrnl.rbuild" />
+ <!-- <xi:include href="ntoskrnl/ntkrnlmp.rbuild" /> -->
+ </directory>
+ <directory name="subsystems">
+ <xi:include href="subsystems/subsystems.rbuild" />
+ </directory>
+ <directory name="tools">
+ <xi:include href="tools/tools.rbuild" />
+ </directory>
+
+</group>
--- /dev/null
- <compilerflag>-Os</compilerflag>
+<?xml version="1.0"?>
+<!DOCTYPE project SYSTEM "tools/rbuild/project.dtd">
+<project name="ReactOS" makefile="makefile.auto" xmlns:xi="http://www.w3.org/2001/XInclude">
+ <xi:include href="config.rbuild">
+ <xi:fallback>
+ <xi:include href="config.template.rbuild" />
+ </xi:fallback>
+ </xi:include>
+
+ <xi:include href="ReactOS-generic.rbuild" />
+
+ <define name="_M_IX86" />
+ <define name="_X86_" />
+ <define name="__i386__" />
+
+ <property name="NTOSKRNL_SHARED" value="-file-alignment=0x1000 -section-alignment=0x1000 -shared"/>
+
+ <if property="OPTIMIZE" value="1">
++ <!--
+ <compilerflag>-Os</compilerflag>
+ <compilerflag>-ftracer</compilerflag>
+ <compilerflag>-momit-leaf-frame-pointer</compilerflag>
++ -->
++ <compilerflag>-O1</compilerflag>
+ </if>
+ <if property="OPTIMIZE" value="2">
- <compilerflag>-O1</compilerflag>
++ <!--<compilerflag>-Os</compilerflag>-->
++ <compilerflag>-O2</compilerflag>
+ </if>
+ <if property="OPTIMIZE" value="3">
- <compilerflag>-O2</compilerflag>
++ <!--<compilerflag>-O1</compilerflag>-->
++ <compilerflag>-Ox</compilerflag>
++ <compilerflag>-Os</compilerflag>
+ </if>
+ <if property="OPTIMIZE" value="4">
- <compilerflag>-O3</compilerflag>
++ <!--<compilerflag>-O2</compilerflag>-->
++ <compilerflag>-Ox</compilerflag>
++ <compilerflag>-Os</compilerflag>
+ </if>
+ <if property="OPTIMIZE" value="5">
++ <!--<compilerflag>-O3</compilerflag>-->
++ <compilerflag>-Ox</compilerflag>
++ <compilerflag>-Os</compilerflag>
+ </if>
+
++ <!--
+ <compilerflag>-mpreferred-stack-boundary=2</compilerflag>
+ <compilerflag>-fno-strict-aliasing</compilerflag>
+ <compilerflag>-Wno-strict-aliasing</compilerflag>
+ <compilerflag>-Wpointer-arith</compilerflag>
++ -->
++ <compilerflag>-Oy-</compilerflag>
++ <compilerflag>-GS-</compilerflag>
+ <linkerflag>-disable-stdcall-fixup</linkerflag>
+
+</project>
--- /dev/null
- #include <initguid.h>
+/*
+ * ReactOS Access Control List Editor
+ * Copyright (C) 2004-2005 ReactOS Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* DO NOT USE THE PRECOMPILED HEADER FOR THIS FILE! */
+
+#include <windows.h>
++
++#include <initguid.h>
++#include <objbase.h>
++
+#include <aclui.h>
+#include <objsel.h>
+
+#ifdef _MSC_VER
+#include <precomp.h>
+#endif
+
+/* NO CODE HERE, THIS IS JUST REQUIRED FOR THE GUID DEFINITIONS */
--- /dev/null
- #include <oleauto.h>
+#define WIN32_NO_STATUS
+#define NTOS_MODE_USER
+#define _ACLUI_
+#include <windows.h>
+#include <ndk/ntndk.h>
+#include <commctrl.h>
++#include <ole2.h>
+#include <objsel.h>
+#include <prsht.h>
+#include <aclui.h>
+#include <sddl.h>
+#include <ntsecapi.h>
+#ifdef SUPPORT_UXTHEME
+#include <uxtheme.h>
+#include <tmschema.h>
+#endif
+#include "resource.h"
+
+#define EnableRedrawWindow(hwnd) \
+ SendMessage((hwnd), WM_SETREDRAW, TRUE, 0)
+
+#define DisableRedrawWindow(hwnd) \
+ SendMessage((hwnd), WM_SETREDRAW, FALSE, 0)
+
+extern HINSTANCE hDllInstance;
+
+typedef struct _ACE_ENTRY
+{
+ struct _ACE_ENTRY *Next;
+} ACE_ENTRY, *PACE_ENTRY;
+
+typedef struct _PRINCIPAL_LISTITEM
+{
+ struct _PRINCIPAL_LISTITEM *Next;
+ struct _SIDREQRESULT *SidReqResult;
+ PACE_ENTRY ACEs;
+ LPWSTR DisplayString;
+} PRINCIPAL_LISTITEM, *PPRINCIPAL_LISTITEM;
+
+typedef struct _SECURITY_PAGE
+{
+ HWND hWnd;
+ HWND hBtnAdd;
+ HWND hBtnRemove;
+ HWND hBtnAdvanced;
+ HWND hAceCheckList;
+ HWND hPermissionsForLabel;
+
+ /* Main Principals List */
+ HWND hWndPrincipalsList;
+ PPRINCIPAL_LISTITEM PrincipalsListHead;
+
+ PSID OwnerSid;
+ BOOL OwnerDefaulted;
+
+ INT ControlsMargin;
+
+ INT SpecialPermCheckIndex;
+
+ HIMAGELIST hiPrincipals;
+
+ LPSECURITYINFO psi;
+ SI_OBJECT_INFO ObjectInfo;
+ IDsObjectPicker *pDsObjectPicker;
+
+ SI_ACCESS DefaultAccess;
+
+ HANDLE SidCacheMgr;
+ LONG SidLookupsPending;
+ UINT Initializing : 1;
+
+ LPCWSTR ServerName;
+} SECURITY_PAGE, *PSECURITY_PAGE;
+
+/* MISC ***********************************************************************/
+
+DWORD
+LoadAndFormatString(IN HINSTANCE hInstance,
+ IN UINT uID,
+ OUT LPWSTR *lpTarget,
+ ...);
+
+LPARAM
+ListViewGetSelectedItemData(IN HWND hwnd);
+
+BOOL
+ListViewSelectItem(IN HWND hwnd,
+ IN INT Index);
+
+HRESULT
+InitializeObjectPicker(IN PCWSTR ServerName,
+ IN PSI_OBJECT_INFO ObjectInfo,
+ OUT IDsObjectPicker **pDsObjectPicker);
+
+VOID
+FreeObjectPicker(IN IDsObjectPicker *pDsObjectPicker);
+
+typedef BOOL (*POBJPICK_SELECTED_SID)(IN IDsObjectPicker *pDsObjectPicker,
+ IN HWND hwndParent OPTIONAL,
+ IN PSID pSid,
+ IN PVOID Context OPTIONAL);
+
+HRESULT
+InvokeObjectPickerDialog(IN IDsObjectPicker *pDsObjectPicker,
+ IN HWND hwndParent OPTIONAL,
+ IN POBJPICK_SELECTED_SID SelectedSidCallback,
+ IN PVOID Context OPTIONAL);
+
+/* CHECKLIST CONTROL **********************************************************/
+
+#define CIS_DENYDISABLED (0x8)
+#define CIS_DENYENABLED (0x0)
+#define CIS_ALLOWDISABLED (0x4)
+#define CIS_ALLOWENABLED (0x0)
+#define CIS_ALLOW (0x2)
+#define CIS_DENY (0x1)
+#define CIS_NONE (0x0)
+#define CIS_DISABLED (CIS_ALLOWDISABLED | CIS_DENYDISABLED)
+
+#define CLB_ALLOW (0x1)
+#define CLB_DENY (0x0)
+
+#define CIS_MASK (CIS_DISABLED | CIS_ALLOW | CIS_DENY)
+
+#define CLM_ADDITEM (WM_USER + 1)
+#define CLM_DELITEM (WM_USER + 2)
+#define CLM_GETITEMCOUNT (WM_USER + 3)
+#define CLM_CLEAR (WM_USER + 4)
+#define CLM_SETCHECKBOXCOLUMN (WM_USER + 5)
+#define CLM_GETCHECKBOXCOLUMN (WM_USER + 6)
+#define CLM_CLEARCHECKBOXES (WM_USER + 7)
+#define CLM_SETITEMSTATE (WM_USER + 8)
+#define CLM_ENABLEQUICKSEARCH (WM_USER + 9)
+#define CLM_SETQUICKSEARCH_TIMEOUT_RESET (WM_USER + 10)
+#define CLM_SETQUICKSEARCH_TIMEOUT_SETFOCUS (WM_USER + 11)
+#define CLM_FINDITEMBYACCESSMASK (WM_USER + 12)
+
+#define CLN_CHANGINGITEMCHECKBOX (101)
+
+typedef struct _NMCHANGEITEMCHECKBOX
+{
+ NMHDR nmhdr;
+ DWORD OldState;
+ DWORD NewState;
+ DWORD CheckBox;
+ BOOL Checked;
+} NMCHANGEITEMCHECKBOX, *PNMCHANGEITEMCHECKBOX;
+
+BOOL
+RegisterCheckListControl(HINSTANCE hInstance);
+
+VOID
+UnregisterCheckListControl(HINSTANCE hInstance);
+
+/* DLLMAIN ********************************************************************/
+
+BOOL
+WINAPI
+DllMain(IN HINSTANCE hinstDLL,
+ IN DWORD dwReason,
+ IN LPVOID lpvReserved);
+
+/* SIDCACHE *******************************************************************/
+
+typedef struct _SIDREQRESULT
+{
+ LONG RefCount;
+ SID_NAME_USE SidNameUse;
+ LPWSTR AccountName;
+ LPWSTR DomainName;
+} SIDREQRESULT, *PSIDREQRESULT;
+
+typedef VOID (*PSIDREQCOMPLETIONPROC)(IN HANDLE SidCacheMgr,
+ IN PSID Sid,
+ IN PSIDREQRESULT SidRequestResult,
+ IN PVOID Context);
+
+HANDLE
+CreateSidCacheMgr(IN HANDLE Heap,
+ IN LPCWSTR SystemName);
+
+VOID
+DestroySidCacheMgr(IN HANDLE SidCacheMgr);
+
+VOID
+DequeueSidLookup(IN HANDLE SidCacheMgr,
+ IN PSID pSid);
+
+BOOL
+LookupSidCache(IN HANDLE SidCacheMgr,
+ IN PSID pSid,
+ IN PSIDREQCOMPLETIONPROC CompletionProc,
+ IN PVOID Context);
+
+VOID
+ReferenceSidReqResult(IN HANDLE SidCacheMgr,
+ IN PSIDREQRESULT ReqResult);
+
+VOID
+DereferenceSidReqResult(IN HANDLE SidCacheMgr,
+ IN PSIDREQRESULT ReqResult);
+
+/* EOF */
--- /dev/null
- LsaSystemName.Length = wcslen(SystemName) * sizeof(WCHAR);
+/*
+ * ReactOS Access Control List Editor
+ * Copyright (C) 2004-2005 ReactOS Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+/* $Id: aclui.c 19715 2005-11-28 01:10:49Z weiden $
+ *
+ * PROJECT: ReactOS Access Control List Editor
+ * FILE: lib/aclui/sidcache.c
+ * PURPOSE: Access Control List Editor
+ * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
+ *
+ * UPDATE HISTORY:
+ * 12/10/2005 Created
+ */
+#include <precomp.h>
+
+#define NDEBUG
+#include <debug.h>
+
+#define HandleToScm(Handle) (PSIDCACHEMGR)(Handle)
+#define ScmToHandle(Scm) (HANDLE)(Scm)
+
+typedef struct _SIDCACHEMGR
+{
+ volatile LONG RefCount;
+ LSA_HANDLE LsaHandle;
+ CRITICAL_SECTION Lock;
+ LIST_ENTRY QueueListHead;
+ struct _SIDQUEUEENTRY *QueueLookingUp;
+ LIST_ENTRY CacheListHead;
+ HANDLE Heap;
+ HANDLE LookupEvent;
+ HANDLE LookupThread;
+ WCHAR SystemName[1];
+} SIDCACHEMGR, *PSIDCACHEMGR;
+
+
+typedef struct _SIDCACHECALLBACKINFO
+{
+ PSIDREQCOMPLETIONPROC CompletionProc;
+ PVOID Context;
+} SIDCACHECALLBACKINFO, *PSIDCACHECALLBACKINFO;
+
+
+typedef struct _SIDQUEUEENTRY
+{
+ LIST_ENTRY ListEntry;
+ ULONG CallbackCount;
+ PSIDCACHECALLBACKINFO Callbacks;
+ /* the SID is appended to this structure */
+} SIDQUEUEENTRY, *PSIDQUEUEENTRY;
+
+
+typedef struct _SIDCACHEENTRY
+{
+ LIST_ENTRY ListEntry;
+ SID_NAME_USE SidNameUse;
+ PWSTR AccountName;
+ PWSTR DomainName;
+ /* the SID and strings are appended to this structure */
+} SIDCACHEENTRY, *PSIDCACHEENTRY;
+
+
+static VOID
+FreeQueueEntry(IN PSIDCACHEMGR scm,
+ IN PSIDQUEUEENTRY QueueEntry)
+{
+ if (QueueEntry->ListEntry.Flink != NULL)
+ {
+ RemoveEntryList(&QueueEntry->ListEntry);
+ }
+
+ HeapFree(scm->Heap,
+ 0,
+ QueueEntry->Callbacks);
+
+ HeapFree(scm->Heap,
+ 0,
+ QueueEntry);
+}
+
+
+static VOID
+FreeCacheEntry(IN PSIDCACHEMGR scm,
+ IN PSIDCACHEENTRY CacheEntry)
+{
+ RemoveEntryList(&CacheEntry->ListEntry);
+
+ HeapFree(scm->Heap,
+ 0,
+ CacheEntry);
+}
+
+
+static VOID
+CleanupSidCacheMgr(IN PSIDCACHEMGR scm)
+{
+ LsaClose(scm->LsaHandle);
+ CloseHandle(scm->LookupEvent);
+ CloseHandle(scm->LookupThread);
+
+ /* delete the queue */
+ while (!IsListEmpty(&scm->QueueListHead))
+ {
+ PSIDQUEUEENTRY QueueEntry;
+
+ QueueEntry = CONTAINING_RECORD(scm->QueueListHead.Flink,
+ SIDQUEUEENTRY,
+ ListEntry);
+ FreeQueueEntry(scm,
+ QueueEntry);
+ }
+
+ /* delete the cache */
+ while (!IsListEmpty(&scm->CacheListHead))
+ {
+ PSIDCACHEENTRY CacheEntry;
+
+ CacheEntry = CONTAINING_RECORD(scm->CacheListHead.Flink,
+ SIDCACHEENTRY,
+ ListEntry);
+ FreeCacheEntry(scm,
+ CacheEntry);
+ }
+
+ DeleteCriticalSection(&scm->Lock);
+}
+
+
+static PSIDCACHEMGR
+ReferenceSidCacheMgr(IN HANDLE SidCacheMgr)
+{
+ PSIDCACHEMGR scm = HandleToScm(SidCacheMgr);
+
+ if (InterlockedIncrement(&scm->RefCount) != 1)
+ {
+ return scm;
+ }
+
+ return NULL;
+}
+
+
+static VOID
+DereferenceSidCacheMgr(IN PSIDCACHEMGR scm)
+{
+ if (InterlockedDecrement(&scm->RefCount) == 0)
+ {
+ /* Signal the lookup thread so it can terminate */
+ SetEvent(scm->LookupEvent);
+ }
+}
+
+
+static BOOL
+OpenLSAPolicyHandle(IN LPWSTR SystemName,
+ IN ACCESS_MASK DesiredAccess,
+ OUT PLSA_HANDLE PolicyHandle)
+{
+ LSA_OBJECT_ATTRIBUTES LsaObjectAttributes = {0};
+ LSA_UNICODE_STRING LsaSystemName, *psn;
+ NTSTATUS Status;
+
+ if (SystemName != NULL && SystemName[0] != L'\0')
+ {
+ LsaSystemName.Buffer = SystemName;
++ LsaSystemName.Length = (USHORT)(wcslen(SystemName) * sizeof(WCHAR)); /* FIXME: possible overflow */
+ LsaSystemName.MaximumLength = LsaSystemName.Length + sizeof(WCHAR);
+ psn = &LsaSystemName;
+ }
+ else
+ {
+ psn = NULL;
+ }
+
+ Status = LsaOpenPolicy(psn,
+ &LsaObjectAttributes,
+ DesiredAccess,
+ PolicyHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastError(LsaNtStatusToWinError(Status));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+static BOOL
+LookupSidInformation(IN PSIDCACHEMGR scm,
+ IN PSID pSid,
+ OUT PSIDREQRESULT *ReqResult)
+{
+ PLSA_REFERENCED_DOMAIN_LIST ReferencedDomain;
+ PLSA_TRANSLATED_NAME Names;
+ PLSA_TRUST_INFORMATION Domain;
+ PLSA_UNICODE_STRING DomainName;
+ SID_NAME_USE SidNameUse = SidTypeUnknown;
+ PPOLICY_ACCOUNT_DOMAIN_INFO PolicyAccountDomainInfo = NULL;
+ NTSTATUS Status;
+ DWORD SidLength, AccountNameSize, DomainNameSize = 0;
+ PSIDREQRESULT ReqRet = NULL;
+ BOOL Ret = FALSE;
+
+ Status = LsaLookupSids(scm->LsaHandle,
+ 1,
+ &pSid,
+ &ReferencedDomain,
+ &Names);
+ if (NT_SUCCESS(Status))
+ {
+ SidLength = GetLengthSid(pSid);
+ SidNameUse = Names->Use;
+
+ if (ReferencedDomain != NULL &&
+ Names->DomainIndex >= 0)
+ {
+ Domain = &ReferencedDomain->Domains[Names->DomainIndex];
+ DomainName = &Domain->Name;
+ }
+ else
+ {
+ Domain = NULL;
+ DomainName = NULL;
+ }
+
+ switch (SidNameUse)
+ {
+ case SidTypeAlias:
+ {
+ if (Domain != NULL)
+ {
+ /* query the domain name for BUILTIN accounts */
+ Status = LsaQueryInformationPolicy(scm->LsaHandle,
+ PolicyAccountDomainInformation,
+ (PVOID*)&PolicyAccountDomainInfo);
+ if (NT_SUCCESS(Status))
+ {
+ DomainName = &PolicyAccountDomainInfo->DomainName;
+
+ /* make the user believe this is a group */
+ SidNameUse = (PolicyAccountDomainInfo != NULL ? SidTypeGroup : SidTypeUser);
+ }
+ }
+ break;
+ }
+
+ default:
+ {
+ DPRINT("Unhandled SID type: 0x%x\n", Names->Use);
+ break;
+ }
+ }
+
+ AccountNameSize = Names->Name.Length;
+ if (DomainName != NULL)
+ {
+ DomainNameSize = DomainName->Length;
+ }
+
+ ReqRet = HeapAlloc(scm->Heap,
+ 0,
+ sizeof(SIDREQRESULT) +
+ (((AccountNameSize + DomainNameSize) + 2) * sizeof(WCHAR)));
+ if (ReqRet != NULL)
+ {
+ ReqRet->RefCount = 1;
+ ReqRet->AccountName = (LPWSTR)(ReqRet + 1);
+ ReqRet->DomainName = ReqRet->AccountName + (AccountNameSize / sizeof(WCHAR)) + 1;
+
+ CopyMemory(ReqRet->AccountName,
+ Names->Name.Buffer,
+ Names->Name.Length);
+
+ if (DomainName != NULL)
+ {
+ CopyMemory(ReqRet->DomainName,
+ DomainName->Buffer,
+ DomainName->Length);
+ }
+
+ ReqRet->AccountName[AccountNameSize / sizeof(WCHAR)] = L'\0';
+ ReqRet->DomainName[DomainNameSize / sizeof(WCHAR)] = L'\0';
+
+ ReqRet->SidNameUse = SidNameUse;
+ }
+
+ if (PolicyAccountDomainInfo != NULL)
+ {
+ LsaFreeMemory(PolicyAccountDomainInfo);
+ }
+
+ LsaFreeMemory(ReferencedDomain);
+ LsaFreeMemory(Names);
+
+ Ret = TRUE;
+ }
+ else if (Status == STATUS_NONE_MAPPED)
+ {
+ Ret = TRUE;
+ }
+
+ if (Ret)
+ {
+ *ReqResult = ReqRet;
+ }
+
+ return Ret;
+}
+
+
+static BOOL
+FindSidInCache(IN PSIDCACHEMGR scm,
+ IN PSID pSid,
+ OUT PSIDREQRESULT *ReqResult)
+{
+ PSIDCACHEENTRY CacheEntry;
+ PLIST_ENTRY CurrentEntry;
+ PSIDREQRESULT ReqRes;
+ BOOL Ret = FALSE;
+
+ /* NOTE: assumes the lists are locked! */
+
+ CurrentEntry = &scm->CacheListHead;
+ while (CurrentEntry != &scm->CacheListHead)
+ {
+ CacheEntry = CONTAINING_RECORD(CurrentEntry,
+ SIDCACHEENTRY,
+ ListEntry);
+
+ if (EqualSid(pSid,
+ (PSID)(CacheEntry + 1)))
+ {
+ SIZE_T ReqResultSize;
+ ULONG AccountNameLen, DomainNameLen;
+
+ Ret = TRUE;
+
+ AccountNameLen = wcslen(CacheEntry->AccountName);
+ DomainNameLen = wcslen(CacheEntry->DomainName);
+
+ ReqResultSize = sizeof(SIDREQRESULT) +
+ (((AccountNameLen + 1) +
+ (DomainNameLen + 1)) * sizeof(WCHAR));
+
+ ReqRes = HeapAlloc(scm->Heap,
+ 0,
+ ReqResultSize);
+ if (ReqRes != NULL)
+ {
+ PWSTR Buffer = (PWSTR)(ReqRes + 1);
+
+ ReqRes->RefCount = 1;
+
+ ReqRes->AccountName = Buffer;
+ wcscpy(ReqRes->AccountName,
+ CacheEntry->AccountName);
+ Buffer += AccountNameLen + 1;
+
+ ReqRes->DomainName = Buffer;
+ wcscpy(ReqRes->DomainName,
+ CacheEntry->DomainName);
+ }
+
+ /* return the result, even if we weren't unable to
+ allocate enough memory! */
+ *ReqResult = ReqRes;
+ break;
+ }
+
+ CurrentEntry = CurrentEntry->Flink;
+ }
+
+ return Ret;
+}
+
+
+static VOID
+CacheLookupResults(IN PSIDCACHEMGR scm,
+ IN PSID pSid,
+ IN PSIDREQRESULT ReqResult)
+{
+ PSIDCACHEENTRY CacheEntry;
+ DWORD SidLen;
+ SIZE_T AccountNameLen = 0;
+ SIZE_T DomainNameLen = 0;
+ SIZE_T CacheEntrySize = sizeof(SIDCACHEENTRY);
+
+ /* NOTE: assumes the lists are locked! */
+
+ SidLen = GetLengthSid(pSid);
+ CacheEntrySize += SidLen;
+
+ AccountNameLen = wcslen(ReqResult->AccountName);
+ CacheEntrySize += (AccountNameLen + 1) * sizeof(WCHAR);
+
+ DomainNameLen = wcslen(ReqResult->DomainName);
+ CacheEntrySize += (wcslen(ReqResult->DomainName) + 1) * sizeof(WCHAR);
+
+ CacheEntry = HeapAlloc(scm->Heap,
+ 0,
+ CacheEntrySize);
+ if (CacheEntry != NULL)
+ {
+ PWSTR lpBuf = (PWSTR)((ULONG_PTR)(CacheEntry + 1) + SidLen);
+
+ CacheEntry->SidNameUse = ReqResult->SidNameUse;
+
+ /* append the SID */
+ CopySid(SidLen,
+ (PSID)(CacheEntry + 1),
+ pSid);
+
+ /* append the strings */
+ CacheEntry->AccountName = lpBuf;
+ wcscpy(lpBuf,
+ ReqResult->AccountName);
+ lpBuf += AccountNameLen + 1;
+
+ CacheEntry->DomainName = lpBuf;
+ wcscpy(lpBuf,
+ ReqResult->DomainName);
+ lpBuf += DomainNameLen + 1;
+
+ /* add the entry to the cache list */
+ InsertTailList(&scm->CacheListHead,
+ &CacheEntry->ListEntry);
+ }
+}
+
+
+static DWORD WINAPI
+LookupThreadProc(IN LPVOID lpParameter)
+{
+ HMODULE hModule;
+ PSIDCACHEMGR scm = (PSIDCACHEMGR)lpParameter;
+
+ /* Reference the dll to avoid problems in case of accidental
+ FreeLibrary calls... */
+ if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
+ (LPCWSTR)hDllInstance,
+ &hModule))
+ {
+ hModule = NULL;
+ }
+
+ while (scm->RefCount != 0)
+ {
+ PSIDQUEUEENTRY QueueEntry = NULL;
+
+ EnterCriticalSection(&scm->Lock);
+
+ /* get the first item of the queue */
+ if (scm->QueueListHead.Flink != &scm->QueueListHead)
+ {
+ QueueEntry = CONTAINING_RECORD(scm->QueueListHead.Flink,
+ SIDQUEUEENTRY,
+ ListEntry);
+ RemoveEntryList(&QueueEntry->ListEntry);
+ QueueEntry->ListEntry.Flink = NULL;
+ }
+ else
+ {
+ LeaveCriticalSection(&scm->Lock);
+
+ /* wait for the next asynchronous lookup queued */
+ WaitForSingleObject(scm->LookupEvent,
+ INFINITE);
+ continue;
+ }
+
+ scm->QueueLookingUp = QueueEntry;
+
+ LeaveCriticalSection(&scm->Lock);
+
+ if (QueueEntry != NULL)
+ {
+ PSIDREQRESULT ReqResult, FoundReqResult;
+ PSID pSid = (PSID)(QueueEntry + 1);
+
+ /* lookup the SID information */
+ if (!LookupSidInformation(scm,
+ pSid,
+ &ReqResult))
+ {
+ ReqResult = NULL;
+ }
+
+ EnterCriticalSection(&scm->Lock);
+
+ /* see if the SID was added to the cache in the meanwhile */
+ if (!FindSidInCache(scm,
+ pSid,
+ &FoundReqResult))
+ {
+ if (ReqResult != NULL)
+ {
+ /* cache the results */
+ CacheLookupResults(scm,
+ pSid,
+ ReqResult);
+ }
+ }
+ else
+ {
+ if (ReqResult != NULL)
+ {
+ /* free the information of our lookup and use the cached
+ information*/
+ DereferenceSidReqResult(scm,
+ ReqResult);
+ }
+
+ ReqResult = FoundReqResult;
+ }
+
+ /* notify the callers unless the lookup was cancelled */
+ if (scm->QueueLookingUp != NULL)
+ {
+ ULONG i = 0;
+
+ while (scm->QueueLookingUp != NULL &&
+ i < QueueEntry->CallbackCount)
+ {
+ PVOID Context;
+ PSIDREQCOMPLETIONPROC CompletionProc;
+
+ Context = QueueEntry->Callbacks[i].Context;
+ CompletionProc = QueueEntry->Callbacks[i].CompletionProc;
+
+ LeaveCriticalSection(&scm->Lock);
+
+ /* call the completion proc without holding the lock! */
+ CompletionProc(ScmToHandle(scm),
+ pSid,
+ ReqResult,
+ Context);
+
+ EnterCriticalSection(&scm->Lock);
+
+ i++;
+ }
+
+ scm->QueueLookingUp = NULL;
+ }
+
+ LeaveCriticalSection(&scm->Lock);
+
+ /* free the queue item */
+ FreeQueueEntry(scm,
+ QueueEntry);
+ }
+ }
+
+ CleanupSidCacheMgr(scm);
+
+ HeapFree(scm->Heap,
+ 0,
+ scm);
+
+ if (hModule != NULL)
+ {
+ /* dereference the library and exit */
+ FreeLibraryAndExitThread(hModule,
+ 0);
+ }
+
+ return 0;
+}
+
+
+
+HANDLE
+CreateSidCacheMgr(IN HANDLE Heap,
+ IN LPCWSTR SystemName)
+{
+ PSIDCACHEMGR scm;
+
+ if (SystemName == NULL)
+ SystemName = L"";
+
+ scm = HeapAlloc(Heap,
+ 0,
+ FIELD_OFFSET(SIDCACHEMGR,
+ SystemName[wcslen(SystemName) + 1]));
+ if (scm != NULL)
+ {
+ /* zero the static part of the structure */
+ ZeroMemory(scm,
+ FIELD_OFFSET(SIDCACHEMGR,
+ SystemName));
+
+ scm->RefCount = 1;
+ scm->Heap = Heap;
+
+ wcscpy(scm->SystemName,
+ SystemName);
+
+ InitializeCriticalSection(&scm->Lock);
+ InitializeListHead(&scm->QueueListHead);
+ InitializeListHead(&scm->CacheListHead);
+
+ scm->LookupEvent = CreateEvent(NULL,
+ FALSE,
+ FALSE,
+ NULL);
+ if (scm->LookupEvent == NULL)
+ {
+ goto Cleanup;
+ }
+
+ if (!OpenLSAPolicyHandle(scm->SystemName,
+ POLICY_LOOKUP_NAMES | POLICY_VIEW_LOCAL_INFORMATION,
+ &scm->LsaHandle))
+ {
+ goto Cleanup;
+ }
+
+ scm->LookupThread = CreateThread(NULL,
+ 0,
+ LookupThreadProc,
+ scm,
+ 0,
+ NULL);
+ if (scm->LookupThread == NULL)
+ {
+Cleanup:
+ if (scm->LookupEvent != NULL)
+ {
+ CloseHandle(scm->LookupEvent);
+ }
+
+ if (scm->LsaHandle != NULL)
+ {
+ LsaClose(scm->LsaHandle);
+ }
+
+ HeapFree(Heap,
+ 0,
+ scm);
+ scm = NULL;
+ }
+ }
+ else
+ {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ }
+
+ return (HANDLE)scm;
+}
+
+
+VOID
+DestroySidCacheMgr(IN HANDLE SidCacheMgr)
+{
+ PSIDCACHEMGR scm = HandleToScm(SidCacheMgr);
+
+ if (scm != NULL)
+ {
+ /* remove the keep-alive reference */
+ DereferenceSidCacheMgr(scm);
+ }
+}
+
+
+static BOOL
+QueueSidLookup(IN PSIDCACHEMGR scm,
+ IN PSID pSid,
+ IN PSIDREQCOMPLETIONPROC CompletionProc,
+ IN PVOID Context)
+{
+ PLIST_ENTRY CurrentEntry;
+ PSIDQUEUEENTRY QueueEntry, FoundEntry = NULL;
+ BOOL Ret = FALSE;
+
+ /* NOTE: assumes the lists are locked! */
+
+ if (scm->QueueLookingUp != NULL &&
+ EqualSid(pSid,
+ (PSID)(scm->QueueLookingUp + 1)))
+ {
+ FoundEntry = scm->QueueLookingUp;
+ }
+ else
+ {
+ CurrentEntry = &scm->QueueListHead;
+ while (CurrentEntry != &scm->QueueListHead)
+ {
+ QueueEntry = CONTAINING_RECORD(CurrentEntry,
+ SIDQUEUEENTRY,
+ ListEntry);
+
+ if (EqualSid(pSid,
+ (PSID)(QueueEntry + 1)))
+ {
+ FoundEntry = QueueEntry;
+ break;
+ }
+
+ CurrentEntry = CurrentEntry->Flink;
+ }
+ }
+
+ if (FoundEntry == NULL)
+ {
+ DWORD SidLength = GetLengthSid(pSid);
+
+ FoundEntry = HeapAlloc(scm->Heap,
+ 0,
+ sizeof(SIDQUEUEENTRY) + SidLength);
+ if (FoundEntry != NULL)
+ {
+ CopySid(SidLength,
+ (PSID)(FoundEntry + 1),
+ pSid);
+
+ FoundEntry->CallbackCount = 1;
+ FoundEntry->Callbacks = HeapAlloc(scm->Heap,
+ 0,
+ sizeof(SIDCACHECALLBACKINFO));
+
+ if (FoundEntry->Callbacks != NULL)
+ {
+ FoundEntry->Callbacks[0].CompletionProc = CompletionProc;
+ FoundEntry->Callbacks[0].Context = Context;
+
+ /* append it to the queue */
+ InsertTailList(&scm->QueueListHead,
+ &FoundEntry->ListEntry);
+
+ /* signal the lookup event */
+ SetEvent(scm->LookupEvent);
+
+ Ret = TRUE;
+ }
+ else
+ {
+ /* unable to queue it because we couldn't allocate the callbacks
+ array, free the memory and return */
+ HeapFree(scm->Heap,
+ 0,
+ FoundEntry);
+ }
+ }
+ }
+ else
+ {
+ PSIDCACHECALLBACKINFO Sidccb;
+
+ /* add the callback */
+ Sidccb = HeapReAlloc(scm->Heap,
+ 0,
+ FoundEntry->Callbacks,
+ (FoundEntry->CallbackCount + 1) * sizeof(SIDCACHECALLBACKINFO));
+ if (Sidccb != NULL)
+ {
+ FoundEntry->Callbacks = Sidccb;
+ FoundEntry->Callbacks[FoundEntry->CallbackCount].CompletionProc = CompletionProc;
+ FoundEntry->Callbacks[FoundEntry->CallbackCount++].Context = Context;
+
+ Ret = TRUE;
+ }
+ }
+
+ return Ret;
+}
+
+
+VOID
+DequeueSidLookup(IN HANDLE SidCacheMgr,
+ IN PSID pSid)
+{
+ PLIST_ENTRY CurrentEntry;
+ PSIDQUEUEENTRY QueueEntry;
+ PSIDCACHEMGR scm;
+
+ scm = ReferenceSidCacheMgr(SidCacheMgr);
+ if (scm != NULL)
+ {
+ EnterCriticalSection(&scm->Lock);
+
+ if (scm->QueueLookingUp != NULL &&
+ EqualSid(pSid,
+ (PSID)(scm->QueueLookingUp + 1)))
+ {
+ /* don't free the queue lookup item! this will be
+ done in the lookup thread */
+ scm->QueueLookingUp = NULL;
+ }
+ else
+ {
+ CurrentEntry = &scm->QueueListHead;
+ while (CurrentEntry != &scm->QueueListHead)
+ {
+ QueueEntry = CONTAINING_RECORD(CurrentEntry,
+ SIDQUEUEENTRY,
+ ListEntry);
+
+ if (EqualSid(pSid,
+ (PSID)(QueueEntry + 1)))
+ {
+ FreeQueueEntry(scm,
+ QueueEntry);
+ break;
+ }
+
+ CurrentEntry = CurrentEntry->Flink;
+ }
+ }
+
+ LeaveCriticalSection(&scm->Lock);
+
+ DereferenceSidCacheMgr(scm);
+ }
+}
+
+
+VOID
+ReferenceSidReqResult(IN HANDLE SidCacheMgr,
+ IN PSIDREQRESULT ReqResult)
+{
+ PSIDCACHEMGR scm;
+
+ scm = ReferenceSidCacheMgr(SidCacheMgr);
+ if (scm != NULL)
+ {
+ InterlockedIncrement(&ReqResult->RefCount);
+
+ DereferenceSidCacheMgr(scm);
+ }
+}
+
+
+VOID
+DereferenceSidReqResult(IN HANDLE SidCacheMgr,
+ IN PSIDREQRESULT ReqResult)
+{
+ PSIDCACHEMGR scm;
+
+ scm = ReferenceSidCacheMgr(SidCacheMgr);
+ if (scm != NULL)
+ {
+ if (InterlockedDecrement(&ReqResult->RefCount) == 0)
+ {
+ HeapFree(scm->Heap,
+ 0,
+ ReqResult);
+ }
+
+ DereferenceSidCacheMgr(scm);
+ }
+}
+
+
+BOOL
+LookupSidCache(IN HANDLE SidCacheMgr,
+ IN PSID pSid,
+ IN PSIDREQCOMPLETIONPROC CompletionProc,
+ IN PVOID Context)
+{
+ BOOL Found = FALSE;
+ PSIDREQRESULT ReqResult = NULL;
+ PSIDCACHEMGR scm;
+
+ scm = ReferenceSidCacheMgr(SidCacheMgr);
+ if (scm != NULL)
+ {
+ EnterCriticalSection(&scm->Lock);
+
+ /* search the cache */
+ Found = FindSidInCache(scm,
+ pSid,
+ &ReqResult);
+
+ if (!Found)
+ {
+ /* the sid is not in the cache, queue it if not already queued */
+ if (!QueueSidLookup(scm,
+ pSid,
+ CompletionProc,
+ Context))
+ {
+ PSIDREQRESULT FoundReqResult = NULL;
+
+ /* unable to queue it, look it up now */
+
+ LeaveCriticalSection(&scm->Lock);
+
+ /* lookup everything we need */
+ if (!LookupSidInformation(scm,
+ pSid,
+ &ReqResult))
+ {
+ ReqResult = NULL;
+ }
+
+ EnterCriticalSection(&scm->Lock);
+
+ /* see if the SID was added to the cache in the meanwhile */
+ if (!FindSidInCache(scm,
+ pSid,
+ &FoundReqResult))
+ {
+ if (ReqResult != NULL)
+ {
+ /* cache the results */
+ CacheLookupResults(scm,
+ pSid,
+ ReqResult);
+ }
+ }
+ else
+ {
+ if (ReqResult != NULL)
+ {
+ /* free the information of our lookup and use the cached
+ information*/
+ DereferenceSidReqResult(scm,
+ ReqResult);
+ }
+
+ ReqResult = FoundReqResult;
+ }
+
+ Found = (ReqResult != NULL);
+ }
+ }
+
+ LeaveCriticalSection(&scm->Lock);
+
+ /* call the completion callback */
+ if (Found)
+ {
+ CompletionProc(SidCacheMgr,
+ pSid,
+ ReqResult,
+ Context);
+
+ if (ReqResult != NULL)
+ {
+ HeapFree(scm->Heap,
+ 0,
+ ReqResult);
+ }
+ }
+
+ DereferenceSidCacheMgr(scm);
+ }
+
+ return Found;
+}
--- /dev/null
- typedef ULONG u32;
+/******************************************************************************
+ *
+ * Name: actypes.h - Common data types for the entire ACPI subsystem
+ * $Revision: 1.5 $
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000, 2001 R. Byron Moore
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __ACTYPES_H__
+#define __ACTYPES_H__
+
+/*! [Begin] no source code translation (keep the typedefs) */
+
+/*
+ * Data types - Fixed across all compilation models
+ *
+ * BOOLEAN Logical Boolean.
+ * 1 byte value containing a 0 for FALSE or a 1 for TRUE.
+ * Other values are undefined.
+ *
+ * INT8 8-bit (1 byte) signed value
+ * UINT8 8-bit (1 byte) unsigned value
+ * INT16 16-bit (2 byte) signed value
+ * UINT16 16-bit (2 byte) unsigned value
+ * INT32 32-bit (4 byte) signed value
+ * UINT32 32-bit (4 byte) unsigned value
+ * INT64 64-bit (8 byte) signed value
+ * UINT64 64-bit (8 byte) unsigned value
+ * NATIVE_INT 32-bit on IA-32, 64-bit on IA-64 signed value
+ * NATIVE_UINT 32-bit on IA-32, 64-bit on IA-64 unsigned value
+ * UCHAR Character. 1 byte unsigned value.
+ */
+
+
+#ifdef _IA64
+/*
+ * 64-bit type definitions
+ */
+typedef unsigned char UINT8;
+typedef unsigned char BOOLEAN;
+typedef unsigned char UCHAR;
+typedef unsigned short UINT16;
+typedef int INT32;
+typedef unsigned int UINT32;
+typedef COMPILER_DEPENDENT_UINT64 UINT64;
+
+typedef UINT64 NATIVE_UINT;
+typedef INT64 NATIVE_INT;
+
+typedef NATIVE_UINT ACPI_TBLPTR;
+typedef UINT64 ACPI_IO_ADDRESS;
+typedef UINT64 ACPI_PHYSICAL_ADDRESS;
+
+#define ALIGNED_ADDRESS_BOUNDARY 0x00000008
+
+/* (No hardware alignment support in IA64) */
+
+
+#elif _IA16
+/*
+ * 16-bit type definitions
+ */
+typedef unsigned char UINT8;
+typedef unsigned char BOOLEAN;
+typedef unsigned char UCHAR;
+typedef unsigned int UINT16;
+typedef long INT32;
+typedef int INT16;
+typedef unsigned long UINT32;
+
+typedef struct
+{
+ UINT32 Lo;
+ UINT32 Hi;
+
+} UINT64;
+
+typedef UINT16 NATIVE_UINT;
+typedef INT16 NATIVE_INT;
+
+typedef UINT32 ACPI_TBLPTR;
+typedef UINT32 ACPI_IO_ADDRESS;
+typedef char *ACPI_PHYSICAL_ADDRESS;
+
+#define ALIGNED_ADDRESS_BOUNDARY 0x00000002
+#define _HW_ALIGNMENT_SUPPORT
+
+/*
+ * (16-bit only) internal integers must be 32-bits, so
+ * 64-bit integers cannot be supported
+ */
+#define ACPI_NO_INTEGER64_SUPPORT
+
+
+#else
+/*
+ * 32-bit type definitions (default)
+ */
+//typedef unsigned char UINT8;
+//typedef unsigned char BOOLEAN;
+//typedef unsigned char UCHAR;
+//typedef unsigned short UINT16;
+//typedef int INT32;
+//typedef unsigned int UINT32;
+//typedef COMPILER_DEPENDENT_UINT64 UINT64;
+
+typedef UINT32 NATIVE_UINT;
+typedef INT32 NATIVE_INT;
+
+typedef NATIVE_UINT ACPI_TBLPTR;
+typedef UINT32 ACPI_IO_ADDRESS;
+typedef UINT64 ACPI_PHYSICAL_ADDRESS;
+
+#define ALIGNED_ADDRESS_BOUNDARY 0x00000004
+#define _HW_ALIGNMENT_SUPPORT
+#endif
+
+
+
+/*
+ * Miscellaneous common types
+ */
+
+typedef UINT32 UINT32_BIT;
+typedef NATIVE_UINT ACPI_PTRDIFF;
+typedef char NATIVE_CHAR;
+
+
+/*
+ * Data type ranges
+ */
+
+#define ACPI_UINT8_MAX (UINT8) 0xFF
+#define ACPI_UINT16_MAX (UINT16) 0xFFFF
+#define ACPI_UINT32_MAX (UINT32) 0xFFFFFFFF
+#ifdef __GNUC__
+#define ACPI_UINT64_MAX (UINT64) 0xFFFFFFFFFFFFFFFFULL
+#else
+#define ACPI_UINT64_MAX (UINT64) 0xFFFFFFFFFFFFFFFF
+#endif
+
+#ifdef DEFINE_ALTERNATE_TYPES
+/*
+ * Types used only in translated source
+ */
+typedef INT32 s32;
+typedef UINT8 u8;
+typedef UINT16 u16;
+typedef UINT32 u32;
+typedef UINT64 u64;
+#endif
+/*! [End] no source code translation !*/
+
+
+/*
+ * Useful defines
+ */
+
+#ifdef FALSE
+#undef FALSE
+#endif
+#define FALSE (1 == 0)
+
+#ifdef TRUE
+#undef TRUE
+#endif
+#define TRUE (1 == 1)
+
+#ifndef NULL
+#define NULL (void *) 0
+#endif
+
+
+/*
+ * Local datatypes
+ */
+#ifdef _MSC_VER
+typedef ULONGLONG u64;
- typedef LONG s32;
++//~ typedef ULONG u32;
+typedef USHORT u16;
+typedef UCHAR u8;
+typedef LONGLONG s64;
++//~ typedef LONG s32;
+typedef SHORT s16;
+typedef CHAR s8;
+#endif
+
+typedef u32 ACPI_STATUS; /* All ACPI Exceptions */
+typedef u32 ACPI_NAME; /* 4-s8 ACPI name */
+typedef char* ACPI_STRING; /* Null terminated ASCII string */
+typedef void* ACPI_HANDLE; /* Actually a ptr to an Node */
+
+
+/*
+ * Acpi integer width. In ACPI version 1, integers are
+ * 32 bits. In ACPI version 2, integers are 64 bits.
+ * Note that this pertains to the ACPI integer type only, not
+ * other integers used in the implementation of the ACPI CA
+ * subsystem.
+ */
+#ifdef ACPI_NO_INTEGER64_SUPPORT
+
+/* 32-bit integers only, no 64-bit support */
+
+typedef u32 ACPI_INTEGER;
+#define ACPI_INTEGER_MAX ACPI_UINT32_MAX
+#define ACPI_INTEGER_BIT_SIZE 32
+#define ACPI_MAX_BCD_VALUE 99999999
+#define ACPI_MAX_BCD_DIGITS 8
+
+#else
+
+/* 64-bit integers */
+
+typedef UINT64 ACPI_INTEGER;
+#define ACPI_INTEGER_MAX ACPI_UINT64_MAX
+#define ACPI_INTEGER_BIT_SIZE 64
+#ifdef __GNUC__
+#define ACPI_MAX_BCD_VALUE 9999999999999999ULL
+#else
+#define ACPI_MAX_BCD_VALUE 9999999999999999
+#endif
+#define ACPI_MAX_BCD_DIGITS 16
+
+#endif
+
+
+/*
+ * Constants with special meanings
+ */
+
+#define ACPI_ROOT_OBJECT (ACPI_HANDLE)(-1)
+
+#define ACPI_FULL_INITIALIZATION 0x00
+#define ACPI_NO_ADDRESS_SPACE_INIT 0x01
+#define ACPI_NO_HARDWARE_INIT 0x02
+#define ACPI_NO_EVENT_INIT 0x04
+#define ACPI_NO_ACPI_ENABLE 0x08
+#define ACPI_NO_DEVICE_INIT 0x10
+#define ACPI_NO_OBJECT_INIT 0x20
+
+
+/*
+ * System states
+ */
+#define ACPI_STATE_S0 (u8) 0
+#define ACPI_STATE_S1 (u8) 1
+#define ACPI_STATE_S2 (u8) 2
+#define ACPI_STATE_S3 (u8) 3
+#define ACPI_STATE_S4 (u8) 4
+#define ACPI_STATE_S5 (u8) 5
+/* let's pretend S4_bIOS didn't exist for now. ASG */
+#define ACPI_STATE_S4_bIOS (u8) 6
+#define ACPI_S_STATES_MAX ACPI_STATE_S5
+#define ACPI_S_STATE_COUNT 6
+
+/*
+ * Device power states
+ */
+#define ACPI_STATE_D0 (u8) 0
+#define ACPI_STATE_D1 (u8) 1
+#define ACPI_STATE_D2 (u8) 2
+#define ACPI_STATE_D3 (u8) 3
+#define ACPI_D_STATES_MAX ACPI_STATE_D3
+#define ACPI_D_STATE_COUNT 4
+
+#define ACPI_STATE_UNKNOWN (u8) 0xFF
+
+
+/*
+ * Table types. These values are passed to the table related APIs
+ */
+
+typedef u32 ACPI_TABLE_TYPE;
+
+#define ACPI_TABLE_RSDP (ACPI_TABLE_TYPE) 0
+#define ACPI_TABLE_DSDT (ACPI_TABLE_TYPE) 1
+#define ACPI_TABLE_FADT (ACPI_TABLE_TYPE) 2
+#define ACPI_TABLE_FACS (ACPI_TABLE_TYPE) 3
+#define ACPI_TABLE_PSDT (ACPI_TABLE_TYPE) 4
+#define ACPI_TABLE_SSDT (ACPI_TABLE_TYPE) 5
+#define ACPI_TABLE_XSDT (ACPI_TABLE_TYPE) 6
+#define ACPI_TABLE_MAX 6
+#define NUM_ACPI_TABLES (ACPI_TABLE_MAX+1)
+
+
+/*
+ * Types associated with names. The first group of
+ * values correspond to the definition of the ACPI
+ * Object_type operator (See the ACPI Spec). Therefore,
+ * only add to the first group if the spec changes!
+ *
+ * Types must be kept in sync with the Acpi_ns_properties
+ * and Acpi_ns_type_names arrays
+ */
+
+typedef u32 ACPI_OBJECT_TYPE;
+typedef u8 OBJECT_TYPE_INTERNAL;
+
+#define ACPI_BTYPE_ANY 0x00000000
+#define ACPI_BTYPE_INTEGER 0x00000001
+#define ACPI_BTYPE_STRING 0x00000002
+#define ACPI_BTYPE_BUFFER 0x00000004
+#define ACPI_BTYPE_PACKAGE 0x00000008
+#define ACPI_BTYPE_FIELD_UNIT 0x00000010
+#define ACPI_BTYPE_DEVICE 0x00000020
+#define ACPI_BTYPE_EVENT 0x00000040
+#define ACPI_BTYPE_METHOD 0x00000080
+#define ACPI_BTYPE_MUTEX 0x00000100
+#define ACPI_BTYPE_REGION 0x00000200
+#define ACPI_BTYPE_POWER 0x00000400
+#define ACPI_BTYPE_PROCESSOR 0x00000800
+#define ACPI_BTYPE_THERMAL 0x00001000
+#define ACPI_BTYPE_BUFFER_FIELD 0x00002000
+#define ACPI_BTYPE_DDB_HANDLE 0x00004000
+#define ACPI_BTYPE_DEBUG_OBJECT 0x00008000
+#define ACPI_BTYPE_REFERENCE 0x00010000
+#define ACPI_BTYPE_RESOURCE 0x00020000
+
+#define ACPI_BTYPE_COMPUTE_DATA (ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER)
+
+#define ACPI_BTYPE_DATA (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_PACKAGE)
+#define ACPI_BTYPE_DATA_REFERENCE (ACPI_BTYPE_DATA | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE)
+#define ACPI_BTYPE_DEVICE_OBJECTS (ACPI_BTYPE_DEVICE | ACPI_BTYPE_THERMAL | ACPI_BTYPE_PROCESSOR)
+#define ACPI_BTYPE_OBJECTS_AND_REFS 0x00017FFF /* ARG or LOCAL */
+#define ACPI_BTYPE_ALL_OBJECTS 0x00007FFF
+
+
+#define ACPI_TYPE_ANY 0 /* 0x00 */
+#define ACPI_TYPE_INTEGER 1 /* 0x01 Byte/Word/Dword/Zero/One/Ones */
+#define ACPI_TYPE_STRING 2 /* 0x02 */
+#define ACPI_TYPE_BUFFER 3 /* 0x03 */
+#define ACPI_TYPE_PACKAGE 4 /* 0x04 Byte_const, multiple Data_term/Constant/Super_name */
+#define ACPI_TYPE_FIELD_UNIT 5 /* 0x05 */
+#define ACPI_TYPE_DEVICE 6 /* 0x06 Name, multiple Node */
+#define ACPI_TYPE_EVENT 7 /* 0x07 */
+#define ACPI_TYPE_METHOD 8 /* 0x08 Name, Byte_const, multiple Code */
+#define ACPI_TYPE_MUTEX 9 /* 0x09 */
+#define ACPI_TYPE_REGION 10 /* 0x0A */
+#define ACPI_TYPE_POWER 11 /* 0x0B Name,Byte_const,Word_const,multi Node */
+#define ACPI_TYPE_PROCESSOR 12 /* 0x0C Name,Byte_const,DWord_const,Byte_const,multi Nm_o */
+#define ACPI_TYPE_THERMAL 13 /* 0x0D Name, multiple Node */
+#define ACPI_TYPE_BUFFER_FIELD 14 /* 0x0E */
+#define ACPI_TYPE_DDB_HANDLE 15 /* 0x0F */
+#define ACPI_TYPE_DEBUG_OBJECT 16 /* 0x10 */
+
+#define ACPI_TYPE_MAX 16
+
+/*
+ * This section contains object types that do not relate to the ACPI Object_type operator.
+ * They are used for various internal purposes only. If new predefined ACPI_TYPEs are
+ * added (via the ACPI specification), these internal types must move upwards.
+ * Also, values exceeding the largest official ACPI Object_type must not overlap with
+ * defined AML opcodes.
+ */
+#define INTERNAL_TYPE_BEGIN 17
+
+#define INTERNAL_TYPE_DEF_FIELD 17 /* 0x11 */
+#define INTERNAL_TYPE_BANK_FIELD 18 /* 0x12 */
+#define INTERNAL_TYPE_INDEX_FIELD 19 /* 0x13 */
+#define INTERNAL_TYPE_REFERENCE 20 /* 0x14 Arg#, Local#, Name, Debug; used only in descriptors */
+#define INTERNAL_TYPE_ALIAS 21 /* 0x15 */
+#define INTERNAL_TYPE_NOTIFY 22 /* 0x16 */
+#define INTERNAL_TYPE_ADDRESS_HANDLER 23 /* 0x17 */
+#define INTERNAL_TYPE_RESOURCE 24 /* 0x18 */
+
+
+#define INTERNAL_TYPE_NODE_MAX 24
+
+/* These are pseudo-types because there are never any namespace nodes with these types */
+
+#define INTERNAL_TYPE_DEF_FIELD_DEFN 25 /* 0x19 Name, Byte_const, multiple Field_element */
+#define INTERNAL_TYPE_BANK_FIELD_DEFN 26 /* 0x1A 2 Name,DWord_const,Byte_const,multi Field_element */
+#define INTERNAL_TYPE_INDEX_FIELD_DEFN 27 /* 0x1B 2 Name, Byte_const, multiple Field_element */
+#define INTERNAL_TYPE_IF 28 /* 0x1C */
+#define INTERNAL_TYPE_ELSE 29 /* 0x1D */
+#define INTERNAL_TYPE_WHILE 30 /* 0x1E */
+#define INTERNAL_TYPE_SCOPE 31 /* 0x1F Name, multiple Node */
+#define INTERNAL_TYPE_DEF_ANY 32 /* 0x20 type is Any, suppress search of enclosing scopes */
+#define INTERNAL_TYPE_EXTRA 33 /* 0x21 */
+
+#define INTERNAL_TYPE_MAX 33
+
+#define INTERNAL_TYPE_INVALID 34
+#define ACPI_TYPE_NOT_FOUND 0xFF
+
+/*
+ * Acpi_event Types:
+ * ------------
+ * Fixed & general purpose...
+ */
+
+typedef u32 ACPI_EVENT_TYPE;
+
+#define ACPI_EVENT_FIXED (ACPI_EVENT_TYPE) 0
+#define ACPI_EVENT_GPE (ACPI_EVENT_TYPE) 1
+
+/*
+ * Fixed events
+ */
+
+#define ACPI_EVENT_PMTIMER (ACPI_EVENT_TYPE) 0
+ /*
+ * There's no bus master event so index 1 is used for IRQ's that are not
+ * handled by the SCI handler
+ */
+#define ACPI_EVENT_NOT_USED (ACPI_EVENT_TYPE) 1
+#define ACPI_EVENT_GLOBAL (ACPI_EVENT_TYPE) 2
+#define ACPI_EVENT_POWER_BUTTON (ACPI_EVENT_TYPE) 3
+#define ACPI_EVENT_SLEEP_BUTTON (ACPI_EVENT_TYPE) 4
+#define ACPI_EVENT_RTC (ACPI_EVENT_TYPE) 5
+#define ACPI_EVENT_GENERAL (ACPI_EVENT_TYPE) 6
+#define ACPI_EVENT_MAX 6
+#define NUM_FIXED_EVENTS (ACPI_EVENT_TYPE) 7
+
+#define ACPI_GPE_INVALID 0xFF
+#define ACPI_GPE_MAX 0xFF
+#define NUM_GPE 256
+
+#define ACPI_EVENT_LEVEL_TRIGGERED (ACPI_EVENT_TYPE) 1
+#define ACPI_EVENT_EDGE_TRIGGERED (ACPI_EVENT_TYPE) 2
+
+/*
+ * Acpi_event Status:
+ * -------------
+ * The encoding of ACPI_EVENT_STATUS is illustrated below.
+ * Note that a set bit (1) indicates the property is TRUE
+ * (e.g. if bit 0 is set then the event is enabled).
+ * +---------------+-+-+
+ * | Bits 31:2 |1|0|
+ * +---------------+-+-+
+ * | | |
+ * | | +- Enabled?
+ * | +--- Set?
+ * +----------- <Reserved>
+ */
+typedef u32 ACPI_EVENT_STATUS;
+
+#define ACPI_EVENT_FLAG_DISABLED (ACPI_EVENT_STATUS) 0x00
+#define ACPI_EVENT_FLAG_ENABLED (ACPI_EVENT_STATUS) 0x01
+#define ACPI_EVENT_FLAG_SET (ACPI_EVENT_STATUS) 0x02
+
+
+/* Notify types */
+
+#define ACPI_SYSTEM_NOTIFY 0
+#define ACPI_DEVICE_NOTIFY 1
+#define ACPI_MAX_NOTIFY_HANDLER_TYPE 1
+
+#define MAX_SYS_NOTIFY 0x7f
+
+
+/* Address Space (Operation Region) Types */
+
+typedef u8 ACPI_ADDRESS_SPACE_TYPE;
+
+#define ADDRESS_SPACE_SYSTEM_MEMORY (ACPI_ADDRESS_SPACE_TYPE) 0
+#define ADDRESS_SPACE_SYSTEM_IO (ACPI_ADDRESS_SPACE_TYPE) 1
+#define ADDRESS_SPACE_PCI_CONFIG (ACPI_ADDRESS_SPACE_TYPE) 2
+#define ADDRESS_SPACE_EC (ACPI_ADDRESS_SPACE_TYPE) 3
+#define ADDRESS_SPACE_SMBUS (ACPI_ADDRESS_SPACE_TYPE) 4
+#define ADDRESS_SPACE_CMOS (ACPI_ADDRESS_SPACE_TYPE) 5
+#define ADDRESS_SPACE_PCI_BAR_TARGET (ACPI_ADDRESS_SPACE_TYPE) 6
+
+
+/*
+ * External ACPI object definition
+ */
+
+typedef union acpi_obj
+{
+ ACPI_OBJECT_TYPE type; /* See definition of Acpi_ns_type for values */
+ struct
+ {
+ ACPI_OBJECT_TYPE type;
+ ACPI_INTEGER value; /* The actual number */
+ } integer;
+
+ struct
+ {
+ ACPI_OBJECT_TYPE type;
+ u32 length; /* # of bytes in string, excluding trailing null */
+ NATIVE_CHAR *pointer; /* points to the string value */
+ } string;
+
+ struct
+ {
+ ACPI_OBJECT_TYPE type;
+ u32 length; /* # of bytes in buffer */
+ u8 *pointer; /* points to the buffer */
+ } buffer;
+
+ struct
+ {
+ ACPI_OBJECT_TYPE type;
+ u32 fill1;
+ ACPI_HANDLE handle; /* object reference */
+ } reference;
+
+ struct
+ {
+ ACPI_OBJECT_TYPE type;
+ u32 count; /* # of elements in package */
+ union acpi_obj *elements; /* Pointer to an array of ACPI_OBJECTs */
+ } package;
+
+ struct
+ {
+ ACPI_OBJECT_TYPE type;
+ u32 proc_id;
+ ACPI_IO_ADDRESS pblk_address;
+ u32 pblk_length;
+ } processor;
+
+ struct
+ {
+ ACPI_OBJECT_TYPE type;
+ u32 system_level;
+ u32 resource_order;
+ } power_resource;
+
+} ACPI_OBJECT, *PACPI_OBJECT;
+
+
+/*
+ * List of objects, used as a parameter list for control method evaluation
+ */
+
+typedef struct acpi_obj_list
+{
+ u32 count;
+ ACPI_OBJECT *pointer;
+
+} ACPI_OBJECT_LIST, *PACPI_OBJECT_LIST;
+
+
+/*
+ * Miscellaneous common Data Structures used by the interfaces
+ */
+
+typedef struct
+{
+ u32 length; /* Length in bytes of the buffer */
+ void *pointer; /* pointer to buffer */
+
+} ACPI_BUFFER;
+
+
+/*
+ * Name_type for Acpi_get_name
+ */
+
+#define ACPI_FULL_PATHNAME 0
+#define ACPI_SINGLE_NAME 1
+#define ACPI_NAME_TYPE_MAX 1
+
+
+/*
+ * Structure and flags for Acpi_get_system_info
+ */
+
+#define SYS_MODE_UNKNOWN 0x0000
+#define SYS_MODE_ACPI 0x0001
+#define SYS_MODE_LEGACY 0x0002
+#define SYS_MODES_MASK 0x0003
+
+/*
+ * ACPI CPU Cx state handler
+ */
+typedef
+ACPI_STATUS (*ACPI_SET_C_STATE_HANDLER) (
+ NATIVE_UINT pblk_address);
+
+/*
+ * ACPI Cx State info
+ */
+typedef struct
+{
+ u32 state_number;
+ u32 latency;
+} ACPI_CX_STATE;
+
+/*
+ * ACPI CPU throttling info
+ */
+typedef struct
+{
+ u32 state_number;
+ u32 percent_of_clock;
+} ACPI_CPU_THROTTLING_STATE;
+
+/*
+ * ACPI Table Info. One per ACPI table _type_
+ */
+typedef struct acpi_table_info
+{
+ u32 count;
+
+} ACPI_TABLE_INFO;
+
+
+/*
+ * System info returned by Acpi_get_system_info()
+ */
+
+typedef struct _acpi_sys_info
+{
+ u32 acpi_ca_version;
+ u32 flags;
+ u32 timer_resolution;
+ u32 reserved1;
+ u32 reserved2;
+ u32 debug_level;
+ u32 debug_layer;
+ u32 num_table_types;
+ ACPI_TABLE_INFO table_info [NUM_ACPI_TABLES];
+
+} ACPI_SYSTEM_INFO;
+
+
+/*
+ * System Initiailization data. This data is passed to ACPIInitialize
+ * copyied to global data and retained by ACPI CA
+ */
+
+typedef struct _acpi_init_data
+{
+ void *RSDP_physical_address; /* Address of RSDP, needed it it is */
+ /* not found in the IA32 manner */
+} ACPI_INIT_DATA;
+
+/*
+ * Various handlers and callback procedures
+ */
+
+typedef
+u32 (*FIXED_EVENT_HANDLER) (
+ void *context);
+
+typedef
+void (*GPE_HANDLER) (
+ void *context);
+
+typedef
+void (*NOTIFY_HANDLER) (
+ ACPI_HANDLE device,
+ u32 value,
+ void *context);
+
+#define ADDRESS_SPACE_READ 1
+#define ADDRESS_SPACE_WRITE 2
+
+typedef
+ACPI_STATUS (*ADDRESS_SPACE_HANDLER) (
+ u32 function,
+ ACPI_PHYSICAL_ADDRESS address,
+ u32 bit_width,
+ u32 *value,
+ void *handler_context,
+ void *region_context);
+
+#define ACPI_DEFAULT_HANDLER ((ADDRESS_SPACE_HANDLER) NULL)
+
+
+typedef
+ACPI_STATUS (*ADDRESS_SPACE_SETUP) (
+ ACPI_HANDLE region_handle,
+ u32 function,
+ void *handler_context,
+ void **region_context);
+
+#define ACPI_REGION_ACTIVATE 0
+#define ACPI_REGION_DEACTIVATE 1
+
+typedef
+ACPI_STATUS (*WALK_CALLBACK) (
+ ACPI_HANDLE obj_handle,
+ u32 nesting_level,
+ void *context,
+ void **return_value);
+
+
+/* Interrupt handler return values */
+
+#define INTERRUPT_NOT_HANDLED 0x00
+#define INTERRUPT_HANDLED 0x01
+
+
+/* Structure and flags for Acpi_get_device_info */
+
+#define ACPI_VALID_HID 0x1
+#define ACPI_VALID_UID 0x2
+#define ACPI_VALID_ADR 0x4
+#define ACPI_VALID_STA 0x8
+
+
+#define ACPI_COMMON_OBJ_INFO \
+ ACPI_OBJECT_TYPE type; /* ACPI object type */ \
+ ACPI_NAME name /* ACPI object Name */
+
+
+typedef struct
+{
+ ACPI_COMMON_OBJ_INFO;
+} ACPI_OBJ_INFO_HEADER;
+
+
+typedef struct
+{
+ ACPI_COMMON_OBJ_INFO;
+
+ u32 valid; /* Are the next bits legit? */
+ NATIVE_CHAR hardware_id [9]; /* _HID value if any */
+ NATIVE_CHAR unique_id[9]; /* _UID value if any */
+ ACPI_INTEGER address; /* _ADR value if any */
+ u32 current_status; /* _STA value */
+} ACPI_DEVICE_INFO;
+
+
+/* Context structs for address space handlers */
+
+typedef struct
+{
+ u32 seg;
+ u32 bus;
+ u32 dev_func;
+} PCI_HANDLER_CONTEXT;
+
+
+typedef struct
+{
+ ACPI_PHYSICAL_ADDRESS mapped_physical_address;
+ u8 *mapped_logical_address;
+ u32 mapped_length;
+} MEM_HANDLER_CONTEXT;
+
+
+/*
+ * C-state handler
+ */
+
+typedef ACPI_STATUS (*ACPI_C_STATE_HANDLER) (ACPI_IO_ADDRESS, u32*);
+
+
+/*
+ * Definitions for Resource Attributes
+ */
+
+/*
+ * Memory Attributes
+ */
+#define READ_ONLY_MEMORY (u8) 0x00
+#define READ_WRITE_MEMORY (u8) 0x01
+
+#define NON_CACHEABLE_MEMORY (u8) 0x00
+#define CACHABLE_MEMORY (u8) 0x01
+#define WRITE_COMBINING_MEMORY (u8) 0x02
+#define PREFETCHABLE_MEMORY (u8) 0x03
+
+/*
+ * IO Attributes
+ * The ISA IO ranges are: n000-n0FFh, n400-n4_fFh, n800-n8_fFh, n_c00-n_cFFh.
+ * The non-ISA IO ranges are: n100-n3_fFh, n500-n7_fFh, n900-n_bFFh, n_cD0-n_fFFh.
+ */
+#define NON_ISA_ONLY_RANGES (u8) 0x01
+#define ISA_ONLY_RANGES (u8) 0x02
+#define ENTIRE_RANGE (NON_ISA_ONLY_RANGES | ISA_ONLY_RANGES)
+
+/*
+ * IO Port Descriptor Decode
+ */
+#define DECODE_10 (u8) 0x00 /* 10-bit IO address decode */
+#define DECODE_16 (u8) 0x01 /* 16-bit IO address decode */
+
+/*
+ * IRQ Attributes
+ */
+#define EDGE_SENSITIVE (u8) 0x00
+#define LEVEL_SENSITIVE (u8) 0x01
+
+#define ACTIVE_HIGH (u8) 0x00
+#define ACTIVE_LOW (u8) 0x01
+
+#define EXCLUSIVE (u8) 0x00
+#define SHARED (u8) 0x01
+
+/*
+ * DMA Attributes
+ */
+#define COMPATIBILITY (u8) 0x00
+#define TYPE_A (u8) 0x01
+#define TYPE_B (u8) 0x02
+#define TYPE_F (u8) 0x03
+
+#define NOT_BUS_MASTER (u8) 0x00
+#define BUS_MASTER (u8) 0x01
+
+#define TRANSFER_8 (u8) 0x00
+#define TRANSFER_8_16 (u8) 0x01
+#define TRANSFER_16 (u8) 0x02
+
+/*
+ * Start Dependent Functions Priority definitions
+ */
+#define GOOD_CONFIGURATION (u8) 0x00
+#define ACCEPTABLE_CONFIGURATION (u8) 0x01
+#define SUB_OPTIMAL_CONFIGURATION (u8) 0x02
+
+/*
+ * 16, 32 and 64-bit Address Descriptor resource types
+ */
+#define MEMORY_RANGE (u8) 0x00
+#define IO_RANGE (u8) 0x01
+#define BUS_NUMBER_RANGE (u8) 0x02
+
+#define ADDRESS_NOT_FIXED (u8) 0x00
+#define ADDRESS_FIXED (u8) 0x01
+
+#define POS_DECODE (u8) 0x00
+#define SUB_DECODE (u8) 0x01
+
+#define PRODUCER (u8) 0x00
+#define CONSUMER (u8) 0x01
+
+
+/*
+ * Structures used to describe device resources
+ */
+typedef struct
+{
+ u32 edge_level;
+ u32 active_high_low;
+ u32 shared_exclusive;
+ u32 number_of_interrupts;
+ u32 interrupts[1];
+
+} IRQ_RESOURCE;
+
+typedef struct
+{
+ u32 type;
+ u32 bus_master;
+ u32 transfer;
+ u32 number_of_channels;
+ u32 channels[1];
+
+} DMA_RESOURCE;
+
+typedef struct
+{
+ u32 compatibility_priority;
+ u32 performance_robustness;
+
+} START_DEPENDENT_FUNCTIONS_RESOURCE;
+
+/*
+ * END_DEPENDENT_FUNCTIONS_RESOURCE struct is not
+ * needed because it has no fields
+ */
+
+typedef struct
+{
+ u32 io_decode;
+ u32 min_base_address;
+ u32 max_base_address;
+ u32 alignment;
+ u32 range_length;
+
+} IO_RESOURCE;
+
+typedef struct
+{
+ u32 base_address;
+ u32 range_length;
+
+} FIXED_IO_RESOURCE;
+
+typedef struct
+{
+ u32 length;
+ u8 reserved[1];
+
+} VENDOR_RESOURCE;
+
+typedef struct
+{
+ u32 read_write_attribute;
+ u32 min_base_address;
+ u32 max_base_address;
+ u32 alignment;
+ u32 range_length;
+
+} MEMORY24_RESOURCE;
+
+typedef struct
+{
+ u32 read_write_attribute;
+ u32 min_base_address;
+ u32 max_base_address;
+ u32 alignment;
+ u32 range_length;
+
+} MEMORY32_RESOURCE;
+
+typedef struct
+{
+ u32 read_write_attribute;
+ u32 range_base_address;
+ u32 range_length;
+
+} FIXED_MEMORY32_RESOURCE;
+
+typedef struct
+{
+ u16 cache_attribute;
+ u16 read_write_attribute;
+
+} MEMORY_ATTRIBUTE;
+
+typedef struct
+{
+ u16 range_attribute;
+ u16 reserved;
+
+} IO_ATTRIBUTE;
+
+typedef struct
+{
+ u16 reserved1;
+ u16 reserved2;
+
+} BUS_ATTRIBUTE;
+
+typedef union
+{
+ MEMORY_ATTRIBUTE memory;
+ IO_ATTRIBUTE io;
+ BUS_ATTRIBUTE bus;
+
+} ATTRIBUTE_DATA;
+
+typedef struct
+{
+ u32 resource_type;
+ u32 producer_consumer;
+ u32 decode;
+ u32 min_address_fixed;
+ u32 max_address_fixed;
+ ATTRIBUTE_DATA attribute;
+ u32 granularity;
+ u32 min_address_range;
+ u32 max_address_range;
+ u32 address_translation_offset;
+ u32 address_length;
+ u32 resource_source_index;
+ u32 resource_source_string_length;
+ NATIVE_CHAR resource_source[1];
+
+} ADDRESS16_RESOURCE;
+
+typedef struct
+{
+ u32 resource_type;
+ u32 producer_consumer;
+ u32 decode;
+ u32 min_address_fixed;
+ u32 max_address_fixed;
+ ATTRIBUTE_DATA attribute;
+ u32 granularity;
+ u32 min_address_range;
+ u32 max_address_range;
+ u32 address_translation_offset;
+ u32 address_length;
+ u32 resource_source_index;
+ u32 resource_source_string_length;
+ NATIVE_CHAR resource_source[1];
+
+} ADDRESS32_RESOURCE;
+
+typedef struct
+{
+ u32 producer_consumer;
+ u32 edge_level;
+ u32 active_high_low;
+ u32 shared_exclusive;
+ u32 number_of_interrupts;
+ u32 interrupts[1];
+ u32 resource_source_index;
+ u32 resource_source_string_length;
+ NATIVE_CHAR resource_source[1];
+
+} EXTENDED_IRQ_RESOURCE;
+
+typedef enum
+{
+ irq,
+ dma,
+ start_dependent_functions,
+ end_dependent_functions,
+ io,
+ fixed_io,
+ vendor_specific,
+ end_tag,
+ memory24,
+ memory32,
+ fixed_memory32,
+ address16,
+ address32,
+ extended_irq
+} RESOURCE_TYPE;
+
+typedef union
+{
+ IRQ_RESOURCE irq;
+ DMA_RESOURCE dma;
+ START_DEPENDENT_FUNCTIONS_RESOURCE start_dependent_functions;
+ IO_RESOURCE io;
+ FIXED_IO_RESOURCE fixed_io;
+ VENDOR_RESOURCE vendor_specific;
+ MEMORY24_RESOURCE memory24;
+ MEMORY32_RESOURCE memory32;
+ FIXED_MEMORY32_RESOURCE fixed_memory32;
+ ADDRESS16_RESOURCE address16;
+ ADDRESS32_RESOURCE address32;
+ EXTENDED_IRQ_RESOURCE extended_irq;
+} RESOURCE_DATA;
+
+typedef struct _resource_tag
+{
+ RESOURCE_TYPE id;
+ u32 length;
+ RESOURCE_DATA data;
+} RESOURCE;
+
+#define RESOURCE_LENGTH 12
+#define RESOURCE_LENGTH_NO_DATA 8
+
+#define NEXT_RESOURCE(res) (RESOURCE*)((u8*) res + res->length)
+
+/*
+ * END: Definitions for Resource Attributes
+ */
+
+
+typedef struct pci_routing_table
+{
+ u32 length;
+ u32 pin;
+ ACPI_INTEGER address; /* here for 64-bit alignment */
+ u32 source_index;
+ NATIVE_CHAR source[4]; /* pad to 64 bits so sizeof() works in all cases */
+
+} PCI_ROUTING_TABLE;
+
+
+/*
+ * END: Definitions for PCI Routing tables
+ */
+
+#endif /* __ACTYPES_H__ */
--- /dev/null
- #elif WIN32
+/******************************************************************************
+ *
+ * Name: acenv.h - Generation environment specific items
+ * $Revision: 1.1 $
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000, 2001 R. Byron Moore
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __ACENV_H__
+#define __ACENV_H__
+
+
+/*
+ * Configuration for ACPI tools and utilities
+ */
+
+#ifdef _ACPI_DUMP_APP
+#define ACPI_DEBUG
+#define ACPI_APPLICATION
+#define ENABLE_DEBUGGER
+#define ACPI_USE_SYSTEM_CLIBRARY
+#define PARSER_ONLY
+#endif
+
+#ifdef _ACPI_EXEC_APP
+#undef DEBUGGER_THREADING
+#define DEBUGGER_THREADING DEBUGGER_SINGLE_THREADED
+#define ACPI_DEBUG
+#define ACPI_APPLICATION
+#define ENABLE_DEBUGGER
+#define ACPI_USE_SYSTEM_CLIBRARY
+#endif
+
+#ifdef _ACPI_ASL_COMPILER
+#define ACPI_DEBUG
+#define ACPI_APPLICATION
+#define ENABLE_DEBUGGER
+#define ACPI_USE_SYSTEM_CLIBRARY
+#endif
+
+/*
+ * Memory allocation tracking. Used only if
+ * 1) This is the debug version
+ * 2) This is NOT a 16-bit version of the code (not enough real-mode memory)
+ */
+#ifdef ACPI_DEBUG
+#ifndef _IA16
+#define ACPI_DEBUG_TRACK_ALLOCATIONS
+#endif
+#endif
+
+/*
+ * Environment configuration. The purpose of this file is to interface to the
+ * local generation environment.
+ *
+ * 1) ACPI_USE_SYSTEM_CLIBRARY - Define this if linking to an actual C library.
+ * Otherwise, local versions of string/memory functions will be used.
+ * 2) ACPI_USE_STANDARD_HEADERS - Define this if linking to a C library and
+ * the standard header files may be used.
+ *
+ * The ACPI subsystem only uses low level C library functions that do not call
+ * operating system services and may therefore be inlined in the code.
+ *
+ * It may be necessary to tailor these include files to the target
+ * generation environment.
+ *
+ *
+ * Functions and constants used from each header:
+ *
+ * string.h: memcpy
+ * memset
+ * strcat
+ * strcmp
+ * strcpy
+ * strlen
+ * strncmp
+ * strncat
+ * strncpy
+ *
+ * stdlib.h: strtoul
+ *
+ * stdarg.h: va_list
+ * va_arg
+ * va_start
+ * va_end
+ *
+ */
+
+/*! [Begin] no source code translation */
+
+#ifdef _LINUX
+#include "aclinux.h"
+
+#elif _AED_EFI
+#include "acefi.h"
+
- #elif __FreeBSD__
++#elif defined(WIN32)
+#include "acwin.h"
+
++#elif defined(__FreeBSD__)
+#include "acfreebsd.h"
+
+#else
+
+/* All other environments */
+
+#define ACPI_USE_STANDARD_HEADERS
+
+/* Name of host operating system (returned by the _OS_ namespace object) */
+
+#define ACPI_OS_NAME "Intel ACPI/CA Core Subsystem"
+
+#endif
+
+
+/*! [End] no source code translation !*/
+
+/******************************************************************************
+ *
+ * C library configuration
+ *
+ *****************************************************************************/
+
+#ifdef ACPI_USE_SYSTEM_CLIBRARY
+/*
+ * Use the standard C library headers.
+ * We want to keep these to a minimum.
+ *
+ */
+
+#ifdef ACPI_USE_STANDARD_HEADERS
+/*
+ * Use the standard headers from the standard locations
+ */
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#endif /* ACPI_USE_STANDARD_HEADERS */
+
+/*
+ * We will be linking to the standard Clib functions
+ */
+
+#define STRSTR(s1,s2) strstr((s1), (s2))
+#define STRUPR(s) strupr((s))
+#define STRLEN(s) (u32) strlen((s))
+#define STRCPY(d,s) strcpy((d), (s))
+#define STRNCPY(d,s,n) strncpy((d), (s), (NATIVE_INT)(n))
+#define STRNCMP(d,s,n) strncmp((d), (s), (NATIVE_INT)(n))
+#define STRCMP(d,s) strcmp((d), (s))
+#define STRCAT(d,s) strcat((d), (s))
+#define STRNCAT(d,s,n) strncat((d), (s), (NATIVE_INT)(n))
+#define STRTOUL(d,s,n) strtoul((d), (s), (NATIVE_INT)(n))
+#define MEMCPY(d,s,n) memcpy((d), (s), (NATIVE_INT)(n))
+#define MEMSET(d,s,n) memset((d), (s), (NATIVE_INT)(n))
+#define TOUPPER toupper
+#define TOLOWER tolower
+#define IS_XDIGIT isxdigit
+
+/******************************************************************************
+ *
+ * Not using native C library, use local implementations
+ *
+ *****************************************************************************/
+#else
+
+/*
+ * Use local definitions of C library macros and functions
+ * NOTE: The function implementations may not be as efficient
+ * as an inline or assembly code implementation provided by a
+ * native C library.
+ */
+
+#ifndef va_arg
+
+#ifndef _VALIST
+#define _VALIST
+typedef char *va_list;
+#endif /* _VALIST */
+
+/*
+ * Storage alignment properties
+ */
+
+#define _AUPBND (sizeof (NATIVE_INT) - 1)
+#define _ADNBND (sizeof (NATIVE_INT) - 1)
+
+/*
+ * Variable argument list macro definitions
+ */
+
+#define _bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd)))
+#define va_arg(ap, T) (*(T *)(((ap) += (_bnd (T, _AUPBND))) - (_bnd (T,_ADNBND))))
+#define va_end(ap) (void) 0
+#define va_start(ap, A) (void) ((ap) = (((char *) &(A)) + (_bnd (A,_AUPBND))))
+
+#endif /* va_arg */
+
+
+#define STRSTR(s1,s2) acpi_cm_strstr ((s1), (s2))
+#define STRUPR(s) acpi_cm_strupr ((s))
+#define STRLEN(s) acpi_cm_strlen ((s))
+#define STRCPY(d,s) acpi_cm_strcpy ((d), (s))
+#define STRNCPY(d,s,n) acpi_cm_strncpy ((d), (s), (n))
+#define STRNCMP(d,s,n) acpi_cm_strncmp ((d), (s), (n))
+#define STRCMP(d,s) acpi_cm_strcmp ((d), (s))
+#define STRCAT(d,s) acpi_cm_strcat ((d), (s))
+#define STRNCAT(d,s,n) acpi_cm_strncat ((d), (s), (n))
+#define STRTOUL(d,s,n) acpi_cm_strtoul ((d), (s),(n))
+#define MEMCPY(d,s,n) acpi_cm_memcpy ((d), (s), (n))
+#define MEMSET(d,v,n) acpi_cm_memset ((d), (v), (n))
+#define TOUPPER acpi_cm_to_upper
+#define TOLOWER acpi_cm_to_lower
+
+#endif /* ACPI_USE_SYSTEM_CLIBRARY */
+
+
+/******************************************************************************
+ *
+ * Assembly code macros
+ *
+ *****************************************************************************/
+
+/*
+ * Handle platform- and compiler-specific assembly language differences.
+ * These should already have been defined by the platform includes above.
+ *
+ * Notes:
+ * 1) Interrupt 3 is used to break into a debugger
+ * 2) Interrupts are turned off during ACPI register setup
+ */
+
+/* Unrecognized compiler, use defaults */
+#ifndef ACPI_ASM_MACROS
+
+#define ACPI_ASM_MACROS
+#define causeinterrupt(level)
+#define BREAKPOINT3
+#define disable()
+#define enable()
+#define halt()
+#define ACPI_ACQUIRE_GLOBAL_LOCK(Glptr, acq)
+#define ACPI_RELEASE_GLOBAL_LOCK(Glptr, acq)
+
+#endif /* ACPI_ASM_MACROS */
+
+
+#ifdef ACPI_APPLICATION
+
+/* Don't want software interrupts within a ring3 application */
+
+#undef causeinterrupt
+#undef BREAKPOINT3
+#define causeinterrupt(level)
+#define BREAKPOINT3
+#endif
+
+
+/******************************************************************************
+ *
+ * Compiler-specific
+ *
+ *****************************************************************************/
+
+/* this has been moved to compiler-specific headers, which are included from the
+ platform header. */
+
+
+#endif /* __ACENV_H__ */
--- /dev/null
- __MINGW_IMPORT void __set_app_type(int);
+/*
+ * crt1.c
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is a part of the mingw-runtime package.
+ * No warranty is given; refer to the file DISCLAIMER within the package.
+ *
+ * Source code for the startup proceedures used by all programs. This code
+ * is compiled to make crt1.o, which should be located in the library path.
+ *
+ */
+
+/* Hide the declaration of _fmode with dllimport attribute in stdlib.h to
+ avoid problems with older GCC. */
+#define __IN_MINGW_RUNTIME
+#include <stdlib.h>
+#include <stdio.h>
+#include <io.h>
+#include <process.h>
+#include <float.h>
+#include <math.h>
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <signal.h>
+
+/* NOTE: The code for initializing the _argv, _argc, and environ variables
+ * has been moved to a separate .c file which is included in both
+ * crt1.c and dllcrt1.c. This means changes in the code don't have to
+ * be manually synchronized, but it does lead to this not-generally-
+ * a-good-idea use of include. */
+#include "winit.c"
+#include "cpu_features.h"
+
+extern void _pei386_runtime_relocator (void);
+
+extern int wmain (int, wchar_t **, wchar_t **);
+
+/*
+ * Must have the correct app type for MSVCRT.
+ */
+
+#ifdef __MSVCRT__
+#define __UNKNOWN_APP 0
+#define __CONSOLE_APP 1
+#define __GUI_APP 2
- static void __attribute__((noreturn))
++_CRTIMP void __set_app_type(int);
+#endif /* __MSVCRT__ */
+
+/* Global _fmode for this .exe, not the one in msvcrt.dll,
+ The default is set in txtmode.o in libmingw32.a */
+/* Override the dllimport'd declarations in stdlib.h */
+#undef _fmode
+extern int _fmode;
+#ifdef __MSVCRT__
+extern int* __p__fmode(void); /* To access the dll _fmode */
+#endif
+
+/*
+ * Setup the default file handles to have the _CRT_fmode mode, as well as
+ * any new files created by the user.
+ */
+extern int _CRT_fmode;
+
+static void
+_mingw32_init_fmode (void)
+{
+ /* Don't set the std file mode if the user hasn't set any value for it. */
+ if (_CRT_fmode)
+ {
+ _fmode = _CRT_fmode;
+
+ /*
+ * This overrides the default file mode settings for stdin,
+ * stdout and stderr. At first I thought you would have to
+ * test with isatty, but it seems that the DOS console at
+ * least is smart enough to handle _O_BINARY stdout and
+ * still display correctly.
+ */
+ if (stdin)
+ {
+ _setmode (_fileno (stdin), _CRT_fmode);
+ }
+ if (stdout)
+ {
+ _setmode (_fileno (stdout), _CRT_fmode);
+ }
+ if (stderr)
+ {
+ _setmode (_fileno (stderr), _CRT_fmode);
+ }
+ }
+
+ /* Now sync the dll _fmode to the one for this .exe. */
+#ifdef __MSVCRT__
+ *__p__fmode() = _fmode;
+#else
+ *_imp___fmode_dll = _fmode;
+#endif
+}
+
+/* This function will be called when a trap occurs. Thanks to Jacob
+ Navia for his contribution. */
+static LONG CALLBACK
+_gnu_exception_handler (EXCEPTION_POINTERS * exception_data)
+{
+ void (*old_handler) (int);
+ LONG action = EXCEPTION_CONTINUE_SEARCH;
+ int reset_fpu = 0;
+
+ switch (exception_data->ExceptionRecord->ExceptionCode)
+ {
+ case EXCEPTION_ACCESS_VIOLATION:
+ /* test if the user has set SIGSEGV */
+ old_handler = signal (SIGSEGV, SIG_DFL);
+ if (old_handler == SIG_IGN)
+ {
+ /* this is undefined if the signal was raised by anything other
+ than raise (). */
+ signal (SIGSEGV, SIG_IGN);
+ action = EXCEPTION_CONTINUE_EXECUTION;
+ }
+ else if (old_handler != SIG_DFL)
+ {
+ /* This means 'old' is a user defined function. Call it */
+ (*old_handler) (SIGSEGV);
+ action = EXCEPTION_CONTINUE_EXECUTION;
+ }
+ break;
+
+ case EXCEPTION_ILLEGAL_INSTRUCTION:
+ case EXCEPTION_PRIV_INSTRUCTION:
+ /* test if the user has set SIGILL */
+ old_handler = signal (SIGILL, SIG_DFL);
+ if (old_handler == SIG_IGN)
+ {
+ /* this is undefined if the signal was raised by anything other
+ than raise (). */
+ signal (SIGILL, SIG_IGN);
+ action = EXCEPTION_CONTINUE_EXECUTION;
+ }
+ else if (old_handler != SIG_DFL)
+ {
+ /* This means 'old' is a user defined function. Call it */
+ (*old_handler) (SIGILL);
+ action = EXCEPTION_CONTINUE_EXECUTION;
+ }
+ break;
+
+ case EXCEPTION_FLT_INVALID_OPERATION:
+ case EXCEPTION_FLT_DIVIDE_BY_ZERO:
+ case EXCEPTION_FLT_DENORMAL_OPERAND:
+ case EXCEPTION_FLT_OVERFLOW:
+ case EXCEPTION_FLT_UNDERFLOW:
+ case EXCEPTION_FLT_INEXACT_RESULT:
+ reset_fpu = 1;
+ /* fall through. */
+
+ case EXCEPTION_INT_DIVIDE_BY_ZERO:
+ /* test if the user has set SIGFPE */
+ old_handler = signal (SIGFPE, SIG_DFL);
+ if (old_handler == SIG_IGN)
+ {
+ signal (SIGFPE, SIG_IGN);
+ if (reset_fpu)
+ _fpreset ();
+ action = EXCEPTION_CONTINUE_EXECUTION;
+ }
+ else if (old_handler != SIG_DFL)
+ {
+ /* This means 'old' is a user defined function. Call it */
+ (*old_handler) (SIGFPE);
+ action = EXCEPTION_CONTINUE_EXECUTION;
+ }
+ break;
+
+ default:
+ break;
+ }
+ return action;
+}
+
+/*
+ * The function mainCRTStartup is the entry point for all console programs.
+ */
++static void __declspec(noreturn)
+__mingw_wCRTStartup (void)
+{
+ int nRet;
+
+ /*
+ * Set up the top-level exception handler so that signal handling
+ * works as expected. The mapping between ANSI/POSIX signals and
+ * Win32 SE is not 1-to-1, so caveat emptore.
+ *
+ */
+ SetUnhandledExceptionFilter (_gnu_exception_handler);
+
+ /*
+ * Initialize floating point unit.
+ */
+ __cpu_features_init (); /* Do we have SSE, etc.*/
+ _fpreset (); /* Supplied by the runtime library. */
+
+ /*
+ * Set up __argc, __argv and _wenviron.
+ */
+ _mingw32_init_wmainargs ();
+
+ /*
+ * Sets the default file mode.
+ * If _CRT_fmode is set, also set mode for stdin, stdout
+ * and stderr, as well
+ * NOTE: DLLs don't do this because that would be rude!
+ */
+ _mingw32_init_fmode ();
+
+ /* Adust references to dllimported data that have non-zero offsets. */
+#if defined(__i386__)
+ _pei386_runtime_relocator ();
+#endif
+
++#if defined(__GNUC__)
+#if defined(__i386__)
+ /* Align the stack to 16 bytes for the sake of SSE ops in main
+ or in functions inlined into main. */
+ asm __volatile__ ("andl $-16, %%esp" : : : "%esp");
+#elif defined(__mips__)
+ /* Align the stack to 16 bytes */
+ asm __volatile__ ("andi %sp,%sp,-16" : : : "%sp");
+#elif defined(__PowerPC__)
+ /* Align the stack to 16 bytes */
+ asm __volatile__ ("li 0,15\n\tandc 1,1,0" : : : "r1");
+#else
+#error Unsupported architecture
++#endif
++#endif
++
++#if defined(_MSC_VER)
++#if defined(_M_IX86)
++ /* Align the stack to 16 bytes for the sake of SSE ops in main
++ or in functions inlined into main. */
++ __asm and esp, 0FFFFFFF0h
++#else
++#error Unsupported architecture
++#endif
+#endif
+
+ /*
+ * Call the main function. If the user does not supply one
+ * the one in the 'libmingw32.a' library will be linked in, and
+ * that one calls WinMain. See main.c in the 'lib' dir
+ * for more details.
+ */
+ nRet = wmain (_argc, _wargv, _wenviron);
+
+ /*
+ * Perform exit processing for the C library. This means
+ * flushing output and calling 'atexit' registered functions.
+ */
+ _cexit ();
+
+ ExitProcess (nRet);
+}
+
+/*
+ * The function mainCRTStartup is the entry point for all console programs.
+ */
+void
+wmainCRTStartup (void)
+{
+#ifdef __MSVCRT__
+ __set_app_type (__CONSOLE_APP);
+#endif
+ __mingw_wCRTStartup ();
+}
+
+/*
+ * For now the GUI startup function is the same as the console one.
+ * This simply gets rid of the annoying warning about not being able
+ * to find WinMainCRTStartup when linking GUI applications.
+ */
+void
+wWinMainCRTStartup (void)
+{
+#ifdef __MSVCRT__
+ __set_app_type (__GUI_APP);
+#endif
+ __mingw_wCRTStartup ();
+}
+
+#if 0
+/*
+ * We force use of library version of atexit, which is only
+ * visible in import lib as _imp__atexit
+ */
+extern int (*_imp__atexit)(void (*)(void));
+int atexit (void (* pfn )(void) )
+{
+ return ( (*_imp__atexit)(pfn));
+}
+
+/* Likewise for non-ANSI _onexit */
+extern _onexit_t (*_imp___onexit)(_onexit_t);
+_onexit_t
+_onexit (_onexit_t pfn )
+{
+ return (*_imp___onexit)(pfn);
+}
+#endif