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

llvm_asm! removed from nightly. #2

Open
Nordgaren opened this issue May 23, 2023 · 1 comment
Open

llvm_asm! removed from nightly. #2

Nordgaren opened this issue May 23, 2023 · 1 comment

Comments

@Nordgaren
Copy link

Nordgaren commented May 23, 2023

Since llvm_asm! was removed from nightly, this can no longer be compiled on the nightly compiler.

I found that this forces you to keep a static mut FARPROC for each function you export, and the new asm!() block looks like this. Unfortunately, Intel syntax would not generate the correct assm with jmp [{}]. Even if I used an identifier.

pub static mut pGetdfDIJoystick: FARPROC = 0 as FARPROC;

#[naked]
#[no_mangle]
pub extern "system" fn GetdfDIJoystick() {
    unsafe {
        asm!(
        "jmpq  *{}(%rip)",
        sym pGetdfDIJoystick,
        options(noreturn, att_syntax),
        );
    }
}

I also found GetdfDIJoystick can be added to the list of exports, too.

and my init_dinput8() function looks like this

pub const MAX_PATH: usize = 260;

pub unsafe fn init_dinput8() {
    let buffer = [0u8; MAX_PATH + 1];
    let path_size = GetWindowsDirectoryA(buffer.as_ptr() as LPSTR, MAX_PATH as u32 + 1) as usize;
    let dir = &buffer[..path_size];
    let dinput = LoadLibraryA(
        format!(
            "{}\\System32\\dinput8.dll\0",
            std::str::from_utf8(dir).unwrap_or_default()
        )
            .as_ptr() as *const i8,
    );

    if dinput.is_null() {
        panic!("Could not find dinput8.dll.");
    }
    let module = GetModuleHandleA(0 as *const i8) as usize;

    pDirectInput8Create = GetProcAddress(dinput, b"DirectInput8Create\0".as_ptr() as *const i8);
    pDllCanUnloadNow = GetProcAddress(dinput, b"DllCanUnloadNow\0".as_ptr() as *const i8);
    pDllGetClassObject = GetProcAddress(dinput, b"DllGetClassObject\0".as_ptr() as *const i8);
    pDllRegisterServer = GetProcAddress(dinput, b"DllRegisterServer\0".as_ptr() as *const i8);
    pDllUnregisterServer = GetProcAddress(dinput, b"DllUnregisterServer\0".as_ptr() as *const i8);
    pGetdfDIJoystick = GetProcAddress(dinput, b"GetdfDIJoystick\0".as_ptr() as *const i8);
}

Hope this helps! If you want a proper update, but don't wanna do it, let me know and I will fork this and send a PR!

@Nordgaren
Copy link
Author

Might also be able to get rid of naked and nightly compiler, if using some specific options for asm!, but I am not sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant