20 #include "modules/system/config/Config.h" 21 #include "modules/system/vfs/File.h" 23 #include "modules/system/vfs/Symlink.h" 24 #include "modules/system/vfs/VFS.h" 25 #include "pedigree/kernel/Log.h" 26 #include "pedigree/kernel/linker/KernelElf.h" 27 #include "pedigree/kernel/machine/Display.h" 28 #include "pedigree/kernel/machine/Framebuffer.h" 29 #include "pedigree/kernel/machine/InputManager.h" 30 #include "pedigree/kernel/machine/KeymapManager.h" 31 #include "pedigree/kernel/process/PerProcessorScheduler.h" 32 #include "pedigree/kernel/process/Process.h" 33 #include "pedigree/kernel/process/eventNumbers.h" 34 #include "pedigree/kernel/processor/Processor.h" 35 #include "pedigree/kernel/syscallError.h" 37 #include "pedigree/kernel/ServiceManager.h" 38 #include "pedigree/kernel/graphics/Graphics.h" 39 #include "pedigree/kernel/graphics/GraphicsService.h" 41 #include "modules/system/users/User.h" 42 #include "modules/system/users/UserManager.h" 44 #define PEDIGREEC_WITHIN_KERNEL 45 #include "pedigree-syscalls.h" 47 static const char *pConfigPermissionError =
48 "insufficient permissions: only root allowed";
53 uint32_t srcx, srcy, destx, desty, width, height;
59 uintptr_t b, c, d, e, f, g, h;
65 void *pReturnProvider;
76 uintptr_t a, b, c, d, e, f;
79 #define MAX_RESULTS 32 82 void pedigree_config_init()
87 void pedigree_config_getcolname(
88 size_t resultIdx,
size_t n,
char *buf,
size_t bufsz)
90 if (resultIdx >= MAX_RESULTS || g_Results[resultIdx] == 0)
93 StringCopyN(buf, static_cast<const char *>(str), bufsz);
96 void pedigree_config_getstr(
97 size_t resultIdx,
size_t row,
size_t n,
char *buf,
size_t bufsz)
99 if (resultIdx >= MAX_RESULTS || g_Results[resultIdx] == 0)
102 StringCopyN(buf, static_cast<const char *>(str), bufsz);
105 void pedigree_config_getstr(
106 size_t resultIdx,
size_t row,
const char *col,
char *buf,
size_t bufsz)
108 if (resultIdx >= MAX_RESULTS || g_Results[resultIdx] == 0)
111 StringCopyN(buf, static_cast<const char *>(str), bufsz);
114 int pedigree_config_getnum(
size_t resultIdx,
size_t row,
size_t n)
116 if (resultIdx >= MAX_RESULTS || g_Results[resultIdx] == 0)
118 return static_cast<int>(g_Results[resultIdx]->
getNum(row, n));
121 int pedigree_config_getnum(
size_t resultIdx,
size_t row,
const char *col)
123 if (resultIdx >= MAX_RESULTS || g_Results[resultIdx] == 0)
125 return static_cast<int>(g_Results[resultIdx]->
getNum(row, col));
128 int pedigree_config_getbool(
size_t resultIdx,
size_t row,
size_t n)
130 if (resultIdx >= MAX_RESULTS || g_Results[resultIdx] == 0)
132 return static_cast<int>(g_Results[resultIdx]->
getBool(row, n));
135 int pedigree_config_getbool(
size_t resultIdx,
size_t row,
const char *col)
137 if (resultIdx >= MAX_RESULTS || g_Results[resultIdx] == 0)
139 return static_cast<int>(g_Results[resultIdx]->
getNum(row, col));
142 int pedigree_config_query(
const char *query)
144 for (
size_t i = 0; i < MAX_RESULTS; i++)
146 if (g_Results[i] == 0)
156 new char[StringLength(pConfigPermissionError) + 1];
157 StringCopy(pError, pConfigPermissionError);
161 g_Results[i] = Config::instance().
query(query);
166 ERROR(
"Insufficient free resultsets.");
170 void pedigree_config_freeresult(
size_t resultIdx)
172 if (resultIdx >= MAX_RESULTS || g_Results[resultIdx] == 0)
174 delete g_Results[resultIdx];
175 g_Results[resultIdx] = 0;
178 int pedigree_config_numcols(
size_t resultIdx)
180 if (resultIdx >= MAX_RESULTS || g_Results[resultIdx] == 0)
182 return g_Results[resultIdx]->
cols();
185 int pedigree_config_numrows(
size_t resultIdx)
187 if (resultIdx >= MAX_RESULTS || g_Results[resultIdx] == 0)
189 return g_Results[resultIdx]->
rows();
192 int pedigree_config_was_successful(
size_t resultIdx)
194 if (resultIdx >= MAX_RESULTS || g_Results[resultIdx] == 0)
196 return (g_Results[resultIdx]->succeeded()) ? 0 : -1;
199 void pedigree_config_get_error_message(
size_t resultIdx,
char *buf,
int buflen)
201 if (resultIdx >= MAX_RESULTS || g_Results[resultIdx] == 0)
203 StringCopyN(buf, g_Results[resultIdx]->errorMessage(), buflen);
209 void pedigree_module_load(
char *_file)
218 SYSCALL_ERROR(DoesNotExist);
228 SYSCALL_ERROR(IsADirectory);
233 uintptr_t buffer = 0;
235 file, buffer, file->getSize(), MemoryMappedObject::Read);
237 reinterpret_cast<uint8_t *>(buffer), file->getSize(),
true);
242 void pedigree_module_unload(
char *name)
248 int pedigree_module_is_loaded(
char *name)
254 int pedigree_module_get_depending(
char *name,
char *buf,
size_t bufsz)
258 StringCopyN(buf, dep, bufsz);
264 void pedigree_input_install_callback(
void *p, uint32_t type, uintptr_t param)
268 static_cast<InputManager::CallbackType>(type),
269 reinterpret_cast<InputManager::callback_t>(p), 0,
273 void pedigree_input_remove_callback(
void *p)
277 reinterpret_cast<InputManager::callback_t>(p), 0,
281 void pedigree_input_inhibit_events(
int inhibit)
284 pThread->
inhibitEvent(EventNumbers::InputEvent, inhibit == 1);
287 int pedigree_load_keymap(uint32_t *buf,
size_t len)
300 int pedigree_gfx_get_provider(
void *p)
318 if (!pService->
serve(
320 reinterpret_cast<void *>(&gfxProvider),
321 sizeof(gfxProvider)))
330 MemoryCopy(p, &gfxProvider,
sizeof(gfxProvider));
335 int pedigree_gfx_get_curr_mode(
void *p,
void *sm)
347 MemoryCopy(sm, &mode,
sizeof(mode));
352 uintptr_t pedigree_gfx_get_raw_buffer(
void *p)
362 physical_uintptr_t ret = 0;
378 int pedigree_gfx_create_buffer(
void *p,
void **b,
void *args)
390 reinterpret_cast<void *>(pArgs->a),
391 static_cast<Graphics::PixelFormat>(pArgs->b), pArgs->c, pArgs->d);
396 int pedigree_gfx_destroy_buffer(
void *p,
void *b)
406 reinterpret_cast<Graphics::Buffer *>(b));
411 void pedigree_gfx_redraw(
void *p,
void *args)
422 pProvider->pFramebuffer->
redraw(
423 pArgs->a, pArgs->b, pArgs->c, pArgs->d, pArgs->e);
426 void pedigree_gfx_blit(
void *p,
void *args)
437 pProvider->pFramebuffer->
blit(
438 pArgs->pBuffer, pArgs->srcx, pArgs->srcy, pArgs->destx, pArgs->desty,
439 pArgs->width, pArgs->height);
442 void pedigree_gfx_set_pixel(
443 void *p, uint32_t x, uint32_t y, uint32_t colour, uint32_t fmt)
453 x, y, colour, static_cast<Graphics::PixelFormat>(fmt));
456 void pedigree_gfx_rect(
void *p,
void *args)
467 pProvider->pFramebuffer->
rect(
468 pArgs->a, pArgs->b, pArgs->c, pArgs->d, pArgs->e,
469 static_cast<Graphics::PixelFormat>(pArgs->f));
472 void pedigree_gfx_copy(
void *p,
void *args)
483 pProvider->pFramebuffer->
copy(
484 pArgs->a, pArgs->b, pArgs->c, pArgs->d, pArgs->e, pArgs->f);
487 void pedigree_gfx_line(
void *p,
void *args)
498 pProvider->pFramebuffer->
line(
499 pArgs->a, pArgs->b, pArgs->c, pArgs->d, pArgs->e,
500 static_cast<Graphics::PixelFormat>(pArgs->f));
503 void pedigree_gfx_draw(
void *p,
void *args)
514 pProvider->pFramebuffer->
draw(
515 pArgs->a, pArgs->b, pArgs->c, pArgs->d, pArgs->e, pArgs->f, pArgs->g,
516 static_cast<Graphics::PixelFormat>(pArgs->h));
519 int pedigree_gfx_create_fbuffer(
void *p,
void *args)
530 pArgs->pReturnProvider);
532 pReturnProvider->pFramebuffer = Graphics::createFramebuffer(
533 pProvider->pFramebuffer, pArgs->x, pArgs->y, pArgs->w, pArgs->h,
534 pArgs->pFramebuffer);
535 if (!pReturnProvider->pFramebuffer)
541 void pedigree_gfx_delete_fbuffer(
void *p)
549 Graphics::destroyFramebuffer(pProvider->pFramebuffer);
552 void pedigree_gfx_fbinfo(
553 void *p,
size_t *w,
size_t *h, uint32_t *fmt,
size_t *bypp)
562 *w = pProvider->pFramebuffer->getWidth();
564 *h = pProvider->pFramebuffer->getHeight();
566 *fmt =
static_cast<uint32_t
>(pProvider->pFramebuffer->getFormat());
568 *bypp = pProvider->pFramebuffer->getBytesPerPixel();
571 void pedigree_gfx_setpalette(
void *p, uint32_t *data,
size_t entries)
579 pProvider->pFramebuffer->
setPalette(data, entries);
582 void pedigree_event_return()
587 FATAL(
"event_return: should never get here");
590 void *pedigree_sys_request_mem(
size_t len)
594 uintptr_t mapAddress = 0;
603 return reinterpret_cast<void *
>(mapAddress);
606 void pedigree_haltfs()
610 NOTICE(
"Stubbed: pedigree_haltfs");
File * find(const String &path, File *pStartNode=0)
size_t cols()
Returns the number of columns.
void inhibitEvent(size_t eventNumber, bool bInhibit)
size_t rows()
Returns the number of rows.
virtual void copy(size_t srcx, size_t srcy, size_t destx, size_t desty, size_t w, size_t h, bool bLowestCall=true)
virtual bool getCurrentScreenMode(ScreenMode &sm)
virtual void blit(Graphics::Buffer *pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty, size_t width, size_t height, bool bLowestCall=true)
virtual void getMapping(void *virtualAddress, physical_uintptr_t &physicalAddress, size_t &flags)=0
int followLink(char *pBuffer, size_t bufLen)
std::string getColumnName(size_t col, size_t buffSz=256)
Returns the name of the col'th column.
Module * loadModule(uint8_t *pModule, size_t len, bool silent=false)
virtual bool isMapped(void *virtualAddress)=0
virtual void destroyBuffer(Graphics::Buffer *pBuffer)
static KeymapManager & instance()
Singleton design.
virtual void * getRawBuffer() const
std::string getStr(size_t row, size_t col, size_t buffSz=256)
Returns the value in column 'col' of the result, in string form.
static ProcessorInformation & information()
virtual bool provides(Type service)
bool allocate(T length, T &address)
static KernelElf & instance()
void unmap(MemoryMappedObject *pObj)
virtual void rect(size_t x, size_t y, size_t width, size_t height, uint32_t colour, Graphics::PixelFormat format=Graphics::Bits32_Argb, bool bLowestCall=true)
void redraw(size_t x=~0UL, size_t y=~0UL, size_t w=~0UL, size_t h=~0UL, bool bChild=false)
size_t getNum(size_t row, size_t col)
Returns the value in column 'col' of the result, in number form.
Memory-mapped file interface.
Result * query(const char *sql)
MemoryAllocator & getDynamicSpaceAllocator()
static MemoryMapManager & instance()
virtual void draw(void *pBuffer, size_t srcx, size_t srcy, size_t destx, size_t desty, size_t width, size_t height, Graphics::PixelFormat format=Graphics::Bits32_Argb, bool bLowestCall=true)
MemoryMappedObject * mapFile(File *pFile, uintptr_t &address, size_t length, MemoryMappedObject::Permissions perms, size_t offset=0, bool bCopyOnWrite=true)
static Symlink * fromFile(File *pF)
void setPixel(size_t x, size_t y, uint32_t colour, Graphics::PixelFormat format=Graphics::Bits32_Argb, bool bLowestCall=true)
Service * getService(const String &serviceName)
void unloadModule(const char *name, bool silent=false, bool progress=true)
bool getBool(size_t row, size_t col)
Returns the value in column 'col' of the result, in boolean form.
virtual bool serve(ServiceFeatures::Type type, void *pData, size_t dataLen)=0
void setPalette(uint32_t *palette, size_t nEntries)
char * getDependingModule(char *name)
virtual bool isDirectory()
virtual void line(size_t x1, size_t y1, size_t x2, size_t y2, uint32_t colour, Graphics::PixelFormat format=Graphics::Bits32_Argb, bool bLowestCall=true)
ServiceFeatures * enumerateOperations(const String &serviceName)
virtual Graphics::Buffer * createBuffer(const void *srcData, Graphics::PixelFormat srcFormat, size_t width, size_t height, uint32_t *pPalette=0)
MemoryAllocator & getSpaceAllocator()