summaryrefslogtreecommitdiff
path: root/user/usertests.c
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2020-09-24 13:18:54 -0400
committerFrans Kaashoek <[email protected]>2020-10-03 16:36:20 -0400
commit675060882480c21915629750a5a504d9da445ba3 (patch)
tree49de72d59eace518575770f894d9d637ae7667cd /user/usertests.c
parent8c67f96b72b052083f1ac538141a4a16ca0e1b5c (diff)
downloadxv6-labs-675060882480c21915629750a5a504d9da445ba3.tar.gz
xv6-labs-675060882480c21915629750a5a504d9da445ba3.tar.bz2
xv6-labs-675060882480c21915629750a5a504d9da445ba3.zip
When either_copyin/out fails, return an error from write/read
Add a test to check that read/write return an error
Diffstat (limited to 'user/usertests.c')
-rw-r--r--user/usertests.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/user/usertests.c b/user/usertests.c
index 004c948..7300574 100644
--- a/user/usertests.c
+++ b/user/usertests.c
@@ -233,6 +233,53 @@ copyinstr3(char *s)
}
}
+// See if the kernel refuses to read/write user memory that the
+// application doesn't have anymore, because it returned it.
+void
+rwsbrk()
+{
+ int fd, n;
+
+ uint64 a = (uint64) sbrk(8192);
+
+ if(a == 0xffffffffffffffffLL) {
+ printf("sbrk(rwsbrk) failed\n");
+ exit(1);
+ }
+
+ if ((uint64) sbrk(-8192) == 0xffffffffffffffffLL) {
+ printf("sbrk(rwsbrk) shrink failed\n");
+ exit(1);
+ }
+
+ fd = open("rwsbrk", O_CREATE|O_WRONLY);
+ if(fd < 0){
+ printf("open(rwsbrk) failed\n");
+ exit(1);
+ }
+ n = write(fd, (void*)(a+4096), 1024);
+ if(n >= 0){
+ printf("write(fd, %p, 1024) returned %d, not -1\n", a+4096, n);
+ exit(1);
+ }
+ close(fd);
+ unlink("rwsbrk");
+
+ fd = open("README", O_RDONLY);
+ if(fd < 0){
+ printf("open(rwsbrk) failed\n");
+ exit(1);
+ }
+ n = read(fd, (void*)(a+4096), 10);
+ if(n >= 0){
+ printf("read(fd, %p, 10) returned %d, not -1\n", a+4096, n);
+ exit(1);
+ }
+ close(fd);
+
+ exit(0);
+}
+
// test O_TRUNC.
void
truncate1(char *s)
@@ -2644,6 +2691,7 @@ main(int argc, char *argv[])
{copyinstr1, "copyinstr1"},
{copyinstr2, "copyinstr2"},
{copyinstr3, "copyinstr3"},
+ {rwsbrk, "rwsbrk" },
{truncate1, "truncate1"},
{truncate2, "truncate2"},
{truncate3, "truncate3"},