Skip to content
Snippets Groups Projects
Commit 6d93dc4b authored by Julien Signoles's avatar Julien Signoles
Browse files

Merge branch 'kostyantyn/bugfix/stdstream' into 'master'

Add stdin, stderr and stdout to safe locations

See merge request !117
parents 811e4f68 ce668e76
No related branches found
No related tags found
No related merge requests found
...@@ -67,8 +67,19 @@ extern __thread int errno; ...@@ -67,8 +67,19 @@ extern __thread int errno;
# error "Unknown convention for errno definition" # error "Unknown convention for errno definition"
#endif #endif
/* TODO: May not be utterly portable */
#include <libio.h>
extern struct _IO_FILE *stdin; /* Standard input stream. */
extern struct _IO_FILE *stdout; /* Standard output stream. */
extern struct _IO_FILE *stderr; /* Standard error output stream. */
void collect_safe_locations() { void collect_safe_locations() {
/* Tracking of errno */ /* Tracking of errno */
add_safe_location((uintptr_t)&errno, sizeof(int), "errno"); add_safe_location((uintptr_t)&errno, sizeof(int), "errno");
/* Tracking standard streams */
add_safe_location((uintptr_t)stdout, sizeof(struct _IO_FILE), "stdout");
add_safe_location((uintptr_t)stderr, sizeof(struct _IO_FILE), "stderr");
add_safe_location((uintptr_t)stdin, sizeof(struct _IO_FILE), "stdin");
} }
#endif #endif
...@@ -155,6 +155,7 @@ static void memory_init(int *argc_ref, char *** argv_ref, size_t ptr_size) { ...@@ -155,6 +155,7 @@ static void memory_init(int *argc_ref, char *** argv_ref, size_t ptr_size) {
collect_safe_locations(); collect_safe_locations();
int i; int i;
for (i = 0; i < safe_location_counter; i++) { for (i = 0; i < safe_location_counter; i++) {
DLOG("Safe location %lu\n", safe_locations[i].address, safe_locations[i].address + safe_locations[i].length);
void *addr = (void*)safe_locations[i].address; void *addr = (void*)safe_locations[i].address;
uintptr_t len = safe_locations[i].length; uintptr_t len = safe_locations[i].length;
shadow_alloca(addr, len); shadow_alloca(addr, len);
......
...@@ -71,7 +71,7 @@ char *strerror(int errnum); ...@@ -71,7 +71,7 @@ char *strerror(int errnum);
#define PGM_HEAP_SIZE (256 * MB) #define PGM_HEAP_SIZE (256 * MB)
/*! \brief Size of a program's Thread-local storage (TLS) */ /*! \brief Size of a program's Thread-local storage (TLS) */
#define PGM_TLS_SIZE (8 * MB) #define PGM_TLS_SIZE (16 * MB)
/* }}} */ /* }}} */
/** Thread-local storage information {{{ */ /** Thread-local storage information {{{ */
......
/* Generated by Frama-C */ /* Generated by Frama-C */
#include "stdio.h" #include "stdio.h"
#include "stdlib.h" #include "stdlib.h"
char *__gen_e_acsl_literal_string_2;
char *__gen_e_acsl_literal_string;
void __e_acsl_globals_init(void) void __e_acsl_globals_init(void)
{ {
__gen_e_acsl_literal_string_2 = "wb";
__e_acsl_store_block((void *)__gen_e_acsl_literal_string_2,sizeof("wb"));
__e_acsl_full_init((void *)__gen_e_acsl_literal_string_2);
__e_acsl_readonly((void *)__gen_e_acsl_literal_string_2);
__gen_e_acsl_literal_string = "/tmp/foo";
__e_acsl_store_block((void *)__gen_e_acsl_literal_string,
sizeof("/tmp/foo"));
__e_acsl_full_init((void *)__gen_e_acsl_literal_string);
__e_acsl_readonly((void *)__gen_e_acsl_literal_string);
__e_acsl_store_block((void *)(& stdout),(size_t)8); __e_acsl_store_block((void *)(& stdout),(size_t)8);
__e_acsl_full_init((void *)(& stdout)); __e_acsl_full_init((void *)(& stdout));
__e_acsl_store_block((void *)(& stdin),(size_t)8);
__e_acsl_full_init((void *)(& stdin));
__e_acsl_store_block((void *)(& stderr),(size_t)8);
__e_acsl_full_init((void *)(& stderr));
return; return;
} }
int main(void) int main(void)
{ {
int __retres; int __retres;
FILE *f;
FILE *f2;
__e_acsl_memory_init((int *)0,(char ***)0,(size_t)8); __e_acsl_memory_init((int *)0,(char ***)0,(size_t)8);
__e_acsl_globals_init(); __e_acsl_globals_init();
__e_acsl_store_block((void *)(& f),(size_t)8); /*@ assert \valid(__fc_stderr); */
__e_acsl_full_init((void *)(& f)); {
f = stdout; {
f2 = __gen_e_acsl_fopen(__gen_e_acsl_literal_string, int __gen_e_acsl_valid;
__gen_e_acsl_literal_string_2); __gen_e_acsl_valid = __e_acsl_valid((void *)stderr,sizeof(FILE));
/*@ assert f ≡ __fc_stdout; */ __e_acsl_assert(__gen_e_acsl_valid,(char *)"Assertion",(char *)"main",
__e_acsl_assert(f == stdout,(char *)"Assertion",(char *)"main", (char *)"\\valid(__fc_stderr)",8);
(char *)"f == __fc_stdout",10); }
}
/*@ assert \valid(__fc_stdin); */
{
{
int __gen_e_acsl_valid_2;
__gen_e_acsl_valid_2 = __e_acsl_valid((void *)stdin,sizeof(FILE));
__e_acsl_assert(__gen_e_acsl_valid_2,(char *)"Assertion",
(char *)"main",(char *)"\\valid(__fc_stdin)",9);
}
}
/*@ assert \valid(__fc_stdout); */
{
{
int __gen_e_acsl_valid_3;
__gen_e_acsl_valid_3 = __e_acsl_valid((void *)stdout,sizeof(FILE));
__e_acsl_assert(__gen_e_acsl_valid_3,(char *)"Assertion",
(char *)"main",(char *)"\\valid(__fc_stdout)",10);
}
}
__retres = 0; __retres = 0;
__e_acsl_delete_block((void *)(& stdout)); __e_acsl_delete_block((void *)(& stdout));
__e_acsl_delete_block((void *)(& f)); __e_acsl_delete_block((void *)(& stdin));
__e_acsl_delete_block((void *)(& stderr));
__e_acsl_memory_clean(); __e_acsl_memory_clean();
return __retres; return __retres;
} }
......
[e-acsl] beginning translation. [e-acsl] beginning translation.
[e-acsl] warning: annotating undefined function `fopen':
the generated program may miss memory instrumentation
if there are memory-related annotations.
FRAMAC_SHARE/libc/stdlib.h:277:[kernel] warning: No code nor implicit assigns clause for function calloc, generating default assigns from the prototype FRAMAC_SHARE/libc/stdlib.h:277:[kernel] warning: No code nor implicit assigns clause for function calloc, generating default assigns from the prototype
tests/runtime/stdout.c:10:[e-acsl] warning: E-ACSL construct `assigns clause in behavior' is not yet supported.
Ignoring annotation.
FRAMAC_SHARE/libc/stdio.h:109:[e-acsl] warning: E-ACSL construct `logic function application' is not yet supported.
Ignoring annotation.
[e-acsl] translation done in project "e-acsl". [e-acsl] translation done in project "e-acsl".
tests/runtime/stdout.c:10:[value] warning: assertion got status unknown. tests/runtime/stdout.c:8:[value] warning: assertion got status unknown.
FRAMAC_SHARE/e-acsl/e_acsl.h:43:[value] warning: function __e_acsl_assert: precondition got status unknown. FRAMAC_SHARE/e-acsl/e_acsl.h:43:[value] warning: function __e_acsl_assert: precondition got status unknown.
tests/runtime/stdout.c:9:[value] warning: assertion got status unknown.
tests/runtime/stdout.c:10:[value] warning: assertion got status unknown.
/* run.config /* run.config
COMMENT: __fc_stdout et __fc_fopen COMMENT: ensure that standard streams are properly tracked
*/ */
#include<stdio.h> #include <stdio.h>
int main(){ int main(void) {
FILE *f = stdout; /*@assert \valid(stderr); */
FILE *f2 = fopen("/tmp/foo","wb"); /*@assert \valid(stdin); */
//@ assert f == stdout; /*@assert \valid(stdout); */
return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment