myproc() points to a different thread.
myproc();
sched();
myproc(); // this proc maybe different than the one before sched
Thus, in a function that operates on one thread better to retrieve the
current process once at the start of the function.
Previously, these were inconsistent: they used their struct proc
argument for bounds checking, but always copied the argument from the
current address space (and hence the current process). Drop the
struct proc argument and always use the current proc.
Suggested by Carmi Merimovich.
My changes have a race with re-used bufs and the code doesn't seem to get shorter
Keep the changes that fixed ip->off race
This reverts commit 3a5fa7ed90.
Conflicts:
defs.h
file.c
file.h
Remove I_BUSY, B_BUSY, and intrans defs and usages
One spinlock per buf to avoid ugly loop in bget
fix race in filewrite (don't update f->off after releasing lock)
Variable declarations at top of function,
separate from initialization.
Use == 0 instead of ! for checking pointers.
Consistent spacing around {, *, casts.
Declare 0-parameter functions as (void) not ().
Integer valued functions return -1 on failure, 0 on success.
the macro expansion of "char *cp;" turned into
char *(curproc[cpu()]); which declares a dynamically
sized array of char* called curproc.
so then &cp == &(curproc[cpu()]) was actually a
stack variable as "expected". it was one past the
end of the array, but the implicit alloca allocated
more than was necessary.
do not tell me that making cp a #define was a bad idea.
there are worse problems to fix. more on that later.
Various changes made while offline.
+ bwrite sector argument is redundant; use b->sector.
+ reformatting of files for nicer PDF page breaks
+ distinguish between locked, unlocked inodes in type signatures
+ change FD_FILE to FD_INODE
+ move userinit (nee proc0init) to proc.c
+ move ROOTDEV to param.h
+ always parenthesize sizeof argument
- Got rid of dummy proc[0]. Now proc[0] is init.
- Added initcode.S to exec /init, so that /init is
just a regular binary.
- Moved exec out of sysfile to exec.c
- Moved code dealing with fs guts (like struct inode)
from sysfile.c to fs.c. Code dealing with system call
arguments stays in sysfile.c
- Refactored directory routines in fs.c; should be simpler.
- Changed iget to return *unlocked* inode structure.
This solves the lookup-then-use race in namei
without introducing deadlocks.
It also enabled getting rid of the dummy proc[0].