libc: refactoring

This commit is contained in:
Giacomo Tesio 2019-11-28 02:35:52 +01:00
parent f104c46858
commit 4067cb45cb
75 changed files with 596 additions and 355 deletions

View File

@ -1,7 +1,6 @@
{
"buildflags": {
"Cflags": [
"--sysroot=$JEHANNE",
"-fno-builtin",
"-fno-omit-frame-pointer",
"-fplan9-extensions",

102
arch/amd64/include/limits.h Normal file
View File

@ -0,0 +1,102 @@
/*
* This file is part of Jehanne.
*
* Copyright (C) 2016-2019 Giacomo Tesio <giacomo@tesio.it>
*
* Jehanne is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Jehanne is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _JEHANNE_LIMITS_H
#define _JEHANNE_LIMITS_H
#undef CHAR_BIT
#define CHAR_BIT __CHAR_BIT__
#ifndef MB_LEN_MAX
#define MB_LEN_MAX 4 /* UTFmax in libc.h */
#endif
#define SCHAR_MAX 127
#define SCHAR_MIN (-128)
#define UCHAR_MAX (SCHAR_MAX * 2 + 1)
/* Jehanne's chars are signed */
#define CHAR_MIN SCHAR_MIN
#define CHAR_MAX SCHAR_MAX
#define SHRT_MIN (-32768)
#define SHRT_MAX 32767
#define USHRT_MAX 65535
#define INT_MIN (-INT_MAX - 1)
#define INT_MAX 2147483647
#define UINT_MAX 4294967295U
#define LONG_MAX 9223372036854775807L
#define LONG_MIN (-LONG_MAX - 1L)
#define ULONG_MAX 18446744073709551615UL
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
/* Minimum and maximum values a `signed long long int' can hold. */
#define LLONG_MAX 9223372036854775807LL
#define LLONG_MIN (-LLONG_MAX - 1LL)
/* Maximum value an `unsigned long long int' can hold. (Minimum is 0.) */
# define ULLONG_MAX 18446744073709551615ULL
# endif /* ISO C99 */
#if defined (__GNU_LIBRARY__) ? defined (__USE_GNU) : !defined (__STRICT_ANSI__)
/* Minimum and maximum values a `signed long long int' can hold. */
# undef LONG_LONG_MIN
# define LONG_LONG_MIN (-LONG_LONG_MAX - 1LL)
# undef LONG_LONG_MAX
# define LONG_LONG_MAX 9223372036854775807L
/* Maximum value an `unsigned long long int' can hold. (Minimum is 0). */
# undef ULONG_LONG_MAX
# define ULONG_LONG_MAX (LONG_LONG_MAX * 2ULL + 1ULL)
#endif
#ifdef __STDC_WANT_IEC_60559_BFP_EXT__
/* TS 18661-1 widths of integer types. */
# undef CHAR_WIDTH
# define CHAR_WIDTH 8
# undef SCHAR_WIDTH
# define SCHAR_WIDTH 8
# undef UCHAR_WIDTH
# define UCHAR_WIDTH 8
# undef SHRT_WIDTH
# define SHRT_WIDTH 16
# undef USHRT_WIDTH
# define USHRT_WIDTH 16
# undef INT_WIDTH
# define INT_WIDTH 32
# undef UINT_WIDTH
# define UINT_WIDTH 32
# undef LONG_WIDTH
# define LONG_WIDTH 64
# undef ULONG_WIDTH
# define ULONG_WIDTH 64
# undef LLONG_WIDTH
# define LLONG_WIDTH 64
# undef ULLONG_WIDTH
# define ULLONG_WIDTH 64
#endif
#endif /* _LIMITS_H___ */

View File

@ -32,20 +32,20 @@ main(void)
print("FAIL: open: %r\n");
exits("FAIL");
}
if(write(fd, r, sizeof(r)) < 0){
if(jehanne_write(fd, r, sizeof(r)) < 0){
print("FAIL: fprint: %r\n");
exits("FAIL");
}
close(fd);
if((fd = open("/tmp/runetest.txt", OREAD)) < 0) {
sys_close(fd);
if((fd = sys_open("/tmp/runetest.txt", OREAD)) < 0) {
print("FAIL: open: %r\n");
exits("FAIL");
}
if(read(fd, (char*)buf, sizeof(buf)) < 0){
if(jehanne_read(fd, (char*)buf, sizeof(buf)) < 0){
print("FAIL: read: %r\n");
exits("FAIL");
}
close(fd);
sys_close(fd);
if (runestrcmp(r, buf) != 0){
print("FAIL: got '%S' instead of '%S'.\n", buf, r);
exits("FAIL");

View File

@ -68,12 +68,12 @@ main(void)
exits("atnotify fails");
}
alarm(2000);
sys_alarm(2000);
a2000 = nsec();
alarm(500);
sys_alarm(500);
a500 = nsec();
rendezvous(&a500, (void*)0x123);
sys_rendezvous(&a500, (void*)0x123);
if(verbose)
fprint(2, "%d: set alarm(2000)@%lld then alarm(500)@%lld; received after %lld nanosecond\n", getpid(), a2000, a500, alarmReceived-a500);

View File

@ -40,7 +40,7 @@ writeTillBlock(int fd)
memset(buf, 1, sizeof(buf));
while(i < 300) /* pipes should block after at most 256kb */
{
if(write(fd, buf, sizeof(buf)) < 0){
if(jehanne_write(fd, buf, sizeof(buf)) < 0){
break;
}
++i;
@ -56,21 +56,21 @@ main(void)
int fds[2];
char buf[1];
semacquire(&sem, 0);
sys_semacquire(&sem, 0);
alarm(40000); /* global timeout, FAIL if reached */
sys_alarm(40000); /* global timeout, FAIL if reached */
if (!atnotify(failOnTimeout, 1)){
fprint(2, "%r\n");
exits("atnotify fails");
}
awake(100000); /* this will be handled by the kernel, see pexit */
sys_awake(100000); /* this will be handled by the kernel, see pexit */
/* verify that rendezvous are interrupted */
fprint(2, "verify that rendezvous are interrupted\n", elapsed);
wkup = awake(1000);
wkup = sys_awake(1000);
start = nsec();
res = (int64_t)rendezvous(&elapsed, (void*)0x12345);
res = (int64_t)sys_rendezvous(&elapsed, (void*)0x12345);
elapsed = (nsec() - start) / (1000 * 1000);
if(verbose)
fprint(2, "rendezvous interrupted, returned %#p, elapsed = %d ms\n", res, elapsed);
@ -82,7 +82,7 @@ main(void)
/* verify that sleeps are NOT interrupted */
fprint(2, "verify that sleeps are NOT interrupted\n", elapsed);
wkup = awake(700);
wkup = sys_awake(700);
start = nsec();
sleep(1500);
elapsed = (nsec() - start) / (1000 * 1000);
@ -97,11 +97,11 @@ main(void)
/* verify that semacquires are interrupted */
fprint(2, "verify that semacquires are interrupted\n", elapsed);
pipe(fds);
wkup = awake(1000);
wkup = sys_awake(1000);
start = nsec();
if(verbose)
print("semacquire(&sem, 1)...\n");
res = semacquire(&sem, 1);
res = sys_semacquire(&sem, 1);
elapsed = (nsec() - start) / (1000 * 1000);
if(verbose)
print("semacquire(&sem, 1): returned %lld, elapsed = %d ms\n", res, elapsed);
@ -114,7 +114,7 @@ main(void)
/* verify that tsemacquire are NOT interrupted */
fprint(2, "verify that tsemacquire are NOT interrupted\n", elapsed);
start = nsec();
wkup = awake(500);
wkup = sys_awake(500);
res = tsemacquire(&sem, 1500);
elapsed = (nsec() - start) / (1000 * 1000);
if(verbose)
@ -131,9 +131,9 @@ main(void)
print("FAIL: pipe\n");
exits("FAIL");
}
wkup = awake(1000);
wkup = sys_awake(1000);
start = nsec();
res = read(fds[0], buf, 1);
res = jehanne_read(fds[0], buf, 1);
elapsed = (nsec() - start) / (1000 * 1000);
if(verbose)
fprint(2, "read(fds[0], buf, 1) returned %lld, elapsed = %d ms\n", res, elapsed);
@ -149,7 +149,7 @@ main(void)
print("FAIL: pipe\n");
exits("FAIL");
}
wkup = awake(1000);
wkup = sys_awake(1000);
start = nsec();
res = writeTillBlock(fds[0]);
elapsed = (nsec() - start) / (1000 * 1000);

View File

@ -22,8 +22,8 @@ void
handler(void *v, char *s)
{
int64_t wakeup;
wakeup = awake(1000);
while(rendezvous(&wakeup, (void*)1) == (void*)~0)
wakeup = sys_awake(1000);
while(sys_rendezvous(&wakeup, (void*)1) == (void*)~0)
if(jehanne_awakened(wakeup)){
print("PASS\n");
exits(nil);
@ -39,12 +39,12 @@ main(int argc, char**argv)
if(argc > 1){
fd = ocreate(argv[1], OWRITE, 0666);
dup(fd, 1);
close(fd);
sys_close(fd);
}
if (notify(handler)){
if (sys_notify(handler)){
fprint(2, "%r\n");
exits("notify fails");
exits("sys_notify fails");
}
print("%s %d: waiting for note", argv[0], getpid());

View File

@ -22,8 +22,8 @@ void
handler(void *v, char *s)
{
int64_t wakeup;
wakeup = awake(1000);
while(rendezvous(&wakeup, (void*)1) == (void*)~0)
wakeup = sys_awake(1000);
while(sys_rendezvous(&wakeup, (void*)1) == (void*)~0)
if(jehanne_awakened(wakeup)){
print("PASS\n");
exits(nil);
@ -40,12 +40,12 @@ main(int argc, char**argv)
if(argc > 1){
fd = ocreate(argv[1], OWRITE, 0666);
dup(fd, 1);
close(fd);
sys_close(fd);
}
if (notify(handler)){
if (sys_notify(handler)){
fprint(2, "%r\n");
exits("notify fails");
exits("sys_notify fails");
}
print("%s %d: waiting for note", argv[0], getpid());

View File

@ -23,7 +23,7 @@ main(void)
{
long b, b1;
b = create("#0/brk/set", -1, 16*1024*1024);
b = sys_create("#0/brk/set", -1, 16*1024*1024);
if(b >= 0){
print("FAIL: create returned fd %d.\n", b);
exits("FAIL");

View File

@ -1,8 +1,8 @@
#!/cmd/rc
rfork
sys_rfork
@{rfork n; mkdir '#σc'/testshr; ramfs -S testshr; echo 3 > '#σc'/testshr/ramfs <>[3]/srv/testshr; echo PASS > '#σ'/testshr/file }
@{sys_rfork n; mkdir '#σc'/testshr; ramfs -S testshr; echo 3 > '#σc'/testshr/ramfs <>[3]/srv/testshr; echo PASS > '#σ'/testshr/file }
bind '#σ' /shr

View File

@ -27,41 +27,41 @@ main(void)
char buf[256];
int fd, r;
fd = open("/fd/0ctl", OREAD|OCEXEC);
fd = sys_open("/fd/0ctl", OREAD|OCEXEC);
if(fd < 0)
goto Fail;
r = read(fd, buf, sizeof(buf));
r = jehanne_read(fd, buf, sizeof(buf));
if(r < 0)
goto Fail;
close(fd);
sys_close(fd);
print("Got 0ctl: %s\n", buf);
fd = open("/fd/1ctl", OREAD|OCEXEC);
fd = sys_open("/fd/1ctl", OREAD|OCEXEC);
if(fd < 0)
goto Fail;
r = read(fd, buf, sizeof(buf));
r = jehanne_read(fd, buf, sizeof(buf));
if(r < 0)
goto Fail;
close(fd);
sys_close(fd);
print("Got 1ctl: %s\n", buf);
fd = open("/fd/2ctl", OREAD|OCEXEC);
fd = sys_open("/fd/2ctl", OREAD|OCEXEC);
if(fd < 0)
goto Fail;
r = read(fd, buf, sizeof(buf));
r = jehanne_read(fd, buf, sizeof(buf));
if(r < 0)
goto Fail;
print("Got 2ctl: %s\n", buf);
snprint(buf, sizeof(buf), "/fd/%dctl", fd);
fd = open(buf, OREAD);
fd = sys_open(buf, OREAD);
if(fd < 0)
goto Fail;
r = read(fd, buf, sizeof(buf));
r = jehanne_read(fd, buf, sizeof(buf));
if(r < 0)
goto Fail;
print("Got: %s\n", buf);
close(fd);
sys_close(fd);
exits(nil);
Fail:

View File

@ -17,7 +17,7 @@ catcher(void *u, char *s)
err = s;
notejmp(u, errj, 0);
}
noted(NDFLT);
sys_noted(NDFLT);
}
void
@ -56,7 +56,7 @@ main(void)
q = d2l.l;
err = 0;
notify(catcher);
sys_notify(catcher);
setjmp(errj);
if(err){
fprint(2, "FAIL: %s\n", err);

View File

@ -15,9 +15,9 @@ main(void)
{
static int c;
int pid;
pid = rfork(RFMEM|RFPROC);
pid = sys_rfork(RFMEM|RFPROC);
if (pid < 0) {
print("FAIL: rfork\n");
print("FAIL: sys_rfork\n");
exits("FAIL");
}
if (pid > 0) {

View File

@ -21,8 +21,8 @@
int r1;
int r2;
#define CHILD_READY(pid) ((long)rendezvous(&r1, (void*)(~(pid))))
//#define C2P_READY(pid) ((long)rendezvous(&r2, (void*)(~(pid))))
#define CHILD_READY(pid) ((long)sys_rendezvous(&r1, (void*)(~(pid))))
//#define C2P_READY(pid) ((long)sys_rendezvous(&r2, (void*)(~(pid))))
int *__target_pid;
@ -30,7 +30,7 @@ static void
forwarding_note_handler(void *ureg, char *note)
{
postnote(PNPROC, *__target_pid, note);
noted(NDFLT);
sys_noted(NDFLT);
}
static void
@ -49,24 +49,24 @@ crazy_fork(void)
int p2c;
long c2p = -1, child = -1;
switch(p2c = rfork(RFPROC|RFMEM)){
switch(p2c = sys_rfork(RFPROC|RFMEM)){
case -1:
return -1;
case 0:
switch(c2p = rfork(RFPROC|RFMEM)){
switch(c2p = sys_rfork(RFPROC|RFMEM)){
case -1:
exits("rfork (c2p)");
exits("sys_rfork (c2p)");
case 0:
switch(child = fork()){
case -1:
exits("rfork (child)");
exits("sys_rfork (child)");
case 0:
return 0;
default:
while(CHILD_READY(child) == -1)
;
*__target_pid = father;
notify(forwarding_note_handler);
sys_notify(forwarding_note_handler);
donothing();
}
default:
@ -74,7 +74,7 @@ crazy_fork(void)
;
child = ~child;
*__target_pid = child;
notify(forwarding_note_handler);
sys_notify(forwarding_note_handler);
donothing();
}
default:
@ -113,13 +113,13 @@ main(void)
case 0:
print("child is %d; child's parent is %d\n", getpid(), getppid());
*__target_pid = getppid();
notify(forwarding_note_handler);
sys_notify(forwarding_note_handler);
/* wait to be killed */
donothing();
break;
default:
print("father is %d; forked child is %d\n", getpid(), c);
sleep(1000); /* give children time to notify() */
sleep(1000); /* give children time to sys_notify() */
print("starting note chain\n");
postnote(PNPROC, c, "die");
/* wait to be killed by the chain */

View File

@ -18,7 +18,7 @@ catcher(void *u, char *s)
err = s;
notejmp(u, errj, 0);
}
noted(NDFLT);
sys_noted(NDFLT);
}
void
@ -51,7 +51,7 @@ main(void)
int exp;
err = 0;
notify(catcher);
sys_notify(catcher);
setjmp(errj);
if(err){
print("FAIL: %s\n", err);

View File

@ -23,21 +23,21 @@ main(void)
{
int pid;
rfork(RFNAMEG);
sys_rfork(RFNAMEG);
pid = getmainpid(); // this comes from exec() syscall
if(getpid() != pid){
print("FAIL: getpid() != getmainpid()\n");
exits("FAIL");
}
rfork(RFNOMNT);
sys_rfork(RFNOMNT);
if(getpid() != pid){
print("FAIL: rfork(RFNOMNT); getpid() != getmainpid()\n");
print("FAIL: sys_rfork(RFNOMNT); getpid() != getmainpid()\n");
exits("FAIL");
}
rfork(RFNOMNT|RFCNAMEG);
sys_rfork(RFNOMNT|RFCNAMEG);
if(getpid() != pid){
print("FAIL: rfork(RFNOMNT|RFCNAMEG)); getpid() != getmainpid()\n");
print("FAIL: sys_rfork(RFNOMNT|RFCNAMEG)); getpid() != getmainpid()\n");
exits("FAIL");
}

View File

@ -24,22 +24,22 @@ main(void)
int ppid;
Waitmsg *w;
rfork(RFNAMEG);
if(rfork(RFPROC) == 0){
sys_rfork(RFNAMEG);
if(sys_rfork(RFPROC) == 0){
ppid = getmainpid(); // this comes from exec() syscall
if(getppid() != ppid){
print("FAIL: getppid() != getmainpid()\n");
exits("FAIL");
}
rfork(RFNOMNT);
sys_rfork(RFNOMNT);
if(getppid() != ppid){
print("FAIL: rfork(RFNOMNT); getppid() != getmainpid()\n");
print("FAIL: sys_rfork(RFNOMNT); getppid() != getmainpid()\n");
exits("FAIL");
}
rfork(RFNOMNT|RFCNAMEG);
sys_rfork(RFNOMNT|RFCNAMEG);
if(getppid() != ppid){
print("FAIL: rfork(RFNOMNT|RFCNAMEG)); getppid() != getmainpid()\n");
print("FAIL: sys_rfork(RFNOMNT|RFCNAMEG)); getppid() != getmainpid()\n");
exits("FAIL");
}
exits(nil);

View File

@ -48,9 +48,9 @@ main(void)
pipe(p);
memset(buf, 0, sizeof buf);
switch((pid = rfork(RFPROC))){
switch((pid = sys_rfork(RFPROC))){
case -1:
fprint(2, "FAIL: rfork: %r\n");
fprint(2, "FAIL: sys_rfork: %r\n");
exits("FAIL");
break;
case 0:
@ -60,7 +60,7 @@ main(void)
fprint(2, "address %p, msg %s\n", msg, msg);
fprint(2, "sending %s\n", buf);
}
if(write(p[0], buf, i) < 0){
if(jehanne_write(p[0], buf, i) < 0){
fprint(2, "FAIL: write: %r\n");
exits("FAIL");
}
@ -69,7 +69,7 @@ main(void)
default:
buf[0] = '0';
buf[1] = 'x';
if((i = read(p[1], buf+2, (sizeof buf) - 2)) <= 0){
if((i = jehanne_read(p[1], buf+2, (sizeof buf) - 2)) <= 0){
fprint(2, "FAIL: read: %r\n");
exits("FAIL");
}

View File

@ -48,9 +48,9 @@ main(void)
pipe(p);
memset(buf, 0, sizeof buf);
switch((pid = rfork(RFPROC|RFMEM))){
switch((pid = sys_rfork(RFPROC|RFMEM))){
case -1:
fprint(2, "FAIL: rfork: %r\n");
fprint(2, "FAIL: sys_rfork: %r\n");
exits("FAIL");
break;
case 0:
@ -60,7 +60,7 @@ main(void)
fprint(2, "address %p, msg %s\n", msg, msg);
fprint(2, "sending %s\n", buf);
}
if(write(p[0], buf, i) < 0){
if(jehanne_write(p[0], buf, i) < 0){
fprint(2, "FAIL: write: %r\n");
exits("FAIL");
}
@ -69,7 +69,7 @@ main(void)
default:
buf[0] = '0';
buf[1] = 'x';
if((i = read(p[1], buf+2, (sizeof buf) - 2)) <= 0){
if((i = jehanne_read(p[1], buf+2, (sizeof buf) - 2)) <= 0){
fprint(2, "FAIL: read: %r\n");
exits("FAIL");
}

View File

@ -37,7 +37,7 @@ handler(void *v, char *s)
print("wait after %s terminated\n", s);
waited++;
}
noted(NCONT);
sys_noted(NCONT);
}
void
@ -47,12 +47,12 @@ main(int argc, char**argv)
if(argc > 1){
fd = ocreate(argv[1], OWRITE, 0666);
dup(fd, 1);
close(fd);
sys_close(fd);
}
if (notify(handler)){
if (sys_notify(handler)){
fprint(2, "%r\n");
exits("notify fails");
exits("sys_notify fails");
}
print("note handler installed\n");

View File

@ -16,9 +16,9 @@ void
callinsn(char *name, char *buf)
{
void (*f)(void);
if (notify(handler)){
if (sys_notify(handler)){
fprint(2, "%r\n");
exits("notify fails");
exits("sys_notify fails");
}
@ -31,9 +31,9 @@ callinsn(char *name, char *buf)
void
writeptr(char *name, void *ptr)
{
if (notify(handler)){
if (sys_notify(handler)){
fprint(2, "%r\n");
exits("notify fails");
exits("sys_notify fails");
}
*(uintptr_t*)ptr = 0xdeadbeef;
@ -48,9 +48,9 @@ main(void)
char stk[128];
char *mem;
switch(rfork(RFMEM|RFPROC)){
switch(sys_rfork(RFMEM|RFPROC)){
case -1:
sysfatal("rfork");
sysfatal("sys_rfork");
case 0:
stk[0] = RET;
callinsn("exec stack", stk);
@ -59,9 +59,9 @@ main(void)
waitpid();
}
switch(rfork(RFMEM|RFPROC)){
switch(sys_rfork(RFMEM|RFPROC)){
case -1:
sysfatal("rfork");
sysfatal("sys_rfork");
case 0:
mem = malloc(128);
mem[0] = RET;
@ -71,9 +71,9 @@ main(void)
waitpid();
}
switch(rfork(RFMEM|RFPROC)){
switch(sys_rfork(RFMEM|RFPROC)){
case -1:
sysfatal("rfork");
sysfatal("sys_rfork");
case 0:
writeptr("write code", (void*)&main);
default:
@ -81,9 +81,9 @@ main(void)
waitpid();
}
switch(rfork(RFMEM|RFPROC)){
switch(sys_rfork(RFMEM|RFPROC)){
case -1:
sysfatal("rfork");
sysfatal("sys_rfork");
case 0:
writeptr("write rodata", (void*)str);
default:

View File

@ -13,9 +13,9 @@ void
main(void)
{
void (*f)(void) = nil;
if (notify(handler)){
if (sys_notify(handler)){
fprint(2, "%r\n");
exits("notify fails");
exits("sys_notify fails");
}
f();

View File

@ -24,20 +24,20 @@ void
setup_ns(void)
{
int fd;
if(bind("#|", "/", MREPL) < 0){
print("FAIL: rfork\n");
write(sync[0], "FAIL", 5);
if(sys_bind("#|", "/", MREPL) < 0){
print("FAIL: sys_rfork\n");
jehanne_write(sync[0], "FAIL", 5);
return;
}
fd = open("/data", OWRITE);
fd = sys_open("/data", OWRITE);
if(fd < 0){
print("FAIL: open(/data)\n");
write(sync[0], "FAIL", 5);
print("FAIL: sys_open(/data)\n");
jehanne_write(sync[0], "FAIL", 5);
return;
}
write(fd, "hi!", 4);
close(fd);
write(sync[0], "DONE", 5);
jehanne_write(fd, "hi!", 4);
sys_close(fd);
jehanne_write(sync[0], "DONE", 5);
sleep(10);
}
@ -47,12 +47,12 @@ main(void)
int child, fd;
char buf[64];
rfork(RFNOTEG|RFNAMEG);
sys_rfork(RFNOTEG|RFNAMEG);
pipe(sync);
switch(child = rfork(RFPROC|RFCNAMEG|RFNOWAIT)){
switch(child = sys_rfork(RFPROC|RFCNAMEG|RFNOWAIT)){
case -1:
print("FAIL: rfork\n");
print("FAIL: sys_rfork\n");
exits("FAIL");
case 0:
setup_ns();
@ -61,27 +61,27 @@ main(void)
break;
}
read(sync[1], buf, sizeof(buf));
jehanne_read(sync[1], buf, sizeof(buf));
if(strcmp("DONE", buf) != 0)
exits("FAIL");
snprint(buf, sizeof(buf), "/proc/%d/ns", child);
fd = open(buf, OWRITE);
fd = sys_open(buf, OWRITE);
if(fd < 0){
print("FAIL: open(%s)\n", buf);
print("FAIL: sys_open(%s)\n", buf);
exits("FAIL");
}
write(fd, "clone", 6);
close(fd);
jehanne_write(fd, "clone", 6);
sys_close(fd);
memset(buf, 0, sizeof(buf));
fd = open("/data1", OREAD);
fd = sys_open("/data1", OREAD);
if(fd < 0){
print("FAIL: open(/data1)\n");
print("FAIL: sys_open(/data1)\n");
exits("FAIL");
}
read(fd, buf, sizeof(buf));
close(fd);
jehanne_read(fd, buf, sizeof(buf));
sys_close(fd);
if(strcmp("hi!", buf) == 0){
print("PASS: read '%s' from /data1\n", buf);

View File

@ -14,7 +14,7 @@ handler(void *v, char *s)
{
print("%d: %d iterations\n", id, i);
if (intr++ < 16)
noted(NCONT);
sys_noted(NCONT);
exits("too many interrupts");
}
@ -23,8 +23,8 @@ main(int argc, char *argv[])
{
int pid;
if (notify(handler)){
sysfatal("notify: %r");
if (sys_notify(handler)){
sysfatal("sys_notify: %r");
}
if (argc > 1)
@ -57,11 +57,11 @@ main(int argc, char *argv[])
for(i = 0; debug && i < nring; i++ ) fprint(2, "pfd[%d,%d]\n", pfd[i*2],pfd[i*2+1]);
for(i = 0; i < niter; i++) {
if (debug) fprint(2, "%d: write %d\n", id, pfd[(id%nring)*2+1]);
int amt = write(pfd[(id%nring)*2+1], data, sizeof(data));
int amt = jehanne_write(pfd[(id%nring)*2+1], data, sizeof(data));
if (amt < sizeof(data))
sysfatal(smprint("%d: write only got %d of %d: %r", id, amt, sizeof(data)));
if (debug) print("%d: read %d\n", id, pfd[(id%nring)*2]);
amt = read(pfd[(id%nring)*2], data, sizeof(data));
amt = jehanne_read(pfd[(id%nring)*2], data, sizeof(data));
if (amt < sizeof(data))
sysfatal(smprint("%d: read only got %d of %d: %r", id, amt, sizeof(data)));
}

View File

@ -73,19 +73,19 @@ main(void)
exits("atnotify fails");
}
rfork(RFNOTEG|RFNAMEG);
sys_rfork(RFNOTEG|RFNAMEG);
if(rfork(RFPROC) == 0){
if(sys_rfork(RFPROC) == 0){
ppid = getppid(); // this comes from exec() syscall
postnote(PNPROC, ppid, "proc");
postnote(PNGROUP, getpid(), "group");
rfork(RFNOMNT);
sys_rfork(RFNOMNT);
postnote(PNPROC, ppid, "proc");
postnote(PNGROUP, getpid(), "group");
rfork(RFNOMNT|RFCNAMEG);
sys_rfork(RFNOMNT|RFCNAMEG);
if(postnote(PNPROC, ppid, "proc") != -1 ||
postnote(PNGROUP, getpid(), "group") != -1){
exits("FAIL");

View File

@ -27,7 +27,7 @@ main(int argc, char *argv[])
}
if (pid == 0) {
char *args[] = {"ps", nil};
exec("/arch/amd64/cmd/ps", args);
sys_exec("/arch/amd64/cmd/ps", (const char **)args);
fprint(2,"Exec fails: %r\n");
print("FAIL\n");
exits("FAIL");

View File

@ -27,10 +27,10 @@ int spin;
void
main(void)
{
rfork(RFNOTEG);
switch(rfork(RFPROC|RFMEM)){
sys_rfork(RFNOTEG);
switch(sys_rfork(RFPROC|RFMEM)){
case -1:
exits("rfork");
exits("sys_rfork");
case 0:
spin = 1;
while(spin)
@ -40,9 +40,9 @@ main(void)
while(spin == 0)
;
}
switch(rfork(RFPROC|RFMEM)){
switch(sys_rfork(RFPROC|RFMEM)){
case -1:
exits("rfork");
exits("sys_rfork");
case 0:
spin = 2;
while(spin)

View File

@ -25,17 +25,17 @@ main(int argc, char**argv)
char *path;
path = smprint("/proc/%d/ctl", getpid());
fd = open(path, OWRITE);
fd = sys_open(path, OWRITE);
if(fd < 0){
print("FAIL: open");
exits("FAIL");
}
n = write(fd, "stop", 4);
n = jehanne_write(fd, "stop", 4);
if(n < 0){
print("FAIL: write");
exits("FAIL");
}
close(fd);
sys_close(fd);
print("PASS\n");
exits("PASS");
}

View File

@ -11,14 +11,14 @@ main(void)
fail = 0;
for(i = 0; i < 10000; i++){
fd = open("/proc/1/status", OREAD);
n = read(fd, buf, sizeof buf);
fd = sys_open("/proc/1/status", OREAD);
n = jehanne_read(fd, buf, sizeof buf);
if(i != 0 && n != oldn){
fprint(2, "read %d, want %d\n", n, oldn);
fail++;
}
oldn = n;
close(fd);
sys_close(fd);
}
print("PASS\n");
exits("PASS");

View File

@ -13,7 +13,7 @@ main(void)
int fd, n;
char buf[1];
fd = open("/dev/sysstat", OREAD);
fd = sys_open("/dev/sysstat", OREAD);
if(fd < 0){
print("FAIL: couldn't open /dev/sysstat: %r\n");
exits("FAIL");
@ -21,13 +21,13 @@ main(void)
ret = 0;
for(;;){
n = read(fd, buf, sizeof(buf));
n = jehanne_read(fd, buf, sizeof(buf));
if(n <= 0)
break;
if(n > sizeof(buf))
ret = 1;
}
close(fd);
sys_close(fd);
if(ret){
print("FAIL: %d bytes read from /dev/sysstat\n", n);

View File

@ -17,7 +17,7 @@ tsemloop(void)
sleep(10);
incr++;
i++;
semrelease(&x, 1);
sys_semrelease(&x, 1);
} else {
//print("pid %d timeout\n", getpid());
}
@ -31,10 +31,10 @@ semloop(void)
int i;
i = 0;
while(i < nloops){
if(semacquire(&x, 1)){
if(sys_semacquire(&x, 1)){
incr++;
i++;
semrelease(&x, 1);
sys_semrelease(&x, 1);
} else {
sysfatal("semacquire failed");
}
@ -49,9 +49,9 @@ main(void)
incr = 0;
for(i = 0; i < nprocs; i++){
switch(rfork(RFMEM|RFPROC)){
switch(sys_rfork(RFMEM|RFPROC)){
case -1:
sysfatal("rfork");
sysfatal("sys_rfork");
case 0:
tsemloop();
exits("PASS");
@ -69,9 +69,9 @@ main(void)
incr = 0;
for(i = 0; i < nprocs; i++){
switch(rfork(RFMEM|RFPROC)){
switch(sys_rfork(RFMEM|RFPROC)){
case -1:
sysfatal("rfork");
sysfatal("sys_rfork");
case 0:
semloop();
exits("PASS");
@ -89,9 +89,9 @@ main(void)
incr = 0;
for(i = 0; i < nprocs; i++){
switch(rfork(RFMEM|RFPROC)){
switch(sys_rfork(RFMEM|RFPROC)){
case -1:
sysfatal("rfork");
sysfatal("sys_rfork");
case 0:
if((i&1) == 0)
semloop();

View File

@ -11,13 +11,13 @@ main(void)
char buf[1];
int i;
// Just to be sure.
if (close(3) >= 0) {
print("waserror: close of 3 did not get an error\n");
if (sys_close(3) >= 0) {
print("waserror: sys_close of 3 did not get an error\n");
exits("FAIL");
}
for(i = 0; i < 100000; i++) {
if (read(3, buf, 1) >= 0){
if (jehanne_read(3, buf, 1) >= 0){
print("waserror: read of 3 did not get an error\n");
exits("FAIL");
}

View File

@ -52,7 +52,7 @@ main(void)
}
int fd;
fd = open("#|", ORDWR);
fd = sys_open("#|", ORDWR);
sys_mount(fd, -1, "/tmp", MREPL, "", 'M');
print("PASS\n");

View File

@ -29,7 +29,7 @@ main(void)
memset(msg, '1', BUFSZ);
if((w = write(2, msg, BUFSZ)) < BUFSZ){
if((w = jehanne_write(2, msg, BUFSZ)) < BUFSZ){
print("\nFAIL, written %d instead of %d\n", w, BUFSZ);
exits("FAIL");
}

View File

@ -20,40 +20,40 @@ fdfork(int fd, int post)
if(pfd == -1)
sysfatal("fdfork: create: %r");
snprint(buf, sizeof buf, "%d", ch[0]);
if(write(pfd, buf, strlen(buf)) != strlen(buf)){
remove(path);
if(jehanne_write(pfd, buf, strlen(buf)) != strlen(buf)){
sys_remove(path);
sysfatal("fdfork: post '%s': %r", buf);
}
close(ch[0]);
sys_close(ch[0]);
if(write(fd, path, len) != len){
remove(path);
if(jehanne_write(fd, path, len) != len){
sys_remove(path);
sysfatal("fdfork: write to peer: %r");
}
len = read(fd, buf, sizeof buf-1);
len = jehanne_read(fd, buf, sizeof buf-1);
if(len <= 0){
remove(path);
sys_remove(path);
sysfatal("fdfork: read ack: %s from peer: %r", len == -1 ? "error" : "eof");
}
buf[len] = '\0';
if(strcmp(path, buf)){
remove(path);
sys_remove(path);
print("ack from wrong peer: got '%s' want '%s'\n", buf, path);
sysfatal("ack from wrong peer");
}
close(pfd);
//remove(path);
sys_close(pfd);
//sys_remove(path);
return ch[1];
} else {
len = read(fd, path, sizeof path-1);
len = jehanne_read(fd, path, sizeof path-1);
if(len <= 0)
sysfatal("fdfork: read path: %s from peer: %r", len == -1 ? "error" : "eof");
path[len] = '\0';
pfd = open(path, OWRITE);
pfd = sys_open(path, OWRITE);
if(pfd == -1)
sysfatal("fdfork: open: %r");
if(write(fd, path, len) != len)
if(jehanne_write(fd, path, len) != len)
sysfatal("fdfork: write ack to peer: %r");
return pfd;
@ -61,7 +61,7 @@ fdfork(int fd, int post)
}
int
hyperfork(int *fd, int id, int dim)
hypesys_rfork(int *fd, int id, int dim)
{
int chfd[dim];
int ch[2];
@ -72,20 +72,20 @@ hyperfork(int *fd, int id, int dim)
pipe(ch);
switch(fork()){
case -1:
sysfatal("rfork");
sysfatal("sys_rfork");
case 0:
for(i = 0; i < dim; i++){
close(fd[i]);
sys_close(fd[i]);
fd[i] = chfd[i];
}
id |= 1 << dim;
close(ch[0]);
sys_close(ch[0]);
fd[dim] = ch[1];
break;
default:
for(i = 0; i < dim; i++)
close(chfd[i]);
close(ch[1]);
sys_close(chfd[i]);
sys_cl