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

Not starting on x64 with low memory #1898

Open
dchristl opened this issue Oct 24, 2023 · 6 comments
Open

Not starting on x64 with low memory #1898

dchristl opened this issue Oct 24, 2023 · 6 comments

Comments

@dchristl
Copy link

Hello,

thanks for this great project.
I'm currently trying out pypush in the cloud. It uses Unicorn internally but cannot start because an error occurs:

Could not allocate dynamic translation buffer
The server I'm trying this on is hosted in the Oracle Cloud (Free Tier with 1 x64 processor and 1 GB of RAM). If I interpret the Unicorn source correctly, it automatically reserves 1 GB of RAM upon startup for an x64 processor (DEFAULT_CODE_GEN_BUFFER_SIZE_1). However, since the server is very limited and cannot afford this, it results in this error.
Furthermore, I came across this comment in the code:

We expect most system emulation to run one or two guests per host. Users running large scale system emulation may want to tweak their runtime setup via the tb-size control on the command line.

How can I set the 'tb-size' parameter using the Python bindings, or is there a better alternative to run this on a limited system?

Kind Regards
Danny

@wtdcode
Copy link
Member

wtdcode commented Oct 24, 2023

This has been resolved in our dev branch while not released. You could build it by yourself with: https://github.com/unicorn-engine/unicorn/wiki/Compile#build-python-bindings

@dchristl
Copy link
Author

Thank you, I will try it out.

@dchristl
Copy link
Author

Sorry, there is exact the same issue with the dev-Version (2.0.2). I've reinstalled it many times and cleared the cache and left folders. Any advice?

@wtdcode
Copy link
Member

wtdcode commented Nov 14, 2023

That's weird. I have exactly the same Oracle instance and it works well.

@dchristl
Copy link
Author

Could you point me to the commit, where this should be solved? There are not really changes any near to the code with the issue. I will debug the current release and the dev-version, but I don't think there will be any difference in the output/ memory consumption.

@hInfern0
Copy link

hInfern0 commented Nov 21, 2023

I don't think its only on x64 when i am even trying with arm like with go , rust and python it takes like 1gb of ram with the smallest memory map i tried the sample from rust

use unicorn_engine::{Unicorn, RegisterARM};
use unicorn_engine::unicorn_const::{Arch, Mode, Permission, SECOND_SCALE};
use std::{thread, time};

fn main() {
    let arm_code32: Vec<u8> = vec![0x17, 0x00, 0x40, 0xe2]; // sub r0, #23

    let mut unicorn = Unicorn::new(Arch::ARM, Mode::LITTLE_ENDIAN).expect("failed to initialize Unicorn instance");
    let emu = &mut unicorn;
    emu.mem_map(0x1000, 0x4000, Permission::ALL).expect("failed to map code page");
    emu.mem_write(0x1000, &arm_code32).expect("failed to write instructions");

    emu.reg_write(RegisterARM::R0, 123).expect("failed write R0");
    emu.reg_write(RegisterARM::R5, 1337).expect("failed write R5");
    thread::sleep(time::Duration::from_millis(20000)); // 
    let _ = emu.emu_start(0x1000, (0x1000 + arm_code32.len()) as u64, 10 * SECOND_SCALE, 1000);
    assert_eq!(emu.reg_read(RegisterARM::R0), Ok(100));
    assert_eq!(emu.reg_read(RegisterARM::R5), Ok(1337));
}
// cargo.toml deps 
//[dependencies]
//unicorn-engine = "2.0.1"

image

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

3 participants