Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined symbol: MapViewOfFile2 #22040

Open
zux0x3a opened this issue Nov 20, 2024 · 6 comments
Open

undefined symbol: MapViewOfFile2 #22040

zux0x3a opened this issue Nov 20, 2024 · 6 comments
Labels
error message This issue points out an error message that is unhelpful and should be improved.

Comments

@zux0x3a
Copy link

zux0x3a commented Nov 20, 2024

Zig Version

0.13.0

Steps to Reproduce and Observed Output

it seems MapViewOfFile2 is not declared or linked into Zig code base yet, currently i am declaring it externally :

pub extern "kernel32" fn MapViewOfFile2(
    FileMappingHandle: HANDLE,
    ProcessHandle: HANDLE,
    Offset: u64, 
    BaseAddress: ?*anyopaque, 
    ViewSize: usize, // SIZE_T
    AllocationType: u32, // ULONG
    PageProtection: u32, // ULONG
) callconv(WINAPI) ?*anyopaque; 

raising the following linking error :

error: warning(link): unexpected LLD stderr:
lld-link: warning: undefined symbol: MapViewOfFile2

any alternative solution? if we imported the C headeand then call it from it's name space should be a temporary solution?

Expected Output

error: warning(link): unexpected LLD stderr:
lld-link: warning: undefined symbol: MapViewOfFile2

@zux0x3a zux0x3a added the error message This issue points out an error message that is unhelpful and should be improved. label Nov 20, 2024
@zux0x3a
Copy link
Author

zux0x3a commented Nov 20, 2024

@nektro
Copy link
Contributor

nektro commented Nov 20, 2024

@zux0x3a
Copy link
Author

zux0x3a commented Nov 20, 2024

@nektro I think you are referring to the following

pub extern "api-ms-win-core-memory-l1-1-5" fn UnmapViewOfFile2(
    Process: ?HANDLE,
    BaseAddress: ?*anyopaque,
    UnmapFlags: UNMAP_VIEW_OF_FILE_FLAGS,
) callconv(@import("std").os.windows.WINAPI) BOOL;

and thats limited to windows10.0.15063 check out here : https://github.com/marlersoft/zigwin32/blob/32d085ee67374ad2ec24fc012e6876ca27958fb7/win32/system/memory.zig#L1098

@mesidex
Copy link

mesidex commented Nov 24, 2024

As a workaround, does NtMapViewOfSection suit your use case?

pub extern "ntdll" fn NtMapViewOfSection(

@zux0x3a
Copy link
Author

zux0x3a commented Nov 24, 2024

@mesidex NtMapViewofSection is different than MapViewFile2, however i managed to make it work with following extern API inline call.

https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-mapviewoffilenuma2

pub extern "api-ms-win-core-memory-l1-1-5" fn MapViewOfFileNuma2(
    FileMappingHandle: HANDLE,
    ProcessHandle: HANDLE,
    Offset: u64, // ULONG64
    BaseAddress: ?*anyopaque, // PVOID (optional)
    ViewSize: usize, // SIZE_T
    AllocationType: u32, // ULONG
    PageProtection: u32, // ULONG
) callconv(windows.WINAPI) ?*anyopaque; // Returns PVOID

@vtorri
Copy link

vtorri commented Dec 4, 2024

I have it:

$ fgrep -r MapViewOfFile2 /mingw64/include/memoryapi.h
  WINBASEAPI PVOID MapViewOfFile2(HANDLE FileMappingHandle, HANDLE ProcessHandle, ULONG64 Offset, PVOID BaseAddress, SIZE_T ViewSize, ULONG AllocationType, ULONG PageProtection);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Projects
None yet
Development

No branches or pull requests

4 participants