Skip to content

Commit bd0c933

Browse files
committed
Plan 9 from Bell Labs 2014-05-15
1 parent 6d3b63b commit bd0c933

27 files changed

+234
-110
lines changed

sys/doc/backup.ms

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ as the term is used by everyone but disk manufacturers.
3232
In the case of BDs,
3333
even that is an exaggeration, with the actual capacity being
3434
closer to $48.44 times 10 sup 9$ bytes,
35-
so the claimed capacity should be read as `50 VAX-gigabytes',
35+
so the claimed capacity should be read as `50 BD-gigabytes',
3636
where a
37-
.I VAX-gigabyte
37+
.I BD-gigabyte
3838
is 968,800,338 bytes.
3939
The default
4040
.I venti

sys/doc/backup.pdf

31.2 KB
Binary file not shown.

sys/doc/backup.ps

-2 Bytes
Binary file not shown.

sys/man/2/time

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,27 @@ should be stored in and treated as
3333
.BR ulong s;
3434
this extends the range of valid times into the year 2106.
3535
.PP
36-
These functions work by reading
36+
.I Time
37+
simply calls
38+
.I nsec
39+
and returns the value divided by 1000000000.
40+
.PP
41+
.I Nsec
42+
is a system call.
43+
Previous implementations read
3744
.BR /dev/bintime ,
38-
opening that file when they are first called.
45+
opening that file when first called,
46+
and maintaining a static file descriptor;
47+
however,
48+
the maintenance of file descriptors in the face
49+
of process forks is overly complex and prone to error.
3950
.SH SOURCE
4051
.B /sys/src/libc/9sys/time.c
4152
.br
42-
.B /sys/src/libc/9sys/nsec.c
53+
.B /sys/src/libc/9syscall
4354
.SH SEE ALSO
4455
.IR cputime (2),
4556
.IR cons (3)
4657
.SH DIAGNOSTICS
4758
Sets
4859
.IR errstr .
49-
.SH BUGS
50-
These routines maintain a static file descriptor.

sys/src/9/bcm/fns.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ extern int fpuemu(Ureg*);
9595
extern void delay(int); /* only scheddump() */
9696
extern int islo(void);
9797
extern void microdelay(int); /* only edf.c */
98-
extern void evenaddr(uintptr);
9998
extern void idlehands(void);
10099
extern void setkernur(Ureg*, Proc*); /* only devproc.c */
101100
extern void* sysexecregs(uintptr, ulong, int);
102101
extern void sysprocsetup(Proc*);
102+
extern void validalign(uintptr, unsigned);
103103

104104
extern void kexit(Ureg*);
105105

sys/src/9/kw/arch.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,32 @@ setkernur(Ureg* ureg, Proc* p)
2828
}
2929

3030
/*
31-
* called in sysfile.c
31+
* called in syscallfmt.c, sysfile.c, sysproc.c
3232
*/
3333
void
34-
evenaddr(uintptr addr)
35-
{
36-
if(addr & 3){
37-
postnote(up, 1, "sys: odd address", NDebug);
38-
error(Ebadarg);
39-
}
34+
validalign(uintptr addr, unsigned align)
35+
{
36+
/*
37+
* Plan 9 is a 32-bit O/S, and the hardware it runs on
38+
* does not usually have instructions which move 64-bit
39+
* quantities directly, synthesizing the operations
40+
* with 32-bit move instructions. Therefore, the compiler
41+
* (and hardware) usually only enforce 32-bit alignment,
42+
* if at all.
43+
*
44+
* Take this out if the architecture warrants it.
45+
*/
46+
if(align == sizeof(vlong))
47+
align = sizeof(long);
48+
49+
/*
50+
* Check align is a power of 2, then addr alignment.
51+
*/
52+
if((align != 0 && !(align & (align-1))) && !(addr & (align-1)))
53+
return;
54+
postnote(up, 1, "sys: odd address", NDebug);
55+
error(Ebadarg);
56+
/*NOTREACHED*/
4057
}
4158

4259
/* go to user space */

sys/src/9/kw/fns.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ extern Block* uciallocb(int);
128128
extern void delay(int); /* only scheddump() */
129129
extern int islo(void);
130130
extern void microdelay(int); /* only edf.c */
131-
extern void evenaddr(uintptr);
132131
extern void idlehands(void);
133132
extern void setkernur(Ureg*, Proc*); /* only devproc.c */
134133
extern void spldone(void);
135134
extern int splfhi(void);
136135
extern int splflo(void);
137136
extern void sysprocsetup(Proc*);
137+
extern void validalign(uintptr, unsigned);
138138

139139
/*
140140
* PCI

sys/src/9/mtx/fns.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ void delay(int);
1515
void dumpregs(Ureg*);
1616
void delayloopinit(void);
1717
void eieio(void);
18-
void evenaddr(ulong);
1918
void faultpower(Ureg*, ulong addr, int read);
2019
void fprestore(FPsave*);
2120
void fpsave(FPsave*);
@@ -103,6 +102,7 @@ void trapvec(void);
103102
void tlbflush(ulong);
104103
void tlbflushall(void);
105104
#define userureg(ur) (((ur)->status & MSR_PR) != 0)
105+
void validalign(uintptr, unsigned);
106106
void watchreset(void);
107107

108108
#define waserror() (up->nerrlab++, setlabel(&up->errlab[up->nerrlab-1]))

sys/src/9/mtx/trap.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,32 @@ kprocchild(Proc *p, void (*func)(void*), void *arg)
522522
}
523523

524524
/*
525-
* called in sysfile.c
525+
* called in syscallfmt.c, sysfile.c, sysproc.c
526526
*/
527527
void
528-
evenaddr(ulong addr)
528+
validalign(uintptr addr, unsigned align)
529529
{
530-
if(addr & 3){
531-
postnote(up, 1, "sys: odd address", NDebug);
532-
error(Ebadarg);
533-
}
530+
/*
531+
* Plan 9 is a 32-bit O/S, and the hardware it runs on
532+
* does not usually have instructions which move 64-bit
533+
* quantities directly, synthesizing the operations
534+
* with 32-bit move instructions. Therefore, the compiler
535+
* (and hardware) usually only enforce 32-bit alignment,
536+
* if at all.
537+
*
538+
* Take this out if the architecture warrants it.
539+
*/
540+
if(align == sizeof(vlong))
541+
align = sizeof(long);
542+
543+
/*
544+
* Check align is a power of 2, then addr alignment.
545+
*/
546+
if((align != 0 && !(align & (align-1))) && !(addr & (align-1)))
547+
return;
548+
postnote(up, 1, "sys: odd address", NDebug);
549+
error(Ebadarg);
550+
/*NOTREACHED*/
534551
}
535552

536553
long

sys/src/9/omap/arch.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,32 @@ setkernur(Ureg* ureg, Proc* p)
2828
}
2929

3030
/*
31-
* called in sysfile.c
31+
* called in syscallfmt.c, sysfile.c, sysproc.c
3232
*/
3333
void
34-
evenaddr(uintptr addr)
35-
{
36-
if(addr & 3){
37-
postnote(up, 1, "sys: odd address", NDebug);
38-
error(Ebadarg);
39-
}
34+
validalign(uintptr addr, unsigned align)
35+
{
36+
/*
37+
* Plan 9 is a 32-bit O/S, and the hardware it runs on
38+
* does not usually have instructions which move 64-bit
39+
* quantities directly, synthesizing the operations
40+
* with 32-bit move instructions. Therefore, the compiler
41+
* (and hardware) usually only enforce 32-bit alignment,
42+
* if at all.
43+
*
44+
* Take this out if the architecture warrants it.
45+
*/
46+
if(align == sizeof(vlong))
47+
align = sizeof(long);
48+
49+
/*
50+
* Check align is a power of 2, then addr alignment.
51+
*/
52+
if((align != 0 && !(align & (align-1))) && !(addr & (align-1)))
53+
return;
54+
postnote(up, 1, "sys: odd address", NDebug);
55+
error(Ebadarg);
56+
/*NOTREACHED*/
4057
}
4158

4259
/* go to user space */

sys/src/9/omap/fns.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ extern void ucfreeb(Block*);
138138
extern void delay(int); /* only scheddump() */
139139
extern int islo(void);
140140
extern void microdelay(int); /* only edf.c */
141-
extern void evenaddr(uintptr);
142141
extern void idlehands(void);
143142
extern void setkernur(Ureg*, Proc*); /* only devproc.c */
144143
extern void* sysexecregs(uintptr, ulong, int);
145144
extern void sysprocsetup(Proc*);
145+
extern void validalign(uintptr, unsigned);
146146

147147
/*
148148
* PCI stuff.

sys/src/9/pc/fns.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ int dmadone(int);
2626
void dmaend(int);
2727
int dmainit(int, int);
2828
long dmasetup(int, void*, long, int);
29-
#define evenaddr(x) /* x86 doesn't care */
3029
void fpclear(void);
3130
void fpenv(FPsave*);
3231
void fpinit(void);
@@ -182,6 +181,7 @@ ulong upaalloc(int, int);
182181
void upafree(ulong, int);
183182
void upareserve(ulong, int);
184183
#define userureg(ur) (((ur)->cs & 0xFFFF) == UESEL)
184+
void validalign(uintptr, unsigned);
185185
void vectortable(void);
186186
void* vmap(ulong, int);
187187
int vmapsync(ulong);
@@ -190,6 +190,9 @@ void wbinvd(void);
190190
void wrmsr(int, vlong);
191191
int xchgw(ushort*, int);
192192

193+
#define PTR2UINT(p) ((uintptr)(p))
194+
#define UINT2PTR(i) ((void*)(i))
195+
193196
#define waserror() (up->nerrlab++, setlabel(&up->errlab[up->nerrlab-1]))
194197
#define KADDR(a) kaddr(a)
195198
#define PADDR(a) paddr((void*)(a))

sys/src/9/pc/trap.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,32 @@ if(0) print("%s %lud: noted %.8lux %.8lux\n",
953953
}
954954
}
955955

956+
void
957+
validalign(uintptr addr, unsigned align)
958+
{
959+
/*
960+
* Plan 9 is a 32-bit O/S, and the hardware it runs on
961+
* does not usually have instructions which move 64-bit
962+
* quantities directly, synthesizing the operations
963+
* with 32-bit move instructions. Therefore, the compiler
964+
* (and hardware) usually only enforce 32-bit alignment,
965+
* if at all.
966+
*
967+
* Take this out if the architecture warrants it.
968+
*/
969+
if(align == sizeof(vlong))
970+
align = sizeof(long);
971+
972+
/*
973+
* Check align is a power of 2, then addr alignment.
974+
*/
975+
if((align != 0 && !(align & (align-1))) && !(addr & (align-1)))
976+
return;
977+
postnote(up, 1, "sys: odd address", NDebug);
978+
error(Ebadarg);
979+
/*NOTREACHED*/
980+
}
981+
956982
long
957983
execregs(ulong entry, ulong ssize, ulong nargs)
958984
{

sys/src/9/port/syscallfmt.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ syscallfmt(int syscallno, ulong pc, va_list list)
113113
a = va_arg(list, char*);
114114
fmtuserstring(&fmt, a, "");
115115
argv = va_arg(list, char**);
116-
evenaddr(PTR2UINT(argv));
116+
validalign(PTR2UINT(argv), sizeof(char*));
117117
for(;;){
118118
validaddr((ulong)argv, sizeof(char**), 0);
119119
a = *(char **)argv;
@@ -299,6 +299,10 @@ syscallfmt(int syscallno, ulong pc, va_list list)
299299
fmtprint(&fmt, " %lld", vl);
300300
}
301301
break;
302+
case NSEC:
303+
v = va_arg(list, vlong*);
304+
fmtprint(&fmt, "%#p", v);
305+
break;
302306
}
303307

304308
up->syscalltrace = fmtstrflush(&fmt);
@@ -400,6 +404,9 @@ sysretfmt(int syscallno, va_list list, long ret, uvlong start, uvlong stop)
400404
}
401405
fmtprint(&fmt, " = %ld", ret);
402406
break;
407+
case NSEC:
408+
fmtprint(&fmt, " = %ld", ret); /* FoV */
409+
break;
403410
}
404411
fmtprint(&fmt, " %s %#llud %#llud\n", errstr, start, stop);
405412
up->syscalltrace = fmtstrflush(&fmt);

sys/src/9/port/sysfile.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ syspipe(ulong *arg)
190190
Dev *d;
191191
static char *datastr[] = {"data", "data1"};
192192

193-
validaddr(arg[0], 2*BY2WD, 1);
194-
evenaddr(arg[0]);
193+
validaddr(arg[0], sizeof(fd), 1);
194+
validalign(arg[0], sizeof(int));
195195
d = devtab[devno('|', 0)];
196196
c[0] = namec("#|", Atodir, 0, 0);
197197
c[1] = 0;
@@ -215,8 +215,8 @@ syspipe(ulong *arg)
215215
error(Enofd);
216216
poperror();
217217

218-
((long*)arg[0])[0] = fd[0];
219-
((long*)arg[0])[1] = fd[1];
218+
((int*)arg[0])[0] = fd[0];
219+
((int*)arg[0])[1] = fd[1];
220220
return 0;
221221
}
222222

@@ -859,7 +859,8 @@ sseek(ulong *arg)
859859
long
860860
sysseek(ulong *arg)
861861
{
862-
validaddr(arg[0], BY2V, 1);
862+
validaddr(arg[0], sizeof(vlong), 1);
863+
validalign(arg[0], sizeof(vlong));
863864
sseek(arg);
864865
return 0;
865866
}

0 commit comments

Comments
 (0)