Files
nvdriver/tests/thread-state/ffi.c
nvidia-driver-rs 4526e6a816 Baseline: validated 30/30 tree with passing Level 7 hardware regression
- Updated tools/post_reboot.sh to check kernel oops taint bit and stuck driver tasks instead of <86400s uptime
- Level 7 hardware regression passed on 0000:b3:00.0 (module 37e6fa430835eee2b426019db3ad70eeb7a9e9070c09c84bd9b973cf56cbe529, 107 inventory words, 0 static mismatches, CUDA baseline verified before and after)
- Updated .gitignore to exclude build archives (*.a, *.rlib), __pycache__, and raw trace dumps
2026-11-23 23:48:38 +00:00

55 lines
2.7 KiB
C

/* Host OS fixture: real malloc/pthread synchronization, controlled RM identity. */
#include <pthread.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
static _Atomic unsigned storage, tasks, modules, locks;
static _Thread_local uint64_t pid = 0x9876;
static _Thread_local uint32_t cpu = 2, context, process_flags;
static _Thread_local bool allocation_fail, module_fail;
static _Thread_local unsigned held_locks;
struct snapshot { uint64_t pid; uint32_t cpu, interrupt; };
struct task { pthread_t owner; uint64_t pid; };
void fixture_context(uint64_t id, uint32_t processor, uint32_t ctx, uint32_t flags)
{ pid=id; cpu=processor; context=ctx; process_flags=flags; }
void fixture_fail(bool allocation, bool module) { allocation_fail=allocation; module_fail=module; }
uint64_t fixture_outstanding(void)
{ return atomic_load(&storage) | ((uint64_t)atomic_load(&tasks)<<16) |
((uint64_t)atomic_load(&modules)<<32) | ((uint64_t)atomic_load(&locks)<<48); }
void *nv_rs_thread_storage_alloc(size_t bytes)
{
if (allocation_fail) { allocation_fail=false; return NULL; }
void *p=calloc(1,bytes); if(p) atomic_fetch_add(&storage,1); return p;
}
void nv_rs_thread_storage_free(void *p) { assert(p); free(p); atomic_fetch_sub(&storage,1); }
void *nv_rs_thread_lock_create(void)
{
pthread_mutex_t *p=malloc(sizeof(*p));
if(p) { assert(!pthread_mutex_init(p,NULL)); atomic_fetch_add(&locks,1); }
return p;
}
void nv_rs_thread_lock_destroy(void *p)
{ assert(!pthread_mutex_destroy(p)); free(p); atomic_fetch_sub(&locks,1); }
size_t nv_rs_thread_lock(void *p)
{ assert(!pthread_mutex_lock(p)); assert(!held_locks); held_locks++; return 0x1234; }
void nv_rs_thread_unlock(void *p, size_t flags)
{ assert(flags==0x1234 && held_locks==1); held_locks--; assert(!pthread_mutex_unlock(p)); }
bool nv_rs_thread_process_context(void) { return !context && !held_locks; }
void *nv_rs_thread_task_get(uint32_t *flags)
{
if (!nv_rs_thread_process_context()) return NULL;
struct task *task=malloc(sizeof(*task)); assert(task);
task->owner=pthread_self(); task->pid=pid; *flags=process_flags;
atomic_fetch_add(&tasks,1); return task;
}
bool nv_rs_thread_task_current(void *p)
{ struct task *task=p; return task->pid==pid && pthread_equal(task->owner,pthread_self()); }
void nv_rs_thread_task_put(void *p) { free(p); atomic_fetch_sub(&tasks,1); }
int nv_rs_thread_current(struct snapshot *out)
{ out->pid=context&2 ? 0 : pid; out->cpu=cpu; out->interrupt=!!(context&2); return 0; }
bool nv_rs_gpu_module_get(void)
{ if(module_fail)return false; atomic_fetch_add(&modules,1); return true; }
void nv_rs_gpu_module_put(void) { atomic_fetch_sub(&modules,1); }