44 lines
921 B
C
44 lines
921 B
C
#include <sys/mman.h>
|
|
#include <fcntl.h>
|
|
|
|
#include "gebs/gebs.h"
|
|
#include "stb/stb_ds.h"
|
|
|
|
#include "tmpls.h"
|
|
#include "baked.h"
|
|
|
|
Template *tmpls = NULL;
|
|
|
|
void create_tmpl(char *name, const unsigned char *data, size_t size)
|
|
{
|
|
int fd = memfd_create(name, 0);
|
|
if (fd < 0) {
|
|
LOGE("Could not create file for template %s. Aborting...\n", name);
|
|
abort();
|
|
}
|
|
write(fd, data, size);
|
|
|
|
shput(tmpls, name, fd);
|
|
}
|
|
|
|
void tmpls_init(void)
|
|
{
|
|
create_tmpl(TMPL_HOME, tmpl_home_data, tmpl_home_size);
|
|
create_tmpl(TMPL_PAGE_MISSING, tmpl_page_missing_data, tmpl_page_missing_size);
|
|
}
|
|
|
|
void tmpls_deinit(void)
|
|
{
|
|
shfree(tmpls);
|
|
}
|
|
|
|
void tmpl_get_path_by_key(char *key, char *buf, size_t size)
|
|
{
|
|
// Check first since we can't have a default value here
|
|
if (shgeti(tmpls, key) != -1) {
|
|
int fd = shget(tmpls, key);
|
|
snprintf(buf, size, "/proc/%d/fd/%d", getpid(), fd);
|
|
}
|
|
}
|
|
|