arch/sh/mm/alignment.c
Source file repositories/reference/linux-study-clean/arch/sh/mm/alignment.c
File Facts
- System
- Linux kernel
- Corpus path
arch/sh/mm/alignment.c- Extension
.c- Size
- 4744 bytes
- Lines
- 190
- Domain
- Architecture Layer
- Bucket
- arch/sh
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/kernel.hlinux/seq_file.hlinux/proc_fs.hlinux/uaccess.hlinux/ratelimit.hasm/alignment.hasm/processor.h
Detected Declarations
function inc_unaligned_byte_accessfunction inc_unaligned_word_accessfunction inc_unaligned_dword_accessfunction inc_unaligned_multi_accessfunction inc_unaligned_user_accessfunction inc_unaligned_kernel_accessfunction unaligned_user_actionfunction get_unalign_ctlfunction set_unalign_ctlfunction unaligned_fixups_notifyfunction alignment_proc_showfunction alignment_proc_openfunction alignment_proc_writefunction sysctl_init_basesmodule init alignment_init
Annotated Snippet
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/seq_file.h>
#include <linux/proc_fs.h>
#include <linux/uaccess.h>
#include <linux/ratelimit.h>
#include <asm/alignment.h>
#include <asm/processor.h>
static unsigned long se_user;
static unsigned long se_sys;
static unsigned long se_half;
static unsigned long se_word;
static unsigned long se_dword;
static unsigned long se_multi;
/* bitfield: 1: warn 2: fixup 4: signal -> combinations 2|4 && 1|2|4 are not
valid! */
static int se_usermode = UM_WARN | UM_FIXUP;
/* 0: no warning 1: print a warning message, disabled by default */
static int se_kernmode_warn;
core_param(alignment, se_usermode, int, 0600);
void inc_unaligned_byte_access(void)
{
se_half++;
}
void inc_unaligned_word_access(void)
{
se_word++;
}
void inc_unaligned_dword_access(void)
{
se_dword++;
}
void inc_unaligned_multi_access(void)
{
se_multi++;
}
void inc_unaligned_user_access(void)
{
se_user++;
}
void inc_unaligned_kernel_access(void)
{
se_sys++;
}
/*
* This defaults to the global policy which can be set from the command
* line, while processes can overload their preferences via prctl().
*/
unsigned int unaligned_user_action(void)
{
unsigned int action = se_usermode;
if (current->thread.flags & SH_THREAD_UAC_SIGBUS) {
action &= ~UM_FIXUP;
action |= UM_SIGNAL;
}
if (current->thread.flags & SH_THREAD_UAC_NOPRINT)
action &= ~UM_WARN;
return action;
}
int get_unalign_ctl(struct task_struct *tsk, unsigned long addr)
{
return put_user(tsk->thread.flags & SH_THREAD_UAC_MASK,
(unsigned int __user *)addr);
}
int set_unalign_ctl(struct task_struct *tsk, unsigned int val)
{
tsk->thread.flags = (tsk->thread.flags & ~SH_THREAD_UAC_MASK) |
(val & SH_THREAD_UAC_MASK);
return 0;
}
void unaligned_fixups_notify(struct task_struct *tsk, insn_size_t insn,
struct pt_regs *regs)
{
if (user_mode(regs) && (se_usermode & UM_WARN))
pr_notice_ratelimited("Fixing up unaligned userspace access "
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/seq_file.h`, `linux/proc_fs.h`, `linux/uaccess.h`, `linux/ratelimit.h`, `asm/alignment.h`, `asm/processor.h`.
- Detected declarations: `function inc_unaligned_byte_access`, `function inc_unaligned_word_access`, `function inc_unaligned_dword_access`, `function inc_unaligned_multi_access`, `function inc_unaligned_user_access`, `function inc_unaligned_kernel_access`, `function unaligned_user_action`, `function get_unalign_ctl`, `function set_unalign_ctl`, `function unaligned_fixups_notify`.
- Atlas domain: Architecture Layer / arch/sh.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.