Software isolation model

<<../../../_common/intro/_sandboxing_intro.md>>

<<../../../_common/intro/_sandboxing_sandboxing.md>>

<<../../../_common/intro/_sandboxing_namespaces.md>>

Exercise: Namespaces

Most processes in Fuchsia represent executable programs associated with a component, where the component declaration is responsible for constructing the namespace that process can see.

In this exercise, you‘ll explore the contents of a component’s namespace.

<<../_common/_start_femu.md>>

Find a target component

You learned in the previous section that processes associated with a component are named with a .cm extension. Recall the following example process list:

TASK                     PSS PRIVATE  SHARED   STATE NAME
j: 1027               507.8M  507.4M                 root
  p: 1061             564.4k    564k     36k         bin/bootsvc
  p: 1150            4264.4k   4264k     36k         bin/component_manager
  j: 1479             228.4k    228k
    p: 1583           228.4k    228k     36k         pwrbtn-monitor.cm
  j: 1484             532.4k    532k
    p: 1599           532.4k    532k     36k         svchost.cm
  j: 1544             402.4k    304k
    p: 1633           402.4k    304k    232k         netsvc.cm
  j: 1681             296.4k    296k
    p: 1733           296.4k    296k     36k         console-launcher.cm
  j: 1799            7232.4k   7232k
    p: 1825          7232.4k   7232k     36k         archivist.cm
  ...
{{ '<strong>' }}  j: 31294           1872.2K   1872K {{ '</strong>' }}
{{ '<strong>' }}    p: 31331         1872.2K   1872K     20K         http-client.cm {{ '</strong>' }}

For this exercise, you'll use http-client.cm as your target to explore.

Connect to the target component

In order to explore a component's namespace, you need to determine the unique identifier for that component within the system. This is known as the component moniker.

Use the ffx component show command to list additional details about the component, including the component moniker:

ffx component show http-client.cm

The command prints output similar to the following:

$ ffx component show http-client.cm
{{ '<strong>' }}               Moniker: /core/network/http-client {{ '</strong>' }}
                   URL: #meta/http-client.cm
                  Type: CML static component
                  ...

You can use the ffx component explore command to open an interactive shell inside the target component's environment. Try this for the http-client component:

ffx component explore /core/network/http-client

Inside the explore shell, list the contents of the root directory using the ls command:

bin
exposed
ns
out
runtime
svc

Explore the namespace

You‘ll find the component’s namespace under the /ns path inside the environment.

Inside the explore shell, list the contents of the namespace:

config
pkg
svc

Here are some quick highlights of each element:

  • config/: configuration data for the component
  • pkg/: the contents of the component's package
  • svc/: system services available to the component

Inside the explore shell, list the contents of the incoming /ns/svc directory. This directory contains service nodes representing the system services provided to this component.

fuchsia.logger.LogSink
fuchsia.net.name.Lookup
fuchsia.posix.socket.Provider

Each of these services is accessible over a well-known protocol defined by a [Fuchsia Interface Definition Language (FIDL)][glossary.FIDL] interface. We'll explore FIDL protocols and how to access various services in more detail later on.

Inside the explore shell, type exit to return to the shell on your development machine: