From ab03c1cdce90660dcb75d000ebda817ae589aaec Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Sat, 5 May 2018 00:04:13 +0100 Subject: Fix handling of errno if external functions are invoked If an external function in KLEE is invoked, it might update errno. Previously, the errno specific variable in a state was only updated if it was part of the executed instructions. That opened up a timeframe that increased the likelihood of errno being overwritten by another method call. This patch fixes two issues: * the errno of the KLEE process state is updated before the external function call allowing to detect changes to it later on * after the external call, the memory object of errno is directly updated with its new value, reducing the likelihood to be overwritten by another call Additional features: * Add support for `errno()` for Darwin as well. * Simplified errno handling in POSIX layer --- test/Runtime/POSIX/DirSeek.c | 12 ++++++------ test/Runtime/POSIX/Ioctl.c | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/Runtime/POSIX/DirSeek.c b/test/Runtime/POSIX/DirSeek.c index 3908b4e2..4c68a30c 100644 --- a/test/Runtime/POSIX/DirSeek.c +++ b/test/Runtime/POSIX/DirSeek.c @@ -1,4 +1,4 @@ -// RUN: %llvmgcc %s -emit-llvm -O0 -c -o %t2.bc +// RUN: %llvmgcc %s -emit-llvm -O0 -c -g -o %t2.bc // RUN: rm -rf %t.klee-out %t.klee-out-tmp // RUN: %gentmp %t.klee-out-tmp // RUN: %klee --output-dir=%t.klee-out --run-in=%t.klee-out-tmp --libc=uclibc --posix-runtime --exit-on-error %t2.bc --sym-files 2 2 @@ -11,8 +11,8 @@ // For this test really to work as intended it needs to be run in a // directory large enough to cause uclibc to do multiple getdents -// calls (otherwise uclibc will handle the seeks itself). We should -// create a bunch of files or something. +// calls (otherwise uclibc will handle the seeks itself). +// Therefore gentmp generates a directory with a specific amount of entries #include #include @@ -29,7 +29,6 @@ int main(int argc, char **argv) { assert(de); strcpy(first, de->d_name); off_t pos = telldir(d); - printf("pos: %ld\n", telldir(d)); de = readdir(d); assert(de); strcpy(second, de->d_name); @@ -41,9 +40,10 @@ int main(int argc, char **argv) { assert(strcmp(de->d_name, second) == 0); // Go to end, then back to 2nd - while (de) + while (de) { de = readdir(d); - assert(!errno); + assert(!errno); + } seekdir(d, pos); assert(telldir(d) == pos); de = readdir(d); diff --git a/test/Runtime/POSIX/Ioctl.c b/test/Runtime/POSIX/Ioctl.c index e8220276..f1caaf77 100644 --- a/test/Runtime/POSIX/Ioctl.c +++ b/test/Runtime/POSIX/Ioctl.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include -- cgit 1.4.1