20 #include "modules/Module.h" 21 #include "pedigree/kernel/BootstrapInfo.h" 22 #include "pedigree/kernel/Log.h" 23 #include "pedigree/kernel/linker/KernelElf.h" 24 #include "pedigree/kernel/panic.h" 25 #include "pedigree/kernel/processor/MemoryRegion.h" 26 #include "pedigree/kernel/processor/PhysicalMemoryManager.h" 27 #include "pedigree/kernel/processor/VirtualAddressSpace.h" 28 #include "pedigree/kernel/processor/types.h" 29 #include "pedigree/kernel/utilities/utility.h" 30 #include "sqlite3/sqlite3.h" 36 static uint8_t *g_pFile = 0;
37 static size_t g_FileSz = 0;
40 void log_(
unsigned long a);
41 int atoi(
const char *str);
44 extern "C" void log_(
unsigned long a)
49 extern "C" int atoi(
const char *str)
51 return StringToUnsignedLong(str, 0, 10);
54 extern "C" struct tm *gmtime(
struct tm *timep)
60 strftime(
char *s,
size_t max,
const char *format,
const struct tm *tm)
70 static int xRead(
sqlite3_file *file,
void *ptr,
int iAmt, sqlite3_int64 iOfst)
73 if ((static_cast<size_t>(iOfst + iAmt)) >= g_FileSz)
75 if (static_cast<size_t>(iAmt) > g_FileSz)
77 ByteSet(ptr, 0, iAmt);
78 iAmt = g_FileSz - iOfst;
79 ret = SQLITE_IOERR_SHORT_READ;
81 MemoryCopy(ptr, &g_pFile[iOfst], iAmt);
86 xReadFail(
sqlite3_file *file,
void *ptr,
int iAmt, sqlite3_int64 iOfst)
88 ByteSet(ptr, 0, iAmt);
89 return SQLITE_IOERR_SHORT_READ;
93 xWrite(
sqlite3_file *file,
const void *ptr,
int iAmt, sqlite3_int64 iOfst)
96 if (static_cast<size_t>(iOfst + iAmt) >= g_FileSz)
99 return SQLITE_IOERR_WRITE;
102 MemoryCopy(&g_pFile[iOfst], ptr, iAmt);
107 xWriteFail(
sqlite3_file *file,
const void *ptr,
int iAmt, sqlite3_int64 iOfst)
112 static int xTruncate(
sqlite3_file *file, sqlite3_int64 size)
122 static int xFileSize(
sqlite3_file *file, sqlite3_int64 *pSize)
138 static int xCheckReservedLock(
sqlite3_file *file,
int *pResOut)
144 static int xFileControl(
sqlite3_file *file,
int op,
void *pArg)
171 &xDeviceCharacteristics,
191 &xDeviceCharacteristics,
203 if (StringCompare(zName,
"root»/.pedigree-root"))
206 file->pMethods = &theio_fail;
210 if (!g_pBootstrapInfo->isDatabaseLoaded())
212 FATAL(
"Config database not loaded!");
215 file->pMethods = &theio;
219 static int xDelete(
sqlite3_vfs *vfs,
const char *zName,
int syncDir)
224 static int xAccess(
sqlite3_vfs *vfs,
const char *zName,
int flags,
int *pResOut)
230 xFullPathname(
sqlite3_vfs *vfs,
const char *zName,
int nOut,
char *zOut)
232 StringCopyN(zOut, zName, nOut);
236 static void *xDlOpen(
sqlite3_vfs *vfs,
const char *zFilename)
241 static void xDlError(
sqlite3_vfs *vfs,
int nByte,
char *zErrMsg)
245 static void (*xDlSym(
sqlite3_vfs *vfs,
void *p,
const char *zSymbol))(void)
254 static int xRandomness(
sqlite3_vfs *vfs,
int nByte,
char *zOut)
259 static int xSleep(
sqlite3_vfs *vfs,
int microseconds)
264 static int xCurrentTime(
sqlite3_vfs *vfs, sqlite3_int64 *)
269 static int xGetLastError(
sqlite3_vfs *vfs,
int i,
char *c)
297 int sqlite3_os_init()
299 sqlite3_vfs_register(&thevfs, 1);
310 const unsigned char *text = sqlite3_value_text(values[0]);
318 x = StringToUnsignedLong(reinterpret_cast<const char *>(text), 0, 16);
323 reinterpret_cast<const char *>(text));
327 "Couldn't trigger callback `" 328 << reinterpret_cast<const char *>(text)
329 <<
"': symbol not found.");
334 void (*func)(void) =
reinterpret_cast<void (*)(
void)
>(x);
336 sqlite3_result_int(context, 0);
342 reinterpret_cast<const char *
>(sqlite3_value_text(values[0]));
350 x = StringToUnsignedLong(text, 0, 16);
358 "Couldn't trigger callback `" << text
359 <<
"': symbol not found.");
364 void (*func)(
const char *) =
reinterpret_cast<void (*)(
const char *)
>(x);
365 func(reinterpret_cast<const char *>(sqlite3_value_text(values[1])));
366 sqlite3_result_int(context, 0);
372 reinterpret_cast<const char *
>(sqlite3_value_text(values[0]));
380 x = StringToUnsignedLong(text, 0, 16);
388 "Couldn't trigger callback `" << text
389 <<
"': symbol not found.");
394 void (*func)(
const char *,
const char *) =
395 reinterpret_cast<void (*)(
const char *,
const char *)
>(x);
397 reinterpret_cast<const char *>(sqlite3_value_text(values[1])),
398 reinterpret_cast<const char *>(sqlite3_value_text(values[2])));
399 sqlite3_result_int(context, 0);
402 #ifdef STATIC_DRIVERS 403 #include "config_database.h" 404 #elif !defined(HOSTED) 412 #ifndef STATIC_DRIVERS 413 if (!g_pBootstrapInfo->isDatabaseLoaded())
414 FATAL(
"Database not loaded, cannot continue.");
416 uint8_t *pPhys = g_pBootstrapInfo->getDatabaseAddress();
417 size_t sSize = g_pBootstrapInfo->getDatabaseSize();
419 if ((reinterpret_cast<physical_uintptr_t>(pPhys) &
421 panic(
"Config: Alignment issues");
424 g_pFile =
new uint8_t[sSize];
425 MemoryCopy(g_pFile, pPhys, sSize);
433 reinterpret_cast<physical_uintptr_t>(pPhys)) ==
false)
435 ERROR(
"Config: allocateRegion failed.");
444 g_FileSz =
sizeof file;
447 sqlite3_initialize();
448 int ret = sqlite3_open(
"root»/.pedigree-root", &g_pSqlite);
451 FATAL(
"sqlite3 error: " << sqlite3_errmsg(g_pSqlite));
454 sqlite3_create_function(
455 g_pSqlite,
"pedigree_callback", 1, SQLITE_ANY, 0, &xCallback0, 0, 0);
456 sqlite3_create_function(
457 g_pSqlite,
"pedigree_callback", 2, SQLITE_ANY, 0, &xCallback1, 0, 0);
458 sqlite3_create_function(
459 g_pSqlite,
"pedigree_callback", 3, SQLITE_ANY, 0, &xCallback2, 0, 0);
464 static void destroy()
467 sqlite3_close(g_pSqlite);
470 #if !defined(STATIC_DRIVERS) && !defined(HOSTED) 475 MODULE_INFO(
"config", &init, &destroy);
Bootstrap structure passed to the kernel entry point.
static size_t getPageSize() PURE
static PhysicalMemoryManager & instance()
static const size_t continuous
const char * lookupSymbol(uintptr_t addr, uintptr_t *startAddr, T *symbolTable)
static KernelElf & instance()
static const size_t KernelMode
Special memory entity in the kernel's virtual address space.
void * virtualAddress() const
void EXPORTED_PUBLIC panic(const char *msg) NORETURN