Skip to content

Commit

Permalink
[LibOS] Fix flag printing in syscall parser
Browse files Browse the repository at this point in the history
Previously, Gramine assumed the existence of mapping type in mmap flags
on syscall arg parsing. It had assertions on such flags which could lead
to failures in debug mode in case of missing them. Besides, Gramine also
incorrectly parsed file access modes in open flags.

This commit fixes the above issues and makes Gramine fail with the same
error on syscall handling as Linux does (on incorrect flags).

Signed-off-by: Kailun Qin <kailun.qin@intel.com>
  • Loading branch information
kailun-qin authored and dimakuv committed Sep 3, 2023
1 parent 22114b5 commit 39b529f
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions libos/src/libos_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,14 +688,21 @@ static int parse_flags(struct print_buf* buf, int flags, const struct flag_table
static void parse_open_flags(struct print_buf* buf, va_list* ap) {
int flags = va_arg(*ap, int);

if (flags & O_WRONLY) {
buf_puts(buf, "O_WRONLY");
flags &= ~O_WRONLY;
} else if (flags & O_RDWR) {
buf_puts(buf, "O_RDWR");
flags &= ~O_RDWR;
} else {
buf_puts(buf, "O_RDONLY");
switch (flags & O_ACCMODE) {
case O_RDONLY:
buf_puts(buf, "O_RDONLY");
flags &= ~O_RDONLY;
break;
case O_WRONLY:
buf_puts(buf, "O_WRONLY");
flags &= ~O_WRONLY;
break;
case O_RDWR:
buf_puts(buf, "O_RDWR");
flags &= ~O_RDWR;
break;
default:
break;
}

if (flags & O_APPEND) {
Expand Down Expand Up @@ -833,8 +840,7 @@ static void parse_mmap_flags(struct print_buf* buf, va_list* ap) {
} else if (flags & MAP_SHARED) {
buf_puts(buf, "MAP_SHARED");
flags &= ~MAP_SHARED;
} else {
assert(flags & MAP_PRIVATE);
} else if (flags & MAP_PRIVATE) {
buf_puts(buf, "MAP_PRIVATE");
flags &= ~MAP_PRIVATE;
}
Expand Down

0 comments on commit 39b529f

Please sign in to comment.