<commit_before># Fuchsia support

For information about checking out and building Fuchsia see
[Getting Started](https://fuchsia.dev/fuchsia-src/get-started)
and [Source Code](https://fuchsia.dev/fuchsia-src/get-started/get_fuchsia_source).

## Prerequisites

To run syzkaller with a fuchsia target, you will need:

* A fuchsia checkout.

The rest of the document will use the following environment variables:

* `SOURCEDIR` path of your fuchsia checkout.

## Building Fuchsia

To build fuchsia run:

```shell
$ fx --dir "out/arm64" set core.arm64 \
  --with-base "//bundles:tools" \
  --with-base "//src/testing/fuzzing/syzkaller" \
  --args=syzkaller_dir='"/full/path/to/syzkaller"'
$ fx clean-build
```

And

```shell
$ fx --dir "out/x64" set core.x64 \
  --with-base "//bundles:tools" \
  --with-base "//src/testing/fuzzing/syzkaller" \
  --args=syzkaller_dir='"/full/path/to/syzkaller"'
$ fx clean-build
```

## Building binaries for fuchsia

To build all the binaries required for running syzkaller in fuchsia, run:

```
$ make TARGETOS=fuchsia TARGETARCH=amd64 \
    SOURCEDIR=path/to/fuchsia/checkout
```

## Running syz-manager

Running syz-manager requires you to have built fuchsia previously, and added the ssh keys to the fuchsia.zbi image:

```
$ ${SOURCEDIR}/out/x64/host_x64/zbi -o ${SOURCEDIR}/out/x64/fuchsia-ssh.zbi ${SOURCEDIR}/out/x64/fuchsia.zbi --entry "data/ssh/authorized_keys=${SOURCEDIR}/.ssh/authorized_keys"
```

You will also need to extend the `fvm` image:

```
$ cp "${SOURCEDIR}/out/x64/obj/build/images/fvm.blk" "${SOURCEDIR}/out/x64/obj/build/images/fvm-extended.blk"
$ ${SOURCEDIR}/out/x64/host_x64/fvm "${SOURCEDIR}/out/x64/obj/build/images/fvm-extended.blk" extend --length 3G
```

Note: This needs to be repeated after each `fx build`.

Run `syz-manager` with a config along the lines of:
```
{
        "name": "fuchsia",
        "target": "fuchsia/amd64",
        "http": ":12345",
        "workdir": "/workdir.fuchsia",
        "kernel_obj": "/fuchsia/out/x64.zircon/kernel-x64-gcc",
        "syzkaller": "/syzkaller",
        "image": "/fuchsia/out/x64/obj/build/images/fvm-extended.blk",
        "sshkey": "/fuchsia/.ssh/pkey",
        "reproduce": false,
        "cover": false,
        "procs": 8,
        "type": "qemu",
        "vm": {
                "count": 10,
                "cpu": 4,
                "mem": 2048,
                "kernel": "/fuchsia/out/x64/multiboot.bin",
                "initrd": "/fuchsia/out/x64/fuchsia-ssh.zbi"
        }
}
```

## Update syscall and fidl definitions

Syscall descriptions live in the `sys/fuchsia` folder. To update a syscall, you need to modify the `.txt` file that contains it, make sure your new definition matches the one in zircon's [syscalls.abigen](https://fuchsia.googlesource.com/fuchsia/+/master/zircon/system/public/zircon/syscalls.abigen) file. **If the syscall was used in `executor/common_fuchsia.h`, you need to update the usages there as well**. FIDL definitions do not need manual updating because they are extracted automatically when you run `make extract`, but they require Fuchsia to be rebuilt for each architecture (see "Building Fuchsia" above).

Once you updated the syscalls definitions, everything can be regenerated by running:<commit_msg>docs/fuchsia: update README.md to fix fuchsia build with kasan enabled<commit_after># Fuchsia support

For information about checking out and building Fuchsia see
[Getting Started](https://fuchsia.dev/fuchsia-src/get-started)
and [Source Code](https://fuchsia.dev/fuchsia-src/get-started/get_fuchsia_source).

## Prerequisites

To run syzkaller with a fuchsia target, you will need:

* A fuchsia checkout.

The rest of the document will use the following environment variables:

* `SOURCEDIR` path of your fuchsia checkout.

## Building Fuchsia

To build fuchsia run:

NOTE: Inside `${SOURCEDIR}/src/testing/fuzzing/syzkaller/BUILD.gnsrc/testing/fuzzing/syzkaller/BUILD.gn`
you need to replace the line with `"$(src)/executor/kvm.S.h"` by `"${src}/executor/kvm_amd64.S.h"`

```shell
$ fx --dir "out/arm64" set core.arm64 \
  --with-base "//bundles:tools" \
  --with-base "//src/testing/fuzzing/syzkaller" \
  --args=syzkaller_dir='"/full/path/to/syzkaller"'  --variant=kasan
$ fx clean-build
```

And

```shell
$ fx --dir "out/x64" set core.x64 \
  --with-base "//bundles:tools" \
  --with-base "//src/testing/fuzzing/syzkaller" \
  --args=syzkaller_dir='"/full/path/to/syzkaller"'  --variant=kasan
$ fx clean-build
```

## Building binaries for fuchsia

To build all the binaries required for running syzkaller in fuchsia, run:

```
$ make TARGETOS=fuchsia TARGETARCH=amd64 \
    SOURCEDIR=path/to/fuchsia/checkout
```

## Running syz-manager

Running syz-manager requires you to have built fuchsia previously, and added the ssh keys to the fuchsia.zbi image:

```
$ ${SOURCEDIR}/out/x64/host_x64/zbi -o ${SOURCEDIR}/out/x64/fuchsia-ssh.zbi ${SOURCEDIR}/out/x64/fuchsia.zbi --entry "data/ssh/authorized_keys=${SOURCEDIR}/.ssh/authorized_keys"
```

You will also need to extend the `fvm` image:

```
$ cp "${SOURCEDIR}/out/x64/obj/build/images/fuchsia/fuchsia/fvm.blk" "${SOURCEDIR}/out/x64/obj/build/images/fuchsia/fuchsia/fvm-extended.blk"
$ ${SOURCEDIR}/out/x64/host_x64/fvm "${SOURCEDIR}/out/x64/obj/build/images/fuchsia/fuchsia/fvm-extended.blk" extend --length 3G
```

Note: This needs to be repeated after each `fx build`.

Run `syz-manager` with a config along the lines of:
```
{
        "name": "fuchsia",
        "target": "fuchsia/amd64",
        "http": ":12345",
        "workdir": "/workdir.fuchsia",
        "kernel_obj": "/fuchsia/out/x64.zircon/kernel-x64-gcc",
        "syzkaller": "/syzkaller",
        "image": "/fuchsia/out/x64/obj/build/images/fuchsia/fuchsia/fvm-extended.blk",
        "sshkey": "/fuchsia/.ssh/pkey",
        "reproduce": false,
        "cover": false,
        "procs": 8,
        "type": "qemu",
        "vm": {
                "count": 10,
                "cpu": 4,
                "mem": 2048,
                "kernel": "/fuchsia/out/x64/multiboot.bin",
                "initrd": "/fuchsia/out/x64/fuchsia-ssh.zbi"
        }
}
```

## Update syscall and fidl definitions

Syscall descriptions live in the `sys/fuchsia` folder. To update a syscall, you need to modify the `.txt` file that contains it, make sure your new definition matches the one in zircon's [syscalls.abigen](https://fuchsia.googlesource.com/fuchsia/+/master/zircon/system/public/zircon/syscalls.abigen) file. **If the syscall was used in `executor/common_fuchsia.h`, you need to update the usages there as well**. FIDL definitions do not need manual updating because they are extracted automatically when you run `make extract`, but they require Fuchsia to be rebuilt for each architecture (see "Building Fuchsia" above).

Once you updated the syscalls definitions, everything can be regenerated by running:
{'fraction_non_alphanumeric': 0.1433139534883721, 'fraction_numerical': 0.015988372093023256, 'mean_word_length': 3.408071748878924, 'pattern_counts': {'":': 38, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3062279', 'n_tokens_mistral': 2684, 'n_tokens_neox': 2439, 'n_words': 613}