commit 6954d7b0709f9ff19d89e94ced0ac5a9e0352373
parent 87ad8a9b47ba374a46d05341536e78f23b6af238
Author: Jesus Galan Lopez (yiyus) <yiyu.jgl@gmail.com>
Date: Sat, 11 Sep 2010 12:30:48 +0200
a/ files updated (with 8 errors)
Diffstat:
30 files changed, 467 insertions(+), 184 deletions(-)
diff --git a/src/9vx/a/AUTOGEN b/src/9vx/a/AUTOGEN
@@ -33,11 +33,11 @@ autofiles="
/sys/src/9/pc/mem.h
/sys/src/9/pc/sdscsi.c
/sys/src/9/port/allocb.c
-/sys/src/9/port/aoe.h
-/sys/src/9/port/auth.c
+#/sys/src/9/port/aoe.h
+#/sys/src/9/port/auth.c
/sys/src/9/port/chan.c
/sys/src/9/port/dev.c
-/sys/src/9/port/devaoe.c
+#/sys/src/9/port/devaoe.c
/sys/src/9/port/devcap.c
/sys/src/9/port/devcons.c
/sys/src/9/port/devdraw.c
@@ -55,8 +55,8 @@ autofiles="
/sys/src/9/port/fault.c
/sys/src/9/port/latin1.c
/sys/src/9/port/lib.h
-/sys/src/9/port/netif.c
-/sys/src/9/port/netif.h
+#/sys/src/9/port/netif.c
+#/sys/src/9/port/netif.h
/sys/src/9/port/page.c
/sys/src/9/port/parse.c
/sys/src/9/port/pgrp.c
@@ -67,10 +67,10 @@ autofiles="
/sys/src/9/port/qio.c
/sys/src/9/port/qlock.c
/sys/src/9/port/sd.h
-/sys/src/9/port/sdaoe.c
+#/sys/src/9/port/sdaoe.c
/sys/src/9/port/segment.c
/sys/src/9/port/swap.c
-/sys/src/9/port/sysfile.c
+#/sys/src/9/port/sysfile.c
/sys/src/9/port/sysproc.c
/sys/src/9/port/systab.h
/sys/src/9/port/thwack.c
@@ -101,17 +101,12 @@ autofiles="
/sys/src/libip/parseip.c
"
-plan9=$HOME/plan9
+plan9=/usr/local/9vx
if [ $# -gt 1 ] && [ $1 == "-r" ]; then
- plan9=$2
+ plan9=`ls -d $2` || exit 1
shift 2
fi
-if [ ! -d $plan9/sys/src ]; then
- echo "$0 error: $plan9/sys/src is not a directory" 1>&2
- exit 1
-fi
-
case "$#" in
0)
;;
@@ -119,28 +114,37 @@ case "$#" in
autofiles="$*"
esac
+errors=0
+
for f in $autofiles
do
- test -f $plan9/$f || echo "$0 error: $plan9/$f not found" 1>&2
+ in=`echo $plan9$f | sed 's;//;/;'`
+ out=`echo $f | sed 's;.*/;;;'`
ed=`echo $f | sed 's;.*/;;; s;\.[ch]$;;; s;$;.ed;'`
test -f $ed || ed=`echo $f | sed 's;.*/;;; s;$;.ed;'`
- out=`echo $f | sed 's;.*/;;;'`
- echo -n $f '->' $out
- test -f $ed && echo ' ('$ed')' || echo
- test -f $out && chmod +w $out
- (
- echo ',s;"../ip/;"ip/;g'
- echo ',s;"../port/;";g'
- echo ',s;#include.*<;#include ";g'
- echo ',s;#include.*>;&FIXINCLUDEME;g'
- echo ',s;>FIXINCLUDEME;";g'
- echo ',s;"libc.h";"lib.h";g'
- echo ',s;SET(\(.*\));;g'
- echo 'g/#pragma/d'
- test -f $ed && cat $ed
- echo w $out
- echo q
- ) | ed -s $plan9/$f 2>&1 | egrep -v '^[0-9?]+$'
+ if test -f $in; then
+ echo -n $f '->' $out
+ test -f $ed && echo ' ('$ed')' || echo
+ test -f $out && chmod +w $out
+ (
+ echo ',s;"../ip/;"ip/;g'
+ echo ',s;"../port/;";g'
+ echo ',s;#include.*<;#include ";g'
+ echo ',s;#include.*>;&FIXINCLUDEME;g'
+ echo ',s;>FIXINCLUDEME;";g'
+ echo ',s;"libc.h";"lib.h";g'
+ echo ',s;SET(\(.*\));;g'
+ echo 'g/#pragma/d'
+ test -f $ed && cat $ed
+ echo w $out
+ echo q
+ ) | ed -s $in 2>&1 | egrep -v '^[0-9?]+$'
+ else
+ echo "ERROR: $in not found" 1>&2
+ errors=`echo $errors + 1 | bc`
+ fi
done
-exit 0-
\ No newline at end of file
+test $errors -gt 0 && echo -n $errors error &&
+ (test $errors -gt 1 && echo s || echo)
+exit 0
diff --git a/src/9vx/a/a.out.h b/src/9vx/a/a.out.h
@@ -6,7 +6,7 @@ struct Exec
int32 data; /* size of initialized data */
int32 bss; /* size of uninitialized data */
int32 syms; /* size of symbol table */
- int32 entry; /* entry point32 */
+ int32 entry; /* entry point */
int32 spsz; /* size of pc/sp offset table */
int32 pcsz; /* size of pc/line number table */
};
diff --git a/src/9vx/a/convS2M.c b/src/9vx/a/convS2M.c
@@ -15,10 +15,13 @@ pstring(uchar *p, char *s)
}
n = strlen(s);
+ /*
+ * We are moving the string before the length,
+ * so you can S2M a struct into an existing message
+ */
+ memmove(p + BIT16SZ, s, n);
PBIT16(p, n);
- p += BIT16SZ;
- memmove(p, s, n);
- p += n;
+ p += n + BIT16SZ;
return p;
}
diff --git a/src/9vx/a/devcap.c b/src/9vx/a/devcap.c
@@ -5,7 +5,7 @@
#include "fns.h"
#include "error.h"
-#include "libsec.h"
+#include "libsec.h"
enum
{
diff --git a/src/9vx/a/devcons.c b/src/9vx/a/devcons.c
@@ -5,7 +5,7 @@
#include "fns.h"
#include "error.h"
-#include "authsrv.h"
+#include "authsrv.h"
void (*consdebug)(void) = nil;
void (*screenputs)(char*, int) = nil;
@@ -103,7 +103,8 @@ prflush(void)
*/
struct {
Lock lk;
- char buf[16384];
+// char buf[16384]; /* normal */
+ char buf[256*1024]; /* for acpi debugging */
uint n;
} kmesg;
@@ -1340,6 +1341,8 @@ writebintime(char *buf, int n)
if(n < sizeof(uvlong))
error(Ebadtimectl);
le2vlong(&fasthz, p);
+ if(fasthz <= 0)
+ error(Ebadtimectl);
todsetfreq(fasthz);
break;
}
diff --git a/src/9vx/a/devdraw.c b/src/9vx/a/devdraw.c
@@ -6,10 +6,10 @@
#include "error.h"
#define Image IMAGE
-#include "draw.h"
-#include "memdraw.h"
-#include "memlayer.h"
-#include "cursor.h"
+#include "draw.h"
+#include "memdraw.h"
+#include "memlayer.h"
+#include "cursor.h"
#include "screen.h"
#define blankscreen(x)
@@ -1377,6 +1377,7 @@ printmesg(char *fmt, uchar *a, int plsprnt)
char *p, *q;
if(1|| plsprnt==0){
+ ;
return;
}
q = buf;
diff --git a/src/9vx/a/devproc.c b/src/9vx/a/devproc.c
@@ -1,5 +1,5 @@
#include "u.h"
-#include "trace.h"
+#include "trace.h"
#include "tos.h"
#include "lib.h"
#include "mem.h"
@@ -86,6 +86,7 @@ Dirtab procdir[] =
"wait", {Qwait}, 0, 0400,
"profile", {Qprofile}, 0, 0400,
"syscall", {Qsyscall}, 0, 0400,
+ "syscall", {Qsyscall}, 0, 0400,
};
static
@@ -386,7 +387,7 @@ procopen(Chan *c, int omode)
case Qwait:
case Qregs:
case Qfpregs:
- case Qsyscall:
+ case Qsyscall:
nonone(p);
break;
@@ -695,7 +696,6 @@ procread(Chan *c, void *va, long n, vlong off)
n = j-offset;
memmove(a, &up->genbuf[offset], n);
return n;
-
case Qsyscall:
if(!p->syscalltrace)
return 0;
diff --git a/src/9vx/a/devsrv.c b/src/9vx/a/devsrv.c
@@ -224,6 +224,7 @@ srvremove(Chan *c)
if(sp->chan)
cclose(sp->chan);
+ free(sp->owner);
free(sp->name);
free(sp);
}
diff --git a/src/9vx/a/devssl.c b/src/9vx/a/devssl.c
@@ -8,7 +8,7 @@
#include "fns.h"
#include "error.h"
-#include "libsec.h"
+#include "libsec.h"
#define NOSPOOKS 1
diff --git a/src/9vx/a/devtls.c b/src/9vx/a/devtls.c
@@ -8,7 +8,7 @@
#include "fns.h"
#include "error.h"
-#include "libsec.h"
+#include "libsec.h"
typedef struct OneWay OneWay;
typedef struct Secret Secret;
diff --git a/src/9vx/a/eipfmt.c b/src/9vx/a/eipfmt.c
@@ -27,7 +27,7 @@ eipfmt(Fmt *f)
static char *efmt = "%.2ux%.2ux%.2ux%.2ux%.2ux%.2ux";
static char *ifmt = "%d.%d.%d.%d";
uchar *p, ip[16];
- uint32 *lp;
+ ulong *lp;
ushort s;
int i, j, n, eln, eli;
@@ -73,7 +73,7 @@ common:
return fmtstrcpy(f, buf);
case 'i': /* v6 address as 4 longs */
- lp = va_arg(f->args, uint32*);
+ lp = va_arg(f->args, ulong*);
for(i = 0; i < 4; i++)
hnputl(ip+4*i, *lp++);
p = ip;
diff --git a/src/9vx/a/error.h b/src/9vx/a/error.h
@@ -50,3 +50,4 @@ extern char Ebadstat[]; /* malformed stat buffer */
extern char Enegoff[]; /* negative i/o offset */
extern char Ecmdargs[]; /* wrong #args in control message */
extern char Ebadip[]; /* bad ip address syntax */
+extern char Edirseek[]; /* seek in directory */
diff --git a/src/9vx/a/fault.c b/src/9vx/a/fault.c
@@ -150,12 +150,6 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu)
if(ref > 1) {
unlock(&lkp->lk);
- if(swapfull()){
- qunlock(&s->lk);
- pprint("swap space full\n");
- faulterror(Enoswap, nil, 1);
- }
-
new = newpage(0, &s, addr);
if(s == 0)
return -1;
@@ -165,7 +159,7 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu)
}
else {
/* save a copy of the original for the image cache */
- if(lkp->image && !swapfull())
+ if(lkp->image)
duppage(lkp);
unlock(&lkp->lk);
@@ -222,6 +216,11 @@ retry:
*p = new;
return;
}
+
+ c = s->image->c;
+ ask = s->flen-soff;
+ if(ask > BY2PG)
+ ask = BY2PG;
}
else { /* from a swap image */
daddr = swapaddr(loadrec);
@@ -231,39 +230,34 @@ retry:
*p = new;
return;
}
- }
-
+ c = swapimage.c;
+ ask = BY2PG;
+ }
qunlock(&s->lk);
new = newpage(0, 0, addr);
k = kmap(new);
kaddr = (char*)VA(k);
- if(loadrec == 0) { /* This is demand load */
- c = s->image->c;
- while(waserror()) {
- if(strcmp(up->errstr, Eintr) == 0)
- continue;
- kunmap(k);
- putpage(new);
- faulterror("sys: demand load I/O error", c, 0);
- }
-
- ask = s->flen-soff;
- if(ask > BY2PG)
- ask = BY2PG;
-
- n = devtab[c->type]->read(c, kaddr, ask, daddr);
- if(n != ask)
- faulterror(Eioload, c, 0);
- if(ask < BY2PG)
- memset(kaddr+ask, 0, BY2PG-ask);
-
- poperror();
+ while(waserror()) {
+ if(strcmp(up->errstr, Eintr) == 0)
+ continue;
kunmap(k);
- qlock(&s->lk);
+ putpage(new);
+ faulterror(Eioload, c, 0);
+ }
+ n = devtab[c->type]->read(c, kaddr, ask, daddr);
+ if(n != ask)
+ faulterror(Eioload, c, 0);
+ if(ask < BY2PG)
+ memset(kaddr+ask, 0, BY2PG-ask);
+
+ poperror();
+ kunmap(k);
+ qlock(&s->lk);
+ if(loadrec == 0) { /* This is demand load */
/*
* race, another proc may have gotten here first while
* s->lk was unlocked
@@ -276,24 +270,7 @@ retry:
else
putpage(new);
}
- else { /* This is paged out */
- c = swapimage.c;
- if(waserror()) {
- kunmap(k);
- putpage(new);
- qlock(&s->lk);
- qunlock(&s->lk);
- faulterror("sys: page in I/O error", c, 0);
- }
-
- n = devtab[c->type]->read(c, kaddr, BY2PG, daddr);
- if(n != BY2PG)
- faulterror(Eioload, c, 0);
-
- poperror();
- kunmap(k);
- qlock(&s->lk);
-
+ else { /* This is paged out */
/*
* race, another proc may have gotten here first
* (and the pager may have run on that page) while
diff --git a/src/9vx/a/fns.h b/src/9vx/a/fns.h
@@ -125,6 +125,7 @@ void realmode(Ureg*);
void screeninit(void);
void (*screenputs)(char*, int);
void syncclock(void);
+void syscallretprint(Ureg *ureg, int syscallno, uvlong start, uvlong stop);
void* tmpmap(Page*);
void tmpunmap(void*);
void touser(void*);
diff --git a/src/9vx/a/fs.h b/src/9vx/a/fs.h
@@ -27,12 +27,10 @@ struct Fs{
File root;
};
-/*
-extern int chatty;
-extern int dotini(Fs*);
-extern int fswalk(Fs*, char*, File*);
-extern int fsread(File*, void*, long);
-extern int fsboot(Fs*, char*, Boot*);
-*/
+// extern int chatty;
+// extern int dotini(Fs*);
+// extern int fswalk(Fs*, char*, File*);
+// extern int fsread(File*, void*, long);
+// extern int fsboot(Fs*, char*, Boot*);
#define BADPTR(x) ((ulong)x < 0x80000000)
diff --git a/src/9vx/a/io.h b/src/9vx/a/io.h
@@ -1,7 +1,7 @@
#define X86STEPPING(x) ((x) & 0x0F)
-/* incorporate extended-model bits */
+/* incorporates extended-model and -family bits */
#define X86MODEL(x) ((((x)>>4) & 0x0F) | (((x)>>16) & 0x0F)<<4)
-#define X86FAMILY(x) (((x)>>8) & 0x0F)
+#define X86FAMILY(x) ((((x)>>8) & 0x0F) | (((x)>>20) & 0xFF)<<4)
enum {
VectorNMI = 2, /* non-maskable interrupt */
@@ -259,6 +259,12 @@ struct Pcidev
int pmrb; /* power management register block */
};
+enum {
+ /* vendor ids */
+ Vintel = 0x8086,
+ Vmyricom= 0x14c1,
+};
+
#define PCIWINDOW 0
#define PCIWADDR(va) (PADDR(va)+PCIWINDOW)
#define ISAWINDOW 0
diff --git a/src/9vx/a/ip.h b/src/9vx/a/ip.h
@@ -12,6 +12,59 @@ enum
IP_VER6= 0x60,
};
+/*
+ * for reading /net/ipifc
+ */
+typedef struct Ipifc Ipifc;
+typedef struct Iplifc Iplifc;
+typedef struct Ipv6rp Ipv6rp;
+
+/* local address */
+struct Iplifc
+{
+ Iplifc *next;
+
+ /* per address on the ip interface */
+ uchar ip[IPaddrlen];
+ uchar mask[IPaddrlen];
+ uchar net[IPaddrlen]; /* ip & mask */
+ ulong preflt; /* preferred lifetime */
+ ulong validlt; /* valid lifetime */
+};
+
+/* default values, one per stack */
+struct Ipv6rp
+{
+ int mflag;
+ int oflag;
+ int maxraint;
+ int minraint;
+ int linkmtu;
+ int reachtime;
+ int rxmitra;
+ int ttl;
+ int routerlt;
+};
+
+/* actual interface */
+struct Ipifc
+{
+ Ipifc *next;
+ Iplifc *lifc;
+
+ /* per ip interface */
+ int index; /* number of interface in ipifc dir */
+ char dev[64];
+ uchar sendra6; /* on == send router adv */
+ uchar recvra6; /* on == rcv router adv */
+ int mtu;
+ ulong pktin;
+ ulong pktout;
+ ulong errin;
+ ulong errout;
+ Ipv6rp rp;
+};
+
#define ISIPV6MCAST(addr) ((addr)[0] == 0xff)
#define ISIPV6LINKLOCAL(addr) ((addr)[0] == 0xfe && ((addr)[1] & 0xc0) == 0x80)
@@ -115,6 +168,8 @@ int myetheraddr(uchar*, char*);
int equivip4(uchar*, uchar*);
int equivip6(uchar*, uchar*);
+Ipifc* readipifc(char*, Ipifc*, int);
+
void hnputv(void*, uvlong);
void hnputl(void*, uint);
void hnputs(void*, ushort);
diff --git a/src/9vx/a/libsec.h b/src/9vx/a/libsec.h
@@ -21,17 +21,26 @@ struct AESstate
ulong setup;
int rounds;
int keybytes;
-// uint ctrsz;
+ uint ctrsz;
uchar key[AESmaxkey]; /* unexpanded key */
ulong ekey[4*(AESmaxrounds + 1)]; /* encryption key */
ulong dkey[4*(AESmaxrounds + 1)]; /* decryption key */
uchar ivec[AESbsize]; /* initialization vector */
-// uchar mackey[3 * AESbsize]; /* 3 XCBC mac 96 keys */
+ uchar mackey[3 * AESbsize]; /* 3 XCBC mac 96 keys */
};
+/* block ciphers */
+void aes_encrypt(ulong rk[], int Nr, uchar pt[16], uchar ct[16]);
+void aes_decrypt(ulong rk[], int Nr, uchar ct[16], uchar pt[16]);
+
void setupAESstate(AESstate *s, uchar key[], int keybytes, uchar *ivec);
void aesCBCencrypt(uchar *p, int len, AESstate *s);
void aesCBCdecrypt(uchar *p, int len, AESstate *s);
+void aesCTRdecrypt(uchar *p, int len, AESstate *s);
+void aesCTRencrypt(uchar *p, int len, AESstate *s);
+
+void setupAESXCBCstate(AESstate *s);
+uchar* aesXCBCmac(uchar *p, int len, AESstate *s);
/*
* Blowfish Definitions
@@ -127,6 +136,10 @@ void des3ECBdecrypt(uchar*, int, DES3state*);
enum
{
SHA1dlen= 20, /* SHA digest length */
+ SHA2_224dlen= 28, /* SHA-224 digest length */
+ SHA2_256dlen= 32, /* SHA-256 digest length */
+ SHA2_384dlen= 48, /* SHA-384 digest length */
+ SHA2_512dlen= 64, /* SHA-512 digest length */
MD4dlen= 16, /* MD4 digest length */
MD5dlen= 16, /* MD5 digest length */
AESdlen= 16, /* TODO: see rfc */
@@ -138,14 +151,21 @@ typedef struct DigestState DigestState;
struct DigestState
{
uvlong len;
- uint32 state[5];
- uchar buf[128];
+ union {
+ uint32 state[8];
+ uint64 bstate[8];
+ };
+ uchar buf[256];
int blen;
char malloced;
char seeded;
};
typedef struct DigestState SHAstate; /* obsolete name */
typedef struct DigestState SHA1state;
+typedef struct DigestState SHA2_224state;
+typedef struct DigestState SHA2_256state;
+typedef struct DigestState SHA2_384state;
+typedef struct DigestState SHA2_512state;
typedef struct DigestState MD5state;
typedef struct DigestState MD4state;
typedef struct DigestState AEShstate;
@@ -153,6 +173,10 @@ typedef struct DigestState AEShstate;
DigestState* md4(uchar*, ulong, uchar*, DigestState*);
DigestState* md5(uchar*, ulong, uchar*, DigestState*);
DigestState* sha1(uchar*, ulong, uchar*, DigestState*);
+DigestState* sha2_224(uchar*, ulong, uchar*, DigestState*);
+DigestState* sha2_256(uchar*, ulong, uchar*, DigestState*);
+DigestState* sha2_384(uchar*, ulong, uchar*, DigestState*);
+DigestState* sha2_512(uchar*, ulong, uchar*, DigestState*);
DigestState* aes(uchar*, ulong, uchar*, DigestState*);
DigestState* hmac_x(uchar *p, ulong len, uchar *key, ulong klen,
uchar *digest, DigestState *s,
@@ -160,6 +184,10 @@ DigestState* hmac_x(uchar *p, ulong len, uchar *key, ulong klen,
int xlen);
DigestState* hmac_md5(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
DigestState* hmac_sha1(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
+DigestState* hmac_sha2_224(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
+DigestState* hmac_sha2_256(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
+DigestState* hmac_sha2_384(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
+DigestState* hmac_sha2_512(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
DigestState* hmac_aes(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
char* md5pickle(MD5state*);
MD5state* md5unpickle(char*);
diff --git a/src/9vx/a/mem.h b/src/9vx/a/mem.h
@@ -17,7 +17,7 @@
#define PGROUND(s) ROUND(s, BY2PG)
#define BLOCKALIGN 8
-#define MAXMACH 128 /* max # cpus system can run */
+#define MAXMACH 24 /* max # cpus system can run */
#define KSTACK 65536 /* Size of kernel stack */
/*
diff --git a/src/9vx/a/part.c b/src/9vx/a/part.c
@@ -13,6 +13,7 @@ enum {
uchar *mbrbuf, *partbuf;
int nbuf;
+
#define trace 0
int
@@ -104,7 +105,7 @@ p9part(SDunit *unit, char *name)
char *field[4], *line[Npart+1];
uvlong start, end;
int i, n;
-
+
p = sdfindpart(unit, name);
if(p == nil)
return;
@@ -125,7 +126,7 @@ p9part(SDunit *unit, char *name)
if(getfields(line[i], field, 4, 0, " ") != 4)
break;
start = strtoull(field[2], 0, 0);
- end = strtoull(field[3], 0, 0);
+ end = strtoull(field[3], 0, 0);
if(start >= end || end > unit->sectors)
break;
sdaddpart(unit, field[1], p->start+start, p->start+end);
@@ -159,16 +160,18 @@ mbrpart(SDunit *unit)
taboffset = 0;
dp = (Dospart*)&mbrbuf[0x1BE];
- if(1) {
+ {
/* get the MBR (allowing for DMDDO) */
- if(tsdbio(unit, &unit->part[0], mbrbuf, (vlong)taboffset*unit->secsize, 1) < 0)
+ if(tsdbio(unit, &unit->part[0], mbrbuf,
+ (vlong)taboffset * unit->secsize, 1) < 0)
return -1;
for(i=0; i<4; i++)
if(dp[i].type == DMDDO) {
if(trace)
print("DMDDO partition found\n");
taboffset = 63;
- if(tsdbio(unit, &unit->part[0], mbrbuf, (vlong)taboffset*unit->secsize, 1) < 0)
+ if(tsdbio(unit, &unit->part[0], mbrbuf,
+ (vlong)taboffset * unit->secsize, 1) < 0)
return -1;
i = -1; /* start over */
}
@@ -182,7 +185,8 @@ mbrpart(SDunit *unit)
havedos = 0;
firstxpart = 0;
for(;;) {
- if(tsdbio(unit, &unit->part[0], mbrbuf, (vlong)taboffset*unit->secsize, 1) < 0)
+ if(tsdbio(unit, &unit->part[0], mbrbuf,
+ (vlong)taboffset * unit->secsize, 1) < 0)
return -1;
if(trace) {
if(firstxpart)
@@ -251,7 +255,7 @@ part9660(SDunit *unit)
if(unit->secsize != 2048)
return -1;
- if(unit->dev->ifc->bio(unit, 0, 0, buf, 2048/unit->secsize, (17*2048)/unit->secsize) < 0)
+ if(unit->dev->ifc->bio(unit, 0, 0, buf, 2048/unit->secsize, (a*2048)/unit->secsize) < 0)
return -1;
if(buf[0] || strcmp((char*)buf+1, "CD001\x01EL TORITO SPECIFICATION") != 0)
@@ -333,9 +337,15 @@ partition(SDunit *unit)
nbuf = unit->secsize;
}
+ /*
+ * there might be no mbr (e.g. on a very large device), so look for
+ * a bare plan 9 partition table if mbrpart fails.
+ */
if((type & NEW) && mbrpart(unit) >= 0){
- /* nothing to do */;
+ /* nothing to do */
}
+ else if (type & NEW)
+ p9part(unit, "data");
else if(type & OLD)
oldp9part(unit);
}
diff --git a/src/9vx/a/portdat.h b/src/9vx/a/portdat.h
@@ -310,6 +310,7 @@ struct Page
ulong pa; /* Physical address in memory */
ulong va; /* Virtual address for user */
ulong daddr; /* Disc address on swap */
+ ulong gen; /* Generation counter for swap */
ushort ref; /* Reference count */
char modref; /* Simulated modify/reference bits */
char color; /* Cache coloring */
@@ -752,8 +753,7 @@ struct Proc
* machine specific MMU
*/
PMMU pmmu;
- /* syscall trace */
- char *syscalltrace;
+ char *syscalltrace; /* syscall trace */
};
enum
@@ -784,6 +784,7 @@ extern char* statename[];
extern Image swapimage;
extern char* sysname;
extern uint qiomaxatomic;
+extern char* sysctab[];
enum
{
diff --git a/src/9vx/a/proc.c b/src/9vx/a/proc.c
@@ -1,11 +1,11 @@
#define WANT_M
-#include "u.h"
+#include "u.h"
#include "lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "error.h"
-#include "trace.h"
+#include "trace.h"
int schedgain = 30; /* units in seconds */
int nrdy;
@@ -619,8 +619,12 @@ newproc(void)
if(up && up->procctl == Proc_tracesyscall)
p->procctl = Proc_tracesyscall;
else
+ if(up && up->procctl == Proc_tracesyscall)
+ p->procctl = Proc_tracesyscall;
+ else
p->procctl = 0;
p->syscalltrace = 0;
+ p->syscalltrace = 0;
p->notepending = 0;
p->ureg = 0;
p->privatemem = 0;
@@ -1054,6 +1058,8 @@ pexit(char *exitstr, int freemem)
if(up->syscalltrace)
free(up->syscalltrace);
+ if(up->syscalltrace)
+ free(up->syscalltrace);
up->alarm = 0;
if (up->timer.tt)
timerdel(&up->timer);
diff --git a/src/9vx/a/qlock.c b/src/9vx/a/qlock.c
@@ -4,9 +4,9 @@
#include "mem.h"
#include "dat.h"
#include "fns.h"
-
int tracelock = 0;
+
struct {
ulong rlock;
ulong rlockq;
@@ -22,12 +22,12 @@ __qlock(QLock *q)
Proc *p;
if(m->ilockdepth != 0)
- print("qlock: %lux: ilockdepth %d\n", getcallerpc(&q), m->ilockdepth);
+ print("qlock: %#p: ilockdepth %d\n", getcallerpc(&q), m->ilockdepth);
if(up != nil && up->nlocks.ref)
- print("qlock: %lux: nlocks %lud\n", getcallerpc(&q), up->nlocks.ref);
+ print("qlock: %#p: nlocks %lud\n", getcallerpc(&q), up->nlocks.ref);
if(q->use.key == 0x55555555)
- panic("qlock: q %p, key 5*\n", q);
+ panic("qlock: q %#p, key 5*\n", q);
lock(&q->use);
rwstats.qlock++;
if(!q->locked) {
diff --git a/src/9vx/a/segment.c b/src/9vx/a/segment.c
@@ -64,8 +64,6 @@ newseg(int type, ulong base, ulong size)
if(size > (SEGMAPSIZE*PTEPERTAB))
error(Enovmem);
- if(swapfull())
- error(Enoswap);
s = smalloc(sizeof(Segment));
s->ref.ref = 1;
s->type = type;
@@ -160,7 +158,7 @@ dupseg(Segment **seg, int segno, int share)
Pte *pte;
Segment *n, *s;
- n = 0;
+ ;
s = seg[segno];
qlock(&s->lk);
@@ -465,6 +463,14 @@ ibrk(ulong addr, int seg)
newtop = PGROUND(addr);
newsize = (newtop-s->base)/BY2PG;
if(newtop < s->top) {
+ /*
+ * do not shrink a segment shared with other procs, as the
+ * to-be-freed address space may have been passed to the kernel
+ */
+ if(s->ref.ref > 1){
+ qunlock(&s->lk);
+ error(Einuse);
+ }
mfreeseg(s, newtop, (s->top-newtop)/BY2PG);
s->top = newtop;
s->size = newsize;
@@ -473,11 +479,6 @@ ibrk(ulong addr, int seg)
return 0;
}
- if(swapfull()){
- qunlock(&s->lk);
- error(Enoswap);
- }
-
for(i = 0; i < NSEG; i++) {
ns = up->seg[i];
if(ns == 0 || ns == s)
@@ -675,22 +676,23 @@ segattach(Proc *p, ulong attr, char *name, ulong va, ulong len)
* Starting at the lowest possible stack address - len,
* check for an overlapping segment, and repeat at the
* base of that segment - len until either a hole is found
- * or the address space is exhausted.
+ * or the address space is exhausted. Ensure that we don't
+ * map the zero page.
*/
if(va == 0) {
- va = p->seg[SSEG]->base - len;
- for(;;) {
- os = isoverlap(p, va, len);
- if(os == nil)
- break;
+ for (os = p->seg[SSEG]; os != nil; os = isoverlap(p, va, len)) {
va = os->base;
- if(len > va)
+ if(len >= va)
error(Enovmem);
va -= len;
}
+ va &= ~(BY2PG-1);
+ } else {
+ va &= ~(BY2PG-1);
+ if(va == 0 || va >= USTKTOP)
+ error(Ebadarg);
}
- va = va&~(BY2PG-1);
if(isoverlap(p, va, len) != nil)
error(Esoverlap);
diff --git a/src/9vx/a/segment.ed b/src/9vx/a/segment.ed
@@ -23,5 +23,5 @@
/^}/i
#endif
.
-/validaddr/d
/^syssegflush/s/ulong/uint32/
+g/validaddr/d
diff --git a/src/9vx/a/swap.c b/src/9vx/a/swap.c
@@ -12,10 +12,25 @@ static void pageout(Proc*, Segment*);
static void pagepte(int, Page**);
static void pager(void *v);
- Image swapimage;
+Image swapimage;
+
static Page **iolist;
static int ioptr;
+static ulong genage, genclock, gencount;
+static uvlong gensum;
+
+static void
+gentick(void)
+{
+ genclock++;
+ if(gencount)
+ genage = gensum / gencount;
+ else
+ genage = 0;
+ gensum = gencount = 0;
+}
+
void
swapinit(void)
{
@@ -114,15 +129,17 @@ pager(void *junk)
loop:
up->psstate = "Idle";
+ wakeup(&palloc.r);
sleep(&swapalloc.r, needpages, 0);
while(needpages(junk)) {
-
if(swapimage.c) {
p++;
- if(p >= ep)
+ if(p >= ep){
p = proctab(0);
-
+ gentick();
+ }
+
if(p->state == Dead || p->noswap)
continue;
@@ -157,15 +174,14 @@ loop:
}
}
qunlock(&p->seglock);
- }
- else {
- print("out of physical memory; no swap configured\n");
- if(!cpuserver || freebroken() == 0)
- killbig("out of memory");
+ } else {
+ print("out of memory\n");
+ killbig("out of memory");
+ freebroken(); /* can use the memory */
/* Emulate the old system if no swap channel */
- tsleep(&up->sleep, return0, 0, 5000);
- wakeup(&palloc.r);
+ if(!swapimage.c)
+ tsleep(&up->sleep, return0, 0, 5000);
}
}
goto loop;
@@ -175,6 +191,7 @@ static void
pageout(Proc *p, Segment *s)
{
int type, i, size;
+ ulong age;
Pte *l;
Page **pg, *entry;
@@ -212,9 +229,18 @@ pageout(Proc *p, Segment *s)
if(entry->modref & PG_REF) {
entry->modref &= ~PG_REF;
- continue;
+ entry->gen = genclock;
}
+ if(genclock < entry->gen)
+ age = ~(entry->gen - genclock);
+ else
+ age = genclock - entry->gen;
+ gensum += age;
+ gencount++;
+ if(age <= genage)
+ continue;
+
pagepte(type, pg);
if(ioptr >= conf.nswppo)
@@ -321,6 +347,19 @@ pagersummary(void)
ioptr);
}
+static int
+pageiocomp(void *a, void *b)
+{
+ Page *p1, *p2;
+
+ p1 = *(Page **)a;
+ p2 = *(Page **)b;
+ if(p1->daddr > p2->daddr)
+ return 1;
+ else
+ return -1;
+}
+
static void
executeio(void)
{
@@ -331,7 +370,7 @@ executeio(void)
KMap *k;
c = swapimage.c;
-
+ qsort(iolist, ioptr, sizeof iolist[0], pageiocomp);
for(i = 0; i < ioptr; i++) {
if(ioptr > conf.nswppo)
panic("executeio: ioptr %d > %d", ioptr, conf.nswppo);
diff --git a/src/9vx/a/sysfile.ed b/src/9vx/a/sysfile.ed
@@ -13,7 +13,175 @@
// Plan 9 VX replaced dodgy varargs code
v = *(vlong*)&arg[3];
.
+,s/return bindmount(/return bindmount(0, /g
g/^sys_/ s/ulong \*)/ulong *u)/
+g/^[a-z]/ s/ulong/uint32/g
+/^openmode/ s/uint32/ulong/
+/^sysfd2path/ s/^//
+/validaddr/-1;+1c
+ char *buf;
+
+ buf = uvalidaddr(arg[1], arg[2], 1);
+.
+/snprint/ s/(char\*)arg\[1\]/buf/
+/^syspipe/ s/^//
+/validaddr/-1;+1c
+ int *ufd;
+
+ ufd = uvalidaddr(arg[0], 2*BY2WD, 1);
+.
+/((long\*)arg\[0\])/ s/((long\*)arg\[0\])/ufd/
+/((long\*)arg\[0\])/ s/((long\*)arg\[0\])/ufd/
+/^sysopen/ s/^//
+/^$/i
+ char *name;
+.
+/openmode/a
+ name = uvalidaddr(arg[0], 1, 0);
+ c = namec(name, Aopen, arg[1], 0);
+.
+/if(c)/d
+s/ //
+/validaddr/;/c = namec/d
+/^doread/ s/^//
+/^{/a
+ int dir;
+.
+/validaddr/;/p =/c
+ p = uvalidaddr(arg[1], n, 1);
+.
+/QTDIR/;/c->umh/c
+ dir = c->qid.type&QTDIR;
+ if(dir && mountrockread(c, p, n, &nn)){
+ /* do nothing: mountrockread filled buffer */
+ }else{
+ if(dir && c->umh)
+.
+/else{/;/}/c
+ else
+ nn = devtab[c->type]->read(c, p, n, off);
+ }
+ if(dir)
+.
+/}else/;/nnn/c
+ else
+ nnn = nn;
+.
+/^dowrite/ s/^//
+/^$/i
+ uchar *p;
+.
+/validaddr/ s/v/p = uv/
+/m = devtab/ s/(void\*)arg\[1\]/p/
+/^sseek/s/(/(vlong *ret, /
+/u\[2\]/ s/ulong/uint32/
+/arg\[0\] = off/ s/\*(vlong\*)arg\[0\]/*ret/
+/^sysseek/s/^//
+/validaddr/;/sseek/c
+ sseek(uvalidaddr(arg[0], BY2V, 1), arg);
+.
+/^sysoseek/s/^//
+/^{/;/^$/s/ulong/uint32/g
+/a\[0\]/ s/=.*/= 0;/
+/sseek/ s/(.*)/(\&o.v, a)/
+/^sysfstat/ s/^//
+/^$/i
+ uchar *p;
+.
+/validaddr/ s/v/p = uv/
+/l = devtab/ s/(.*)/(c, p, l)/
+/^sysstat/ s/^//
+/^$/i
+ uchar *p;
+.
+/validaddr/ s/v/p = uv/
+/validaddr/ s/v/name = uv/
+/c = namec/ s/(char\*)arg\[0\]/name/
+/l = devtab/ s/(.*)/(c, p, l)/
+/l = dirsetname/ s/(uchar\*)arg\[1\]/p/
+/^syschdir/ s/^//
+/^$/i
+ char *name;
+.
+/validaddr/ s/v/name = uv/
+/c = namec/ s/(char\*)arg\[0\]/name/
+s/uint32/ulong/
+/^sysbind/ s/^//
+/return/ s/0, //
+s/(char\*)arg\[0\]/uvalidaddr(arg[0], 1, 0)/
+s/(char\*)arg\[1\]/uvalidaddr(arg[1], 1, 0)/
+/^sysmount/ s/^//
+/return/ s/0, //
+s/(char\*)arg\[2\]/uvalidaddr(arg[2], 1, 0)/
+s/(char\*)arg\[4\]/uvalidaddr(arg[4], 1, 0)/
+/^sys_mount/ s/^//
+/return/ s/0, //
+s/(char\*)arg\[1\]/uvalidaddr(arg[1], 1, 0)/
+s/(char\*)arg\[3\]/uvalidaddr(arg[3], 1, 0)/
+/^sysunmount/ s/^//
+/^$/i
+ char *mount, *mounted;
+.
+/validaddr/;/cmount/c
+ mount = uvalidaddr(arg[1], 1, 0);
+ cmount = namec(mount, Amount, 0, 0);
+.
+/validaddr/ s/v/mounted = uv/
+/cmounted/ s/(char\*)arg\[0\]/mounted/
+/^syscreate/ s/^//
+/^$/i
+ char *name;
+.
+/validaddr/;/c = namec/c
+ name = uvalidaddr(arg[0], 1, 0);
+ c = namec(name, Acreate, arg[1], arg[2]);
+.
+/^sysremove/ s/^//
+/^$/i
+ char *name;
+.
+/validaddr/;/c = namec/c
+ name = uvalidaddr(arg[0], 1, 0);
+ c = namec(name, Aremove, 0, 0);
+.
+/^syswstat/ s/^//
+/^$/i
+ char *name;
+ uchar *p;
+.
+/validaddr/;/return/c
+ p = uvalidaddr(arg[1], l, 0);
+ validstat(p, l);
+ name = uvalidaddr(arg[0], 1, 0);
+ c = namec(name, Aaccess, 0, 0);
+ return wstat(c, p, l);
+.
+/^sysfwstat/ s/^//
+/^$/i
+ uchar *p;
+.
+/validaddr/ s/v/p = uv/
+/validstat/ s/(uchar\*)arg\[1\]/p/
+/return/ s/(uchar\*)arg\[1\]/p/
+/^sys_stat/ s/^//
+/name/ s/;/, *elem;/
+/^$/i
+ uchar *p;
+.
+/validaddr/;/namec/c
+ p = uvalidaddr(arg[1], 116, 1);
+ name = uvalidaddr(arg[0], 1, 0);
+ c = namec(name, Aaccess, 0, 0);
+.
+/name =/;/l =/ s/name/elem/g
+/dirsetelem/ s/elem/name/
+/packoldstat/ s/(uchar\*)arg\[1\]/p/
+/^sys_fstat/ s/^//
+/^$/i
+ uchar *p;
+.
+/validaddr/ s/v/p = uv/
+/packoldstat/ s/(uchar\*)arg\[1\]/p/
$a
// Plan 9 VX additions
diff --git a/src/9vx/a/sysproc.c b/src/9vx/a/sysproc.c
@@ -7,7 +7,7 @@
#include "fns.h"
#include "error.h"
-#include "a.out.h"
+#include "a.out.h"
int shargs(char*, int, char**);
diff --git a/src/9vx/a/tos.h b/src/9vx/a/tos.h
@@ -1,7 +1,6 @@
typedef struct Tos Tos;
typedef struct Plink Plink;
-#if 0
struct Tos {
struct /* Per process profiling */
@@ -20,25 +19,5 @@ struct Tos {
ulong clock;
/* top of stack is here */
};
-#else
-
-struct Tos {
- struct /* Per process profiling */
- {
- uint32_t pp; /* known to be 0(ptr) */
- uint32_t next; /* known to be 4(ptr) */
- uint32_t last;
- uint32_t first;
- uint32_t pid;
- uint32_t what;
- } prof;
- uvlong cyclefreq; /* cycle clock frequency if there is one, 0 otherwise */
- vlong kcycles; /* cycles spent in kernel */
- vlong pcycles; /* cycles spent in process (kernel + user) */
- uint32_t pid; /* might as well put the pid here */
- uint32_t clock;
- /* top of stack is here */
-};
-#endif
extern Tos *_tos;
diff --git a/src/9vx/a/unthwack.c b/src/9vx/a/unthwack.c
@@ -171,7 +171,8 @@ unthwack(Unthwack *ut, uchar *dst, int ndst, uchar *src, int nsrc, ulong seq)
}
eblocks = b;
if(cseq != seq){
- print("blocks dropped: seq=%ld cseq=%ld %d cmask=%#lx %#x\n", seq, cseq, src[0], cmask, src[1]);
+ print("unthwack: blocks dropped: seq=%ld cseq=%ld %d cmask=%#lx %#x\n",
+ seq, cseq, src[0], cmask, src[1]);
return -2;
}