Files
nvdriver/kernel-open/nvidia/thread_state_adapter.c
Eric Hartford 33ff608a88 Add MIT LICENSE and unify repository SPDX/Cargo/module licensing
- Add root LICENSE (MIT License, Copyright (c) 2026 QuixiAI / Eric Hartford).
- Set license = "MIT" in workspace Cargo.toml and member crates (zero non-MIT dependencies).
- Update all kernel-open/ and tests/vm/ SPDX headers to MIT and EXPORT_SYMBOL_GPL -> EXPORT_SYMBOL.
- Use MODULE_LICENSE("Dual MIT/GPL") in Linux .ko modules so Linux modpost permits linking against the kernel's own EXPORT_SYMBOL_GPL symbols while keeping the repository source 100% MIT.

Closes #12.
2026-12-01 00:20:02 +00:00

50 lines
1.5 KiB
C

/* SPDX-License-Identifier: MIT */
/* OS allocation, IRQ-saving lock and task references only. Registry policy is Rust. */
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
#include <linux/sched/task.h>
#include "thread_state_adapter.h"
void *nv_rs_thread_storage_alloc(size_t bytes)
{
return kzalloc(bytes, GFP_KERNEL);
}
void nv_rs_thread_storage_free(void *allocation) { kfree(allocation); }
void *nv_rs_thread_lock_create(void)
{
spinlock_t *lock = kmalloc(sizeof(*lock), GFP_KERNEL);
if (lock)
spin_lock_init(lock);
return lock;
}
void nv_rs_thread_lock_destroy(void *lock) { kfree(lock); }
unsigned long nv_rs_thread_lock(void *lock)
{
unsigned long flags;
spin_lock_irqsave((spinlock_t *)lock, flags);
return flags;
}
void nv_rs_thread_unlock(void *lock, unsigned long flags)
{
spin_unlock_irqrestore((spinlock_t *)lock, flags);
}
void *nv_rs_thread_task_get(u32 *flags)
{
if (!flags || in_interrupt() || irqs_disabled() || in_atomic())
return NULL;
*flags = ((current->flags & PF_KTHREAD) ? 1 : 0) |
((current->flags & PF_EXITING) ? 2 : 0);
get_task_struct(current);
return current;
}
void nv_rs_thread_task_put(void *task) { put_task_struct((struct task_struct *)task); }
bool nv_rs_thread_task_current(void *task)
{
/* Identity-only: registry lookup holds an IRQ-saving spinlock. */
return task == current;
}
bool nv_rs_thread_process_context(void)
{
return !in_interrupt() && !irqs_disabled() && !in_atomic();
}