Skip to content
lazymio edited this page May 19, 2023 · 8 revisions

If you would like to make contributions to Unicorn, there are a few conventions to keep in mind.

The unit tests count

Make sure all tests are passed when you doing some modification of the codebase. Also, don't forget to add a unit test for your fix/feature.

Think twice before adding a new API

As is often the case, it's tempting to add a new API to solve some specific problems. However, Unicorn tries its best to offer simple and elegant API, and thus think twice before you really would add a new API. Some examples:

  • You would like to change some specific configuration of flags of CPU model. --> Add a new UC_MODE_* or UC_CTL_* flag.
  • You want a new type of hook. --> Check whether a combination of existing hooks could achieve.
  • You would like to apply your fix at runtime. --> Find the root cause and record the status in uc_struct.

If you really would like a new API, you have to prepare for enough reason to convince us and we are open to API discussion.

Check against qemu whenever possible

Sometimes, the issue is from the qemu itself and there may be already some fix applied on the upstream. In this case, you may backport specific commits to the current codebase.

For example, if you find Unicorn fails to decode some ARM instructions, go to qemu 5.0.1 and check whether they could do before raising an issue.

No dirty fix

We won't accept any dirty fix like generating some special microcode in some special conditions to fix your issue temporarily. If you would like your PR merged, please consider the fix as a universal one.

Finish your fix one time

Don't leave TODO in your fix unless it's really a big feature, like adding new architecture support. For most fixes, make sure you finish all things:

  • If you modify the register enumeration, make sure such modification is also applied on all bindings.
  • If you are adding some new support, make sure add corresponding UC_* flags.
  • If you are implementing some registers, please have reference and add s full set of registers.

Follow qemu coding convention

Unicorn is a fork of qemu, so for code under qemu directory, we kindly ask you to follow qemu coding convention for your best. For example:

void a_function(void)
{
    if (a == 5) {
        printf("a was 5.\n");
    } else if (a == 6) {
        printf("a was 6.\n");
    } else {
        printf("a was something else entirely.\n");
    }
}

Make sure your feature works in all architectures

If you are working to add new features, make it available across all architectures if possible.