Skip to content

Commit

Permalink
Add support for readlinkat syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
janisozaur authored and rocallahan committed Nov 5, 2015
1 parent ca686c1 commit e64e82e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ set(BASIC_TESTS
read_nothing
readdir
readlink
readlinkat
readv
rlimit
robust_futex
Expand Down
7 changes: 7 additions & 0 deletions src/record_syscall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2036,6 +2036,13 @@ static Switchable rec_prepare_syscall_arch(Task* t,
return PREVENT_SWITCH;
}

case Arch::readlinkat: {
syscall_state.reg_parameter(
3, ParamSize::from_syscall_result<typename Arch::ssize_t>(
(size_t)t->regs().arg4()));
return PREVENT_SWITCH;
}

case Arch::getgroups: {
// We could record a little less data by restricting the recorded data
// to the syscall result * sizeof(Arch::legacy_gid_t), but that would
Expand Down
2 changes: 1 addition & 1 deletion src/syscalls.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ def __init__(self, **kwargs):
renameat = UnsupportedSyscall(x86=302, x64=264)
linkat = UnsupportedSyscall(x86=303, x64=265)
symlinkat = UnsupportedSyscall(x86=304, x64=266)
readlinkat = UnsupportedSyscall(x86=305, x64=267)
readlinkat = IrregularEmulatedSyscall(x86=305, x64=267)
fchmodat = UnsupportedSyscall(x86=306, x64=268)

# int faccessat(int dirfd, const char *pathname, int mode, int flags)
Expand Down
42 changes: 42 additions & 0 deletions src/test/readlinkat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */

#include "rrutil.h"

#define BUF_SIZE 10
#define BUF2_SIZE 1000

int main(int argc, char* argv[]) {
char path[] = "rr-test-file-XXXXXX";
char dpath[] = "rr-test-dir-XXXXXX";
const char *dir_path = mkdtemp(dpath);
int count;
char link[PATH_MAX];
char* buf = allocate_guard(BUF_SIZE, 'q');
char* buf2 = allocate_guard(BUF2_SIZE, 'r');

test_assert(0 <= dirfd);

chdir(dir_path);

for (count = 0;; ++count) {
sprintf(link, "rr-test-link-%d", count);
int ret = symlink(path, link);
if (ret == 0) {
break;
}
test_assert(errno == EEXIST);
}
int ret = readlinkat(AT_FDCWD, link, buf, BUF_SIZE);
test_assert(BUF_SIZE == ret);
test_assert(0 == memcmp(path, buf, BUF_SIZE));
verify_guard(BUF_SIZE, buf);

test_assert(strlen(path) == readlinkat(AT_FDCWD, link, buf2, BUF2_SIZE));
test_assert(0 == memcmp(path, buf2, strlen(path)));
verify_guard(BUF2_SIZE, buf2);

test_assert(0 == unlink(link));

atomic_puts("EXIT-SUCCESS");
return 0;
}

0 comments on commit e64e82e

Please sign in to comment.