Skip to content

llvm_asm! removed from nightly. #2

Open
@Nordgaren

Description

@Nordgaren

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions