Commit 628d4450 authored by Alexandre Julliard's avatar Alexandre Julliard

kernel32: Move file mapping functions to kernelbase.

parent aa7f8e93
......@@ -285,7 +285,7 @@
@ stdcall CreateFileMappingA(long ptr long long long str)
# @ stub CreateFileMappingNumaA
# @ stub CreateFileMappingNumaW
@ stdcall CreateFileMappingW(long ptr long long long wstr)
@ stdcall -import CreateFileMappingW(long ptr long long long wstr)
@ stdcall CreateFileW(wstr long long ptr long long long)
@ stdcall CreateHardLinkA(str str ptr)
@ stdcall CreateHardLinkTransactedA(str str ptr ptr)
......@@ -1117,7 +1117,7 @@
@ stdcall OpenFile(str ptr long)
@ stdcall OpenFileById(long ptr long long ptr long)
@ stdcall OpenFileMappingA(long long str)
@ stdcall OpenFileMappingW(long long wstr)
@ stdcall -import OpenFileMappingW(long long wstr)
@ stdcall OpenJobObjectA(long long str)
@ stdcall OpenJobObjectW(long long wstr)
@ stdcall OpenMutexA(long long str)
......
......@@ -663,73 +663,6 @@ HANDLE WINAPI CreateFileMappingA( HANDLE file, SECURITY_ATTRIBUTES *sa, DWORD pr
/***********************************************************************
* CreateFileMappingW (KERNEL32.@)
*/
HANDLE WINAPI CreateFileMappingW( HANDLE file, LPSECURITY_ATTRIBUTES sa, DWORD protect,
DWORD size_high, DWORD size_low, LPCWSTR name )
{
static const int sec_flags = (SEC_FILE | SEC_IMAGE | SEC_RESERVE | SEC_COMMIT |
SEC_NOCACHE | SEC_WRITECOMBINE | SEC_LARGE_PAGES);
HANDLE ret;
NTSTATUS status;
DWORD access, sec_type;
LARGE_INTEGER size;
UNICODE_STRING nameW;
OBJECT_ATTRIBUTES attr;
sec_type = protect & sec_flags;
protect &= ~sec_flags;
if (!sec_type) sec_type = SEC_COMMIT;
/* Win9x compatibility */
if (!protect && !is_version_nt()) protect = PAGE_READONLY;
switch(protect)
{
case PAGE_READONLY:
case PAGE_WRITECOPY:
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ;
break;
case PAGE_READWRITE:
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE;
break;
case PAGE_EXECUTE_READ:
case PAGE_EXECUTE_WRITECOPY:
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_EXECUTE;
break;
case PAGE_EXECUTE_READWRITE:
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE | SECTION_MAP_EXECUTE;
break;
default:
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
size.u.LowPart = size_low;
size.u.HighPart = size_high;
if (file == INVALID_HANDLE_VALUE)
{
file = 0;
if (!size.QuadPart)
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
}
get_create_object_attributes( &attr, &nameW, sa, name );
status = NtCreateSection( &ret, access, &attr, &size, protect, sec_type, file );
if (status == STATUS_OBJECT_NAME_EXISTS)
SetLastError( ERROR_ALREADY_EXISTS );
else
SetLastError( RtlNtStatusToDosError(status) );
return ret;
}
/***********************************************************************
* OpenFileMappingA (KERNEL32.@)
*/
HANDLE WINAPI OpenFileMappingA( DWORD access, BOOL inherit, LPCSTR name )
......@@ -747,36 +680,6 @@ HANDLE WINAPI OpenFileMappingA( DWORD access, BOOL inherit, LPCSTR name )
}
/***********************************************************************
* OpenFileMappingW (KERNEL32.@)
*/
HANDLE WINAPI OpenFileMappingW( DWORD access, BOOL inherit, LPCWSTR name )
{
OBJECT_ATTRIBUTES attr;
UNICODE_STRING nameW;
HANDLE ret;
NTSTATUS status;
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
if (access == FILE_MAP_COPY) access = SECTION_MAP_READ;
if (!is_version_nt())
{
/* win9x doesn't do access checks, so try with full access first */
if (!NtOpenSection( &ret, access | SECTION_MAP_READ | SECTION_MAP_WRITE, &attr )) return ret;
}
status = NtOpenSection( &ret, access, &attr );
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return 0;
}
return ret;
}
/*
* Pipes
*/
......
......@@ -189,7 +189,7 @@
@ stdcall CreateFileA(str long long ptr long long long) kernel32.CreateFileA
# @ stub CreateFileMappingFromApp
@ stub CreateFileMappingNumaW
@ stdcall CreateFileMappingW(long ptr long long long wstr) kernel32.CreateFileMappingW
@ stdcall CreateFileMappingW(long ptr long long long wstr)
@ stdcall CreateFileW(wstr long long ptr long long long) kernel32.CreateFileW
@ stdcall CreateHardLinkA(str str ptr) kernel32.CreateHardLinkA
@ stdcall CreateHardLinkW(wstr wstr ptr) kernel32.CreateHardLinkW
......@@ -985,7 +985,7 @@
@ stdcall OpenEventW(long long wstr)
@ stdcall OpenFileById(long ptr long long ptr long) kernel32.OpenFileById
# @ stub OpenFileMappingFromApp
@ stdcall OpenFileMappingW(long long wstr) kernel32.OpenFileMappingW
@ stdcall OpenFileMappingW(long long wstr)
# @ stub OpenGlobalizationUserSettingsKey
@ stdcall OpenMutexW(long long wstr)
# @ stub OpenPackageInfoByFullName
......
......@@ -617,3 +617,105 @@ BOOL WINAPI DECLSPEC_HOTPATCH InitializeCriticalSectionEx( CRITICAL_SECTION *cri
if (ret) RtlRaiseStatus( ret );
return !ret;
}
/***********************************************************************
* File mappings
***********************************************************************/
/***********************************************************************
* CreateFileMappingW (kernelbase.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH CreateFileMappingW( HANDLE file, LPSECURITY_ATTRIBUTES sa, DWORD protect,
DWORD size_high, DWORD size_low, LPCWSTR name )
{
static const int sec_flags = (SEC_FILE | SEC_IMAGE | SEC_RESERVE | SEC_COMMIT |
SEC_NOCACHE | SEC_WRITECOMBINE | SEC_LARGE_PAGES);
HANDLE ret;
NTSTATUS status;
DWORD access, sec_type;
LARGE_INTEGER size;
UNICODE_STRING nameW;
OBJECT_ATTRIBUTES attr;
sec_type = protect & sec_flags;
protect &= ~sec_flags;
if (!sec_type) sec_type = SEC_COMMIT;
/* Win9x compatibility */
if (!protect && !is_version_nt()) protect = PAGE_READONLY;
switch(protect)
{
case PAGE_READONLY:
case PAGE_WRITECOPY:
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ;
break;
case PAGE_READWRITE:
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE;
break;
case PAGE_EXECUTE_READ:
case PAGE_EXECUTE_WRITECOPY:
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_EXECUTE;
break;
case PAGE_EXECUTE_READWRITE:
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE | SECTION_MAP_EXECUTE;
break;
default:
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
size.u.LowPart = size_low;
size.u.HighPart = size_high;
if (file == INVALID_HANDLE_VALUE)
{
file = 0;
if (!size.QuadPart)
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
}
get_create_object_attributes( &attr, &nameW, sa, name );
status = NtCreateSection( &ret, access, &attr, &size, protect, sec_type, file );
if (status == STATUS_OBJECT_NAME_EXISTS)
SetLastError( ERROR_ALREADY_EXISTS );
else
SetLastError( RtlNtStatusToDosError(status) );
return ret;
}
/***********************************************************************
* OpenFileMappingW (kernelbase.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH OpenFileMappingW( DWORD access, BOOL inherit, LPCWSTR name )
{
OBJECT_ATTRIBUTES attr;
UNICODE_STRING nameW;
HANDLE ret;
NTSTATUS status;
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
if (access == FILE_MAP_COPY) access = SECTION_MAP_READ;
if (!is_version_nt())
{
/* win9x doesn't do access checks, so try with full access first */
if (!NtOpenSection( &ret, access | SECTION_MAP_READ | SECTION_MAP_WRITE, &attr )) return ret;
}
status = NtOpenSection( &ret, access, &attr );
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return 0;
}
return ret;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment