Skip to content

api: add seccomp_arch_name() to resolve an arch token to its name#492

Open
rawrmonster17 wants to merge 1 commit into
seccomp:mainfrom
rawrmonster17:api-seccomp-arch-name
Open

api: add seccomp_arch_name() to resolve an arch token to its name#492
rawrmonster17 wants to merge 1 commit into
seccomp:mainfrom
rawrmonster17:api-seccomp-arch-name

Conversation

@rawrmonster17

Copy link
Copy Markdown

Problem

There is no public API to resolve a SCMP_ARCH_* token back to its
architecture name string. seccomp_arch_resolve_name() converts a name to a
token, but the inverse direction requires callers to maintain their own
token-to-string table, duplicating the mapping already present inside
libseccomp.

Fixes: Github Issue #295

Fix

Add seccomp_arch_name(uint32_t arch_token) as the inverse of
seccomp_arch_resolve_name():

  • Returns a pointer to a static string constant (caller must not free).
  • SCMP_ARCH_NATIVE resolves to the native architecture name, matching
    the zero-token convention used by seccomp_arch_add() and
    seccomp_arch_exist().
  • Returns NULL for an unrecognized token.

Implementation

A new internal helper arch_def_name() in src/arch.c holds the single
authoritative token→name table and is declared in src/arch.h.

The existing static _pfc_arch() in src/gen_pfc.c previously contained
an identical switch — it is now a two-line wrapper calling arch_def_name(),
eliminating the duplicate table and the linux/audit.h include that was
required solely for that switch.

The public seccomp_arch_name() in src/api.c calls arch_def_name()
directly, following the same API visibility macro pattern as every other
public arch function.

Documentation

seccomp_arch_add(3) is updated (NAME, SYNOPSIS, DESCRIPTION, RETURN VALUE)
and a .so redirect seccomp_arch_name(3) is added, following the same
pattern as seccomp_arch_resolve_name(3) and every other arch function stub.

Tests

New test 65-basic-arch_name round-trips every known SCMP_ARCH_* token
through seccomp_arch_resolve_name() and back through seccomp_arch_name(),
verifies SCMP_ARCH_NATIVE resolves to the native arch name, and confirms
that an unrecognized token (0xdeadbeef) returns NULL.

Testing

  • Zero new compiler warnings (-Wall -Wextra).
  • make check passes (PASS: arch-syscall-check, PASS: regression).
  • ./tests/65-basic-arch_name passes directly.

Add seccomp_arch_name() as the inverse of seccomp_arch_resolve_name():
given a SCMP_ARCH_* token it returns the canonical architecture name
string.  This allows callers to obtain a human-readable name for a
token without maintaining their own token-to-string table.

  - SCMP_ARCH_NATIVE resolves to the native architecture name, matching
    the behaviour of seccomp_arch_exist()/seccomp_arch_add() for the
    zero token value.
  - Returns a pointer to a static string constant; the caller must not
    free the returned pointer.
  - Returns NULL for an unrecognized token.

Implementation: add arch_def_name() to src/arch.c holding the single
authoritative token-to-name table, declared in src/arch.h.  The
existing static _pfc_arch() in src/gen_pfc.c is reduced to a thin
wrapper calling arch_def_name(), removing the duplicate switch and the
linux/audit.h include that was required solely for that switch.

The new public API function seccomp_arch_name() in src/api.c calls
arch_def_name() directly.

Documentation: add the new function to the seccomp_arch_add(3) man
page (NAME, SYNOPSIS, DESCRIPTION, RETURN VALUE) and add a .so redirect
seccomp_arch_name(3) following the same pattern as all other arch
function stubs.

Tests: add test 65-basic-arch_name which round-trips every known
SCMP_ARCH_* token through seccomp_arch_resolve_name() and back through
seccomp_arch_name(), verifies that SCMP_ARCH_NATIVE resolves to the
native architecture name, and confirms that an unrecognized token
returns NULL.

Fixes: Github Issue seccomp#295
Signed-off-by: rawrmonster17 <rawrmonster17@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

1 participant