arch/x86/boot/string.c
Source file repositories/reference/linux-study-clean/arch/x86/boot/string.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/boot/string.c- Extension
.c- Size
- 7531 bytes
- Lines
- 351
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
Dependency Surface
linux/types.hlinux/compiler.hlinux/errno.hlinux/limits.hasm/asm.hctype.hstring.h
Detected Declarations
function Copyrightfunction bcmpfunction strcmpfunction strncmpfunction strnlenfunction simple_guess_basefunction simple_strtoullfunction simple_strtolfunction strlenfunction __div_u64_remfunction __div_u64function _tolowerfunction _parse_integerfunction supportfunction _kstrtoullfunction _kstrtoulfunction hexadecimal
Annotated Snippet
if (s[0] == '0') {
if (_tolower(s[1]) == 'x' && isxdigit(s[2]))
*base = 16;
else
*base = 8;
} else
*base = 10;
}
if (*base == 16 && s[0] == '0' && _tolower(s[1]) == 'x')
s += 2;
return s;
}
/*
* Convert non-negative integer string representation in explicitly given radix
* to an integer.
* Return number of characters consumed maybe or-ed with overflow bit.
* If overflow occurs, result integer (incorrect) is still returned.
*
* Don't you dare use this function.
*/
static unsigned int _parse_integer(const char *s,
unsigned int base,
unsigned long long *p)
{
unsigned long long res;
unsigned int rv;
res = 0;
rv = 0;
while (1) {
unsigned int c = *s;
unsigned int lc = c | 0x20; /* don't tolower() this line */
unsigned int val;
if ('0' <= c && c <= '9')
val = c - '0';
else if ('a' <= lc && lc <= 'f')
val = lc - 'a' + 10;
else
break;
if (val >= base)
break;
/*
* Check for overflow only if we are within range of
* it in the max base we support (16)
*/
if (unlikely(res & (~0ull << 60))) {
if (res > __div_u64(ULLONG_MAX - val, base))
rv |= KSTRTOX_OVERFLOW;
}
res = res * base + val;
rv++;
s++;
}
*p = res;
return rv;
}
static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
{
unsigned long long _res;
unsigned int rv;
if (s[0] == '+')
s++;
s = _parse_integer_fixup_radix(s, &base);
rv = _parse_integer(s, base, &_res);
if (rv & KSTRTOX_OVERFLOW)
return -ERANGE;
if (rv == 0)
return -EINVAL;
s += rv;
if (*s == '\n')
s++;
if (*s)
return -EINVAL;
*res = _res;
return 0;
}
static int _kstrtoul(const char *s, unsigned int base, unsigned long *res)
{
unsigned long long tmp;
int rv;
rv = _kstrtoull(s, base, &tmp);
if (rv < 0)
Annotation
- Immediate include surface: `linux/types.h`, `linux/compiler.h`, `linux/errno.h`, `linux/limits.h`, `asm/asm.h`, `ctype.h`, `string.h`.
- Detected declarations: `function Copyright`, `function bcmp`, `function strcmp`, `function strncmp`, `function strnlen`, `function simple_guess_base`, `function simple_strtoull`, `function simple_strtol`, `function strlen`, `function __div_u64_rem`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.