diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec index ebc2cea3351..7808cdc5495 100644 --- a/dlls/kernel32/kernel32.spec +++ b/dlls/kernel32/kernel32.spec @@ -365,7 +365,7 @@ # @ stub DeleteFileTransactedA # @ stub DeleteFileTransactedW @ stdcall DeleteFileW(wstr) -@ stdcall DeleteProcThreadAttributeList(ptr) +@ stdcall -import DeleteProcThreadAttributeList(ptr) # @ stub DisableThreadProfiling @ stdcall DisassociateCurrentThreadFromCallback(ptr) ntdll.TpDisassociateCallback @ stdcall DeleteTimerQueue(long) @@ -949,7 +949,7 @@ @ stdcall InitializeCriticalSection(ptr) ntdll.RtlInitializeCriticalSection @ stdcall -import InitializeCriticalSectionAndSpinCount(ptr long) @ stdcall -import InitializeCriticalSectionEx(ptr long long) -@ stdcall InitializeProcThreadAttributeList(ptr long long ptr) +@ stdcall -import InitializeProcThreadAttributeList(ptr long long ptr) @ stdcall InitializeSListHead(ptr) ntdll.RtlInitializeSListHead @ stdcall InitializeSRWLock(ptr) ntdll.RtlInitializeSRWLock @ stdcall -arch=i386 InterlockedCompareExchange (ptr long long) @@ -1543,7 +1543,7 @@ @ stdcall UnregisterWait(long) @ stdcall -import UnregisterWaitEx(long long) # @ stub UpdateCalendarDayOfWeek -@ stdcall UpdateProcThreadAttribute(ptr long long ptr long ptr ptr) +@ stdcall -import UpdateProcThreadAttribute(ptr long long ptr long ptr ptr) @ stdcall UpdateResourceA(long str str long ptr long) @ stdcall UpdateResourceW(long wstr wstr long ptr long) @ stub VDMConsoleOperation diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c index d482f5b16a6..992437047f7 100644 --- a/dlls/kernel32/process.c +++ b/dlls/kernel32/process.c @@ -4113,135 +4113,6 @@ HRESULT WINAPI UnregisterApplicationRestart(void) return S_OK; } -struct proc_thread_attr -{ - DWORD_PTR attr; - SIZE_T size; - void *value; -}; - -struct _PROC_THREAD_ATTRIBUTE_LIST -{ - DWORD mask; /* bitmask of items in list */ - DWORD size; /* max number of items in list */ - DWORD count; /* number of items in list */ - DWORD pad; - DWORD_PTR unk; - struct proc_thread_attr attrs[1]; -}; - -/*********************************************************************** - * InitializeProcThreadAttributeList (KERNEL32.@) - */ -BOOL WINAPI InitializeProcThreadAttributeList(struct _PROC_THREAD_ATTRIBUTE_LIST *list, - DWORD count, DWORD flags, SIZE_T *size) -{ - SIZE_T needed; - BOOL ret = FALSE; - - TRACE("(%p %d %x %p)\n", list, count, flags, size); - - needed = FIELD_OFFSET(struct _PROC_THREAD_ATTRIBUTE_LIST, attrs[count]); - if (list && *size >= needed) - { - list->mask = 0; - list->size = count; - list->count = 0; - list->unk = 0; - ret = TRUE; - } - else - SetLastError(ERROR_INSUFFICIENT_BUFFER); - - *size = needed; - return ret; -} - -/*********************************************************************** - * UpdateProcThreadAttribute (KERNEL32.@) - */ -BOOL WINAPI UpdateProcThreadAttribute(struct _PROC_THREAD_ATTRIBUTE_LIST *list, - DWORD flags, DWORD_PTR attr, void *value, SIZE_T size, - void *prev_ret, SIZE_T *size_ret) -{ - DWORD mask; - struct proc_thread_attr *entry; - - TRACE("(%p %x %08lx %p %ld %p %p)\n", list, flags, attr, value, size, prev_ret, size_ret); - - if (list->count >= list->size) - { - SetLastError(ERROR_GEN_FAILURE); - return FALSE; - } - - switch (attr) - { - case PROC_THREAD_ATTRIBUTE_PARENT_PROCESS: - if (size != sizeof(HANDLE)) - { - SetLastError(ERROR_BAD_LENGTH); - return FALSE; - } - break; - - case PROC_THREAD_ATTRIBUTE_HANDLE_LIST: - if ((size / sizeof(HANDLE)) * sizeof(HANDLE) != size) - { - SetLastError(ERROR_BAD_LENGTH); - return FALSE; - } - break; - - case PROC_THREAD_ATTRIBUTE_IDEAL_PROCESSOR: - if (size != sizeof(PROCESSOR_NUMBER)) - { - SetLastError(ERROR_BAD_LENGTH); - return FALSE; - } - break; - - case PROC_THREAD_ATTRIBUTE_CHILD_PROCESS_POLICY: - if (size != sizeof(DWORD) && size != sizeof(DWORD64)) - { - SetLastError(ERROR_BAD_LENGTH); - return FALSE; - } - break; - - case PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY: - if (size != sizeof(DWORD) && size != sizeof(DWORD64) && size != sizeof(DWORD64) * 2) - { - SetLastError(ERROR_BAD_LENGTH); - return FALSE; - } - break; - - default: - SetLastError(ERROR_NOT_SUPPORTED); - FIXME("Unhandled attribute number %lu\n", attr & PROC_THREAD_ATTRIBUTE_NUMBER); - return FALSE; - } - - mask = 1 << (attr & PROC_THREAD_ATTRIBUTE_NUMBER); - - if (list->mask & mask) - { - SetLastError(ERROR_OBJECT_NAME_EXISTS); - return FALSE; - } - - list->mask |= mask; - - entry = list->attrs + list->count; - entry->attr = attr; - entry->size = size; - entry->value = value; - list->count++; - - return TRUE; -} - /*********************************************************************** * CreateUmsCompletionList (KERNEL32.@) */ @@ -4262,14 +4133,6 @@ BOOL WINAPI CreateUmsThreadContext(PUMS_CONTEXT *ctx) return FALSE; } -/*********************************************************************** - * DeleteProcThreadAttributeList (KERNEL32.@) - */ -void WINAPI DeleteProcThreadAttributeList(struct _PROC_THREAD_ATTRIBUTE_LIST *list) -{ - return; -} - /*********************************************************************** * DeleteUmsCompletionList (KERNEL32.@) */ diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec index 7609d9fda70..89dcc82f9e4 100644 --- a/dlls/kernelbase/kernelbase.spec +++ b/dlls/kernelbase/kernelbase.spec @@ -252,7 +252,7 @@ @ stdcall DeleteFiber(ptr) @ stdcall DeleteFileA(str) kernel32.DeleteFileA @ stdcall DeleteFileW(wstr) kernel32.DeleteFileW -@ stdcall DeleteProcThreadAttributeList(ptr) kernel32.DeleteProcThreadAttributeList +@ stdcall DeleteProcThreadAttributeList(ptr) # @ stub DeleteStateAtomValue # @ stub DeleteStateContainer # @ stub DeleteStateContainerValue @@ -805,7 +805,7 @@ @ stdcall InitializeCriticalSectionAndSpinCount(ptr long) @ stdcall InitializeCriticalSectionEx(ptr long long) # @ stub InitializeEnclave -@ stdcall InitializeProcThreadAttributeList(ptr long long ptr) kernel32.InitializeProcThreadAttributeList +@ stdcall InitializeProcThreadAttributeList(ptr long long ptr) # @ stub InitializeProcessForWsWatch @ stdcall InitializeSListHead(ptr) ntdll.RtlInitializeSListHead @ stdcall InitializeSRWLock(ptr) ntdll.RtlInitializeSRWLock @@ -1627,7 +1627,7 @@ # @ stub UnsubscribeStateChangeNotification # @ stub UpdatePackageStatus # @ stub UpdatePackageStatusForUser -@ stdcall UpdateProcThreadAttribute(ptr long long ptr long ptr ptr) kernel32.UpdateProcThreadAttribute +@ stdcall UpdateProcThreadAttribute(ptr long long ptr long ptr ptr) @ stdcall UrlApplySchemeA(str ptr ptr long) @ stdcall UrlApplySchemeW(wstr ptr ptr long) @ stdcall UrlCanonicalizeA(str ptr ptr long) diff --git a/dlls/kernelbase/process.c b/dlls/kernelbase/process.c index 4c5cb812974..8423a543bc1 100644 --- a/dlls/kernelbase/process.c +++ b/dlls/kernelbase/process.c @@ -344,3 +344,144 @@ BOOL WINAPI DECLSPEC_HOTPATCH TerminateProcess( HANDLE handle, DWORD exit_code ) } return set_ntstatus( NtTerminateProcess( handle, exit_code )); } + + +/*********************************************************************** + * Process/thread attribute lists + ***********************************************************************/ + + +struct proc_thread_attr +{ + DWORD_PTR attr; + SIZE_T size; + void *value; +}; + +struct _PROC_THREAD_ATTRIBUTE_LIST +{ + DWORD mask; /* bitmask of items in list */ + DWORD size; /* max number of items in list */ + DWORD count; /* number of items in list */ + DWORD pad; + DWORD_PTR unk; + struct proc_thread_attr attrs[1]; +}; + +/*********************************************************************** + * InitializeProcThreadAttributeList (kernelbase.@) + */ +BOOL WINAPI DECLSPEC_HOTPATCH InitializeProcThreadAttributeList( struct _PROC_THREAD_ATTRIBUTE_LIST *list, + DWORD count, DWORD flags, SIZE_T *size ) +{ + SIZE_T needed; + BOOL ret = FALSE; + + TRACE( "(%p %d %x %p)\n", list, count, flags, size ); + + needed = FIELD_OFFSET( struct _PROC_THREAD_ATTRIBUTE_LIST, attrs[count] ); + if (list && *size >= needed) + { + list->mask = 0; + list->size = count; + list->count = 0; + list->unk = 0; + ret = TRUE; + } + else SetLastError( ERROR_INSUFFICIENT_BUFFER ); + + *size = needed; + return ret; +} + + +/*********************************************************************** + * UpdateProcThreadAttribute (kernelbase.@) + */ +BOOL WINAPI DECLSPEC_HOTPATCH UpdateProcThreadAttribute( struct _PROC_THREAD_ATTRIBUTE_LIST *list, + DWORD flags, DWORD_PTR attr, void *value, + SIZE_T size, void *prev_ret, SIZE_T *size_ret ) +{ + DWORD mask; + struct proc_thread_attr *entry; + + TRACE( "(%p %x %08lx %p %ld %p %p)\n", list, flags, attr, value, size, prev_ret, size_ret ); + + if (list->count >= list->size) + { + SetLastError( ERROR_GEN_FAILURE ); + return FALSE; + } + + switch (attr) + { + case PROC_THREAD_ATTRIBUTE_PARENT_PROCESS: + if (size != sizeof(HANDLE)) + { + SetLastError( ERROR_BAD_LENGTH ); + return FALSE; + } + break; + + case PROC_THREAD_ATTRIBUTE_HANDLE_LIST: + if ((size / sizeof(HANDLE)) * sizeof(HANDLE) != size) + { + SetLastError( ERROR_BAD_LENGTH ); + return FALSE; + } + break; + + case PROC_THREAD_ATTRIBUTE_IDEAL_PROCESSOR: + if (size != sizeof(PROCESSOR_NUMBER)) + { + SetLastError( ERROR_BAD_LENGTH ); + return FALSE; + } + break; + + case PROC_THREAD_ATTRIBUTE_CHILD_PROCESS_POLICY: + if (size != sizeof(DWORD) && size != sizeof(DWORD64)) + { + SetLastError( ERROR_BAD_LENGTH ); + return FALSE; + } + break; + + case PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY: + if (size != sizeof(DWORD) && size != sizeof(DWORD64) && size != sizeof(DWORD64) * 2) + { + SetLastError( ERROR_BAD_LENGTH ); + return FALSE; + } + break; + + default: + SetLastError( ERROR_NOT_SUPPORTED ); + FIXME( "Unhandled attribute %lu\n", attr & PROC_THREAD_ATTRIBUTE_NUMBER ); + return FALSE; + } + + mask = 1 << (attr & PROC_THREAD_ATTRIBUTE_NUMBER); + if (list->mask & mask) + { + SetLastError( ERROR_OBJECT_NAME_EXISTS ); + return FALSE; + } + list->mask |= mask; + + entry = list->attrs + list->count; + entry->attr = attr; + entry->size = size; + entry->value = value; + list->count++; + return TRUE; +} + + +/*********************************************************************** + * DeleteProcThreadAttributeList (kernelbase.@) + */ +void WINAPI DECLSPEC_HOTPATCH DeleteProcThreadAttributeList( struct _PROC_THREAD_ATTRIBUTE_LIST *list ) +{ + return; +}