api: add seccomp_arch_name() to resolve an arch token to its name#492
Open
rawrmonster17 wants to merge 1 commit into
Open
api: add seccomp_arch_name() to resolve an arch token to its name#492rawrmonster17 wants to merge 1 commit into
rawrmonster17 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
There is no public API to resolve a
SCMP_ARCH_*token back to itsarchitecture name string.
seccomp_arch_resolve_name()converts a name to atoken, 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 ofseccomp_arch_resolve_name():SCMP_ARCH_NATIVEresolves to the native architecture name, matchingthe zero-token convention used by
seccomp_arch_add()andseccomp_arch_exist().NULLfor an unrecognized token.Implementation
A new internal helper
arch_def_name()insrc/arch.cholds the singleauthoritative token→name table and is declared in
src/arch.h.The existing
static _pfc_arch()insrc/gen_pfc.cpreviously containedan identical switch — it is now a two-line wrapper calling
arch_def_name(),eliminating the duplicate table and the
linux/audit.hinclude that wasrequired solely for that switch.
The public
seccomp_arch_name()insrc/api.ccallsarch_def_name()directly, following the same
APIvisibility macro pattern as every otherpublic arch function.
Documentation
seccomp_arch_add(3)is updated (NAME, SYNOPSIS, DESCRIPTION, RETURN VALUE)and a
.soredirectseccomp_arch_name(3)is added, following the samepattern as
seccomp_arch_resolve_name(3)and every other arch function stub.Tests
New test
65-basic-arch_nameround-trips every knownSCMP_ARCH_*tokenthrough
seccomp_arch_resolve_name()and back throughseccomp_arch_name(),verifies
SCMP_ARCH_NATIVEresolves to the native arch name, and confirmsthat an unrecognized token (
0xdeadbeef) returnsNULL.Testing
-Wall -Wextra).make checkpasses (PASS: arch-syscall-check, PASS: regression)../tests/65-basic-arch_namepasses directly.