File size: 9,376 Bytes
96dc096 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | /**
* intent_schema.h
* ูุธุงู
ุงูููุงูุง ุงูุณูุงุฏู - ูููู ุงูุจูุงูุงุช ุงูุฃุณุงุณู
* Sovereign Intent Schema - Core Data Structures
*
* Author: Ahmad Ali Parr
* License: Sovereign Source
*/
#ifndef ASOS_INTENT_SCHEMA_H
#define ASOS_INTENT_SCHEMA_H
#include <stdint.h>
#include <stddef.h>
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
* Intent Type Constants | ุซูุงุจุช ุฃููุงุน ุงูููุงูุง
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
#define INTENT_ALLOCATE 0x01 /* Resource allocation request */
#define INTENT_IO_READ 0x02 /* Autonomous read operation */
#define INTENT_IO_WRITE 0x03 /* Durable write with WORM seal */
#define INTENT_NET_SEND 0x04 /* Network transmission */
#define INTENT_NET_RECV 0x05 /* Network receive with filter */
#define INTENT_COMPUTE 0x06 /* Offload to NPU/accelerator */
#define INTENT_QUERY_STATE 0x07 /* System state inspection */
#define INTENT_SEAL_COMMIT 0x08 /* Cryptographic state seal */
/* Priority Levels | ู
ุณุชููุงุช ุงูุฃููููุฉ */
#define PRIORITY_BACKGROUND 0 /* Best-effort, defer under load */
#define PRIORITY_NORMAL 1 /* Standard application priority */
#define PRIORITY_HIGH 2 /* Time-sensitive operation */
#define PRIORITY_CRITICAL 3 /* System-critical, preemptive */
/* Trust Nonce Size (Blake3 256-bit) */
#define TRUST_NONCE_SIZE 32
/* Maximum Intent Payload Size (16KB) */
#define MAX_INTENT_PAYLOAD (16 * 1024)
/* Maximum Goal Schema String (1KB) */
#define MAX_GOAL_SCHEMA 1024
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
* Intent Payload Structure | ูููู ุญู
ููุฉ ุงูููุฉ
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
/**
* SystemIntent - User-submitted intent payload
*
* Instead of imperative syscalls, applications construct an intent
* describing WHAT they want (goal) with constraints (trust nonce,
* priority) and let the Kernel Agent Runtime (KAR) resolve HOW.
*
* Memory Layout:
* - Fixed header (64 bytes)
* - Variable payload (up to 16KB)
* - Trust nonce (32 bytes Blake3)
*
* All fields are validated at the kernel boundary.
*/
struct SystemIntent {
/* โโโ Core Intent Fields โโโ */
uint32_t intent_type; /* One of INTENT_* constants */
uint32_t priority; /* Execution urgency (0-3) */
uint32_t flags; /* Reserved for future extensions */
uint32_t payload_len; /* Length of payload_data in bytes */
/* โโโ Goal Description โโโ */
/**
* goal_schema: Symbolic or serialized description of the desired outcome.
*
* Examples:
* - "persist:durability=WORM,replication=3"
* - "allocate:memory=4MB,alignment=4K,zone=DMA"
* - "compute:model=classifier,input=tensor[224,224,3]"
*
* This is NOT Turing-complete code โ it's a structured constraint language
* parsed by the KAR policy engine.
*/
char goal_schema[MAX_GOAL_SCHEMA];
/* โโโ Payload Data โโโ */
/**
* payload_data: Pointer to working memory (user-space address).
*
* Kernel will copy_from_user() this safely. For zero-copy intents,
* this can be a ring buffer descriptor instead.
*/
void *payload_data;
/* โโโ Cryptographic Trust โโโ */
/**
* trust_nonce: Blake3 hash of (intent_type || priority || goal_schema || timestamp)
*
* Verified by KAR before execution. Prevents:
* - Intent replay attacks
* - Privilege escalation via modified intents
* - TOCTOU races (time-of-check to time-of-use)
*
* Generated by libasos in user space, validated in kernel.
*/
uint8_t trust_nonce[TRUST_NONCE_SIZE];
/* โโโ Execution Context โโโ */
uint64_t timestamp_ns; /* Monotonic clock at submission */
uint32_t source_pid; /* Process ID (set by kernel, not user) */
uint32_t source_uid; /* User ID (set by kernel, not user) */
} __attribute__((packed));
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
* Intent Result Structure | ูููู ูุชูุฌุฉ ุงูููุฉ
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
/**
* IntentResult - Kernel's resolved outcome
*
* Returned to user space after KAR processes the intent.
* Contains execution status, resolved resource handles, and
* cryptographic seal for audit trail.
*/
struct IntentResult {
/* โโโ Status Code โโโ */
int32_t status; /* 0 = success, negative = error code */
uint32_t kar_action; /* What the KAR actually did */
/* โโโ Resolved Resources โโโ */
uint64_t resource_handle; /* Opaque handle to kernel resource */
size_t bytes_transferred; /* For I/O operations */
/* โโโ Cryptographic Seal โโโ */
/**
* worm_seal: Blake3(intent || result || timestamp)
*
* Immutable audit record. Can be verified against WORM chain
* to prove this intent was executed with this outcome at this time.
*/
uint8_t worm_seal[TRUST_NONCE_SIZE];
/* โโโ Execution Metadata โโโ */
uint64_t execution_time_ns; /* Time spent in KAR */
uint32_t kar_agent_id; /* Which agent processed this */
} __attribute__((packed));
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
* Ring Buffer Entry | ุฅุฏุฎุงู ุงูู
ุฎุฒู ุงูู
ุคูุช ุงูุญููู
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
/**
* RingBufferEntry - Single slot in the zero-copy ring
*
* User space writes intents here, kernel reads and marks consumed.
* Lock-free single-producer single-consumer (SPSC) queue.
*/
struct RingBufferEntry {
uint32_t sequence; /* Monotonic sequence number */
uint32_t state; /* 0=empty, 1=submitted, 2=processing, 3=done */
struct SystemIntent intent; /* The intent payload */
struct IntentResult result; /* Filled by kernel */
} __attribute__((aligned(64))); /* Cache-line aligned */
/* Ring buffer states */
#define RB_STATE_EMPTY 0
#define RB_STATE_SUBMITTED 1
#define RB_STATE_PROCESSING 2
#define RB_STATE_DONE 3
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
* Error Codes | ุฃููุงุฏ ุงูุฃุฎุทุงุก
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
#define EINVALID_INTENT (-1000) /* Malformed intent structure */
#define ETRUST_NONCE_FAIL (-1001) /* Trust nonce validation failed */
#define EKAR_POLICY_REJECT (-1002) /* Policy engine rejected intent */
#define EKAR_NO_AGENT (-1003) /* No suitable agent available */
#define EKAR_TIMEOUT (-1004) /* Intent processing timeout */
#define EWORM_SEAL_FAIL (-1005) /* Failed to generate WORM seal */
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
* Compile-Time Assertions | ุชุฃููุฏุงุช ููุช ุงูุชุฑุฌู
ุฉ
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
/* Ensure structures are properly sized for efficient copying */
_Static_assert(sizeof(struct SystemIntent) <= 2048,
"SystemIntent too large - exceeds efficient copy threshold");
_Static_assert(sizeof(struct IntentResult) <= 256,
"IntentResult too large - should fit in 4 cache lines");
_Static_assert(sizeof(struct RingBufferEntry) % 64 == 0,
"RingBufferEntry not cache-aligned");
#endif /* ASOS_INTENT_SCHEMA_H */
|