mirror of
https://github.com/drasko/codezero.git
synced 2026-11-25 10:23:54 +01:00
Integrated vm_files with vnodes. execve is not working as expected.
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
/*
|
||||
* Execve test.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <tests.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <alloca.h>
|
||||
|
||||
#define PAGE_SIZE 0x1000
|
||||
|
||||
extern char _start_test_exec[];
|
||||
extern char _end_test_exec[];
|
||||
@@ -19,20 +21,25 @@ int exectest(pid_t parent_of_all)
|
||||
int fd, err;
|
||||
void *exec_start = (void *)_start_test_exec;
|
||||
unsigned long size = _end_test_exec - _start_test_exec;
|
||||
char filename[128];
|
||||
char env_string[30];
|
||||
int left, cnt;
|
||||
char *argv[5];
|
||||
char filename[128];
|
||||
char *envp[2];
|
||||
char env_string[30];
|
||||
void *buf;
|
||||
|
||||
memset(filename, 0, 128);
|
||||
sprintf(filename, "/home/bahadir/execfile%d", getpid());
|
||||
sprintf(filename, "/execfile%d", getpid());
|
||||
|
||||
/* First create a new file and write the executable data to that file */
|
||||
if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
|
||||
err = errno;
|
||||
test_printf("OPEN: %d, for %s\n", errno, filename);
|
||||
/* If it is a minor error like EEXIST, create one with different name */
|
||||
|
||||
/*
|
||||
* If it is a minor error like EEXIST,
|
||||
* create one with different name
|
||||
*/
|
||||
if (errno == EEXIST) {
|
||||
sprintf(filename, "/home/bahadir/execfile%d-2",
|
||||
getpid());
|
||||
@@ -49,7 +56,7 @@ int exectest(pid_t parent_of_all)
|
||||
}
|
||||
|
||||
left = size;
|
||||
test_printf("Writing %d bytes to %s\n", left, filename);
|
||||
test_printf("Writing %x bytes to %s\n", left, filename);
|
||||
while (left != 0) {
|
||||
if ((cnt = write(fd, exec_start, left)) < 0)
|
||||
goto out_err;
|
||||
@@ -60,6 +67,22 @@ int exectest(pid_t parent_of_all)
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
/* Reopen */
|
||||
if ((fd = open(filename, O_RDONLY, S_IRWXU)) < 0) {
|
||||
err = errno;
|
||||
test_printf("OPEN: %d, for %s\n", errno, filename);
|
||||
|
||||
}
|
||||
|
||||
printf("Reopened %s\n", filename);
|
||||
buf = alloca(PAGE_SIZE);
|
||||
read(fd, buf, PAGE_SIZE);
|
||||
|
||||
if (memcmp(exec_start, buf, PAGE_SIZE))
|
||||
printf("First page of read and written file doesn't match\n");
|
||||
else
|
||||
printf("First page matches.\n");
|
||||
|
||||
/* Set up some arguments */
|
||||
argv[0] = "FIRST ARG";
|
||||
argv[1] = "SECOND ARG";
|
||||
|
||||
@@ -17,7 +17,7 @@ int forktest(void)
|
||||
|
||||
|
||||
/* 16 forks */
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int i = 0; i < 1; i++) {
|
||||
test_printf("%d: Forking...\n", getpid());
|
||||
if (fork() < 0)
|
||||
goto out_err;
|
||||
|
||||
Reference in New Issue
Block a user