Unix v6 Ported to ANSI C
os-blog.com
os-blog.com
void*
memmove(void *vdst, void *vsrc, int n)
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
*dst++ = *src++;
return vdst;
}
If the two blocks overlap, and the address of dst is greater than the address of src, then parts of the source will be overwritten before it can be copied.> The memory areas may overlap: copying takes place as though the bytes in src are first copied into a temporary array that does not overlap src or dest, and the bytes are then copied from the temporary array to dest.
http://www.kernel.org/doc/man-pages/online/pages/man3/memmov...
Notice how it says 'as though'; I can't see why doing the copy backwards (from end to start) wouldn't work, myself.
src starts at 50, ends at 100
dst starts at 25, ends at 75.
First we copy 100 to 75, then 99 to 74, etc ... now we get to copy from 75 to 50, but we've overwritten it already! void*
memmove(void *vdst, void *vsrc, int n)
{
char *dst, *src;
dst = vdst;
src = vsrc;
if(*vdst > *vsrc) {
*vdst += n;
*vsrc += n;
while(n-- > 0)
*dst-- = *src--;
}
else if(*vdst < *vsrc)
while(n-- > 0)
*dst++ == *src++;
return vdst;
}Second bug, cheers.
void*
memmove(void *vdst, void *vsrc, int n)
{
char *dst, *src;
dst = vdst;
src = vsrc;
if(vdst > vsrc) {
dst = vdst + n;
src = vsrc + n;
while(n-- > 0)
*--dst = *--src;
}
else if(vdst < vsrc)
while(n-- > 0)
*dst++ == *src++;
return vdst;
}
Does this solve the bugs? /* memmove.c -- copy memory.
Copy LENGTH bytes from SOURCE to DEST. Does not null-terminate.
In the public domain.
By David MacKenzie <djm@gnu.ai.mit.edu>. */
#if HAVE_CONFIG_H
# include <config.h>
#endif
void *
memmove (dest, source, length)
char *dest;
const char *source;
unsigned length;
{
char *d0 = dest;
if (source < dest)
/* Moving from low mem to hi mem; start at end. */
for (source += length, dest += length; length; --length)
*--dest = *--source;
else if (source != dest)
{
/* Moving from hi mem to low mem; start at beginning. */
for (; length; --length)
*dest++ = *source++;
}
return (void *) d0;
}Or, they could be lazy, and hope that this HN thread turns out to be a representative sample of the Textbooks/Operating Systems in use.
If I may prognosticate, stripped-down monolithic OSes running on hypervisors are the wave of the future. Look at VM/CMS for an extreme example: CMS is about as complex as MS-DOS, being a single-user single-tasking OS with no memory protection or security model. VM is the hypervisor. Together, they date to about 1968, or a little before if you include research systems.
http://www.garlic.com/~lynn/2010k.html#25
A Service VM is one where an application runs directly on the 'bare metal' provided by the VM (that is, the whole point of a VM is to multiplex the hardware; it provides few or no abstractions as such). There's no guest OS as you'd think of one.
This idea also exists in exokernel designs:
http://c2.com/cgi/wiki?ExoKernel
http://pdos.csail.mit.edu/exo.html
In an exokernel, the guest OS is reduced to a library, like libc, which is (ideally) optimized for the specific application: Emacs has its own, Apache has its own, and so on. It's a half-step removed from the Service VM idea in that the applications themselves would still get to use the OS abstractions, unaware that the OS is basically gone.
The project page gives this link to the schedule, where the lecture notes are supposed to be, but the link 404's.
Is there a working URL for these lecture notes?
The lectures themselves are not xv6 specific, although the projects are xv6 based.
Those students were MIT students. I'd expect MIT students to not have had a problem with either of these, so I'm a bit puzzled.
P.S. I still maintain a very HLL is ideal for presenting multi-processing/multi-tasking to students.
Edit: all the user tests passed.