Skip to content

Commit

Permalink
[LibOS] Remove shim_str and shim_qstr
Browse files Browse the repository at this point in the history
We have replaced all usages with regular heap-allocated C strings.

Signed-off-by: Paweł Marczewski <[email protected]>
  • Loading branch information
pwmarcz committed Dec 6, 2021
1 parent afda07d commit 76f8f66
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 206 deletions.
8 changes: 5 additions & 3 deletions LibOS/shim/include/shim_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "shim_lock.h"
#include "shim_types.h"

#define CMDLINE_SIZE 4096

DEFINE_LIST(shim_child_process);
DEFINE_LISTP(shim_child_process);
struct shim_child_process {
Expand Down Expand Up @@ -60,9 +62,9 @@ struct shim_process {
struct shim_lock fs_lock;

/* Complete command line for the process, as reported by /proc/[pid]/cmdline; currently filled
* once during initialization, using static buffer and restricted to STR_SIZE. This is enough
* for current workloads but see https://github.com/gramineproject/gramine/issues/79. */
char cmdline[STR_SIZE];
* once during initialization, using static buffer and restricted to CMDLINE_SIZE. This is
* enough for current workloads but see https://github.com/gramineproject/gramine/issues/79. */
char cmdline[CMDLINE_SIZE];
size_t cmdline_size;
};

Expand Down
16 changes: 0 additions & 16 deletions LibOS/shim/include/shim_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,22 +347,6 @@ typedef struct shim_aevent {
PAL_HANDLE event;
} AEVENTTYPE;

#define STR_SIZE 4096

struct shim_str {
char str[STR_SIZE];
};

#define QSTR_SIZE 32

/* Use qstr for names. This has fixed size string + string object
* if len > SHIM_QSTR_SIZE then use overflow string */
struct shim_qstr {
size_t len;
char name[QSTR_SIZE];
struct shim_str* oflow;
};

/* maximum length of pipe/FIFO name (should be less than Linux sockaddr_un.sun_path = 108) */
#define PIPE_URI_SIZE 96

Expand Down
107 changes: 0 additions & 107 deletions LibOS/shim/include/shim_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,113 +26,6 @@ static inline uint64_t hash64(uint64_t key) {
return key;
}

/* string object */
struct shim_str* get_str_obj(void);
int free_str_obj(struct shim_str* str);
int init_str_mgr(void);

/* qstring object */
#define QSTR_INIT \
{ .len = 0, .oflow = NULL }

static inline const char* qstrgetstr(const struct shim_qstr* qstr) {
return qstr->oflow ? qstr->oflow->str : qstr->name;
}

static inline void qstrfree(struct shim_qstr* qstr) {
if (qstr->oflow) {
free_str_obj(qstr->oflow);
qstr->oflow = NULL;
}

qstr->name[0] = 0;
qstr->len = 0;
}

static inline char* qstrsetstr(struct shim_qstr* qstr, const char* str, size_t len) {
if (!str) {
qstrfree(qstr);
return NULL;
}

if (len >= STR_SIZE)
return NULL;

char* buf = qstr->name;

if (len >= QSTR_SIZE) {
if (!qstr->oflow) {
qstr->oflow = get_str_obj();
if (!qstr->oflow)
return NULL;
}
buf = qstr->oflow->str;
} else {
if (qstr->oflow) {
free_str_obj(qstr->oflow);
qstr->oflow = NULL;
}
}

memcpy(buf, str, len);
buf[len] = 0;
qstr->len = len;

return buf;
}

static inline char* qstrsetstrs(struct shim_qstr* qstr, int nstrs, const char** strs,
size_t* lengths) {
size_t total_len = 0;

for (int i = 0; i < nstrs; i++) {
total_len += lengths[i];
}

if (total_len >= STR_SIZE)
return NULL;

char* buf = qstr->name;

if (total_len >= QSTR_SIZE) {
if (!qstr->oflow) {
// TODO: alloc proper size.
qstr->oflow = get_str_obj();
if (!qstr->oflow)
return NULL;
}
buf = qstr->oflow->str;
}

char* ptr = buf;
qstr->len = 0;

for (int i = 0; i < nstrs; i++) {
size_t len = lengths[i];
memcpy(ptr, strs[i], len);
ptr[len] = 0;
qstr->len += len;
ptr += len;
}

return buf;
}

static inline int qstrempty(const struct shim_qstr* qstr) {
return qstr->len == 0;
}

static inline void qstrcopy(struct shim_qstr* to, const struct shim_qstr* from) {
qstrsetstr(to, qstrgetstr(from), from->len);
}

static inline int qstrcmpstr(const struct shim_qstr* qstr, const char* str, size_t len) {
if (qstr->len != len)
return 1;

return memcmp(qstrgetstr(qstr), str, len);
}

/* heap allocation functions */
int init_slab(void);

Expand Down
1 change: 0 additions & 1 deletion LibOS/shim/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ libos_sources = files(
'sys/shim_wait.c',
'sys/shim_wrappers.c',
'utils/log.c',
'utils/strobjs.c',
)

libos_sources_arch = [
Expand Down
31 changes: 0 additions & 31 deletions LibOS/shim/src/shim_checkpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,37 +185,6 @@ BEGIN_RS_FUNC(migratable) {
}
END_RS_FUNC(migratable)

BEGIN_CP_FUNC(qstr) {
__UNUSED(size);
__UNUSED(objp);

struct shim_qstr* qstr = (struct shim_qstr*)obj;

/* qstr is always embedded as sub-object in other objects so it is automatically checkpointed as
* part of other checkpoint routines. However, its oflow string resides in some other memory
* region and must be checkpointed and restored explicitly. Copy oflow string inside checkpoint
* right before qstr cp entry. */
if (qstr->oflow) {
struct shim_str* str = (struct shim_str*)(base + ADD_CP_OFFSET(qstr->len + 1));
memcpy(str, qstr->oflow, qstr->len + 1);
ADD_CP_FUNC_ENTRY((uintptr_t)qstr - base);
}
}
END_CP_FUNC(qstr)

BEGIN_RS_FUNC(qstr) {
__UNUSED(offset);
__UNUSED(rebase);

/* If we are here, qstr has oflow string. We know that oflow string is right before this qstr cp
* entry (aligned to 8B). Calculate oflow string's base and update qstr to point to it. */
struct shim_qstr* qstr = (struct shim_qstr*)(base + GET_CP_FUNC_ENTRY());
size_t size = qstr->len + 1;
size = ALIGN_UP(size, sizeof(uintptr_t));
qstr->oflow = (void*)entry - size;
}
END_RS_FUNC(qstr)

/* Checkpoints a C string (char*). */
BEGIN_CP_FUNC(str) {
__UNUSED(size);
Expand Down
1 change: 0 additions & 1 deletion LibOS/shim/src/shim_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ noreturn void* shim_init(int argc, const char** argv, const char** envp) {
RUN_INIT(init_vma);
RUN_INIT(init_slab);
RUN_INIT(read_environs, envp);
RUN_INIT(init_str_mgr);
RUN_INIT(init_rlimit);
RUN_INIT(init_fs);
RUN_INIT(init_fs_lock);
Expand Down
47 changes: 0 additions & 47 deletions LibOS/shim/src/utils/strobjs.c

This file was deleted.

0 comments on commit 76f8f66

Please sign in to comment.