summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>2002-07-03 20:47:50 +0000
committerjulian <julian@FreeBSD.org>2002-07-03 20:47:50 +0000
commit45b02b9551294d78d4788fe276832f3f61ab5028 (patch)
tree4bbed7197d45468c827166e9c931a77ee945a17b /sys
parent9925a6e0691b36505c6695c8ebbf51e056ccf7f7 (diff)
downloadFreeBSD-src-45b02b9551294d78d4788fe276832f3f61ab5028.zip
FreeBSD-src-45b02b9551294d78d4788fe276832f3f61ab5028.tar.gz
Add comments and slightly rearrange the thread stack assignment code
to try make it less obscure.
Diffstat (limited to 'sys')
-rw-r--r--sys/amd64/amd64/pmap.c28
-rw-r--r--sys/i386/i386/pmap.c28
2 files changed, 38 insertions, 18 deletions
diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c
index 68b94ba..146d463 100644
--- a/sys/amd64/amd64/pmap.c
+++ b/sys/amd64/amd64/pmap.c
@@ -1012,23 +1012,29 @@ pmap_new_thread(struct thread *td)
#ifdef KSTACK_GUARD
/* get a kernel virtual address for the kstack for this thread */
- ks = kmem_alloc_nofault(kernel_map,
- (KSTACK_PAGES + 1) * PAGE_SIZE);
+ ks = kmem_alloc_nofault(kernel_map, (KSTACK_PAGES + 1) * PAGE_SIZE);
if (ks == 0)
panic("pmap_new_thread: kstack allocation failed");
- ks += PAGE_SIZE;
- td->td_kstack = ks;
- ptek = vtopte(ks - PAGE_SIZE);
+ /*
+ * Set the first page to be the unmapped guard page.
+ */
+ ptek = vtopte(ks);
oldpte = *ptek;
*ptek = 0;
if (oldpte) {
#ifdef I386_CPU
updateneeded = 1;
#else
- invlpg(ks - PAGE_SIZE);
+ invlpg(ks);
#endif
}
+
+ /*
+ * move to the next page, which is where the real stack starts.
+ */
+ ks += PAGE_SIZE;
+ td->td_kstack = ks;
ptek++;
#else
/* get a kernel virtual address for the kstack for this thread */
@@ -1038,6 +1044,10 @@ pmap_new_thread(struct thread *td)
td->td_kstack = ks;
ptek = vtopte(ks);
#endif
+ /*
+ * For the length of the stack, link in a real page of ram for each
+ * page of stack.
+ */
for (i = 0; i < KSTACK_PAGES; i++) {
/*
* Get a kernel stack page
@@ -1050,16 +1060,16 @@ pmap_new_thread(struct thread *td)
m->wire_count++;
cnt.v_wire_count++;
- oldpte = *(ptek + i);
/*
* Enter the page into the kernel address space.
*/
- *(ptek + i) = VM_PAGE_TO_PHYS(m) | PG_RW | PG_V | pgeflag;
+ oldpte = ptek[i];
+ ptek[i] = VM_PAGE_TO_PHYS(m) | PG_RW | PG_V | pgeflag;
if (oldpte) {
#ifdef I386_CPU
updateneeded = 1;
#else
- invlpg(ks + i * PAGE_SIZE);
+ invlpg(ks + (i * PAGE_SIZE));
#endif
}
diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c
index 68b94ba..146d463 100644
--- a/sys/i386/i386/pmap.c
+++ b/sys/i386/i386/pmap.c
@@ -1012,23 +1012,29 @@ pmap_new_thread(struct thread *td)
#ifdef KSTACK_GUARD
/* get a kernel virtual address for the kstack for this thread */
- ks = kmem_alloc_nofault(kernel_map,
- (KSTACK_PAGES + 1) * PAGE_SIZE);
+ ks = kmem_alloc_nofault(kernel_map, (KSTACK_PAGES + 1) * PAGE_SIZE);
if (ks == 0)
panic("pmap_new_thread: kstack allocation failed");
- ks += PAGE_SIZE;
- td->td_kstack = ks;
- ptek = vtopte(ks - PAGE_SIZE);
+ /*
+ * Set the first page to be the unmapped guard page.
+ */
+ ptek = vtopte(ks);
oldpte = *ptek;
*ptek = 0;
if (oldpte) {
#ifdef I386_CPU
updateneeded = 1;
#else
- invlpg(ks - PAGE_SIZE);
+ invlpg(ks);
#endif
}
+
+ /*
+ * move to the next page, which is where the real stack starts.
+ */
+ ks += PAGE_SIZE;
+ td->td_kstack = ks;
ptek++;
#else
/* get a kernel virtual address for the kstack for this thread */
@@ -1038,6 +1044,10 @@ pmap_new_thread(struct thread *td)
td->td_kstack = ks;
ptek = vtopte(ks);
#endif
+ /*
+ * For the length of the stack, link in a real page of ram for each
+ * page of stack.
+ */
for (i = 0; i < KSTACK_PAGES; i++) {
/*
* Get a kernel stack page
@@ -1050,16 +1060,16 @@ pmap_new_thread(struct thread *td)
m->wire_count++;
cnt.v_wire_count++;
- oldpte = *(ptek + i);
/*
* Enter the page into the kernel address space.
*/
- *(ptek + i) = VM_PAGE_TO_PHYS(m) | PG_RW | PG_V | pgeflag;
+ oldpte = ptek[i];
+ ptek[i] = VM_PAGE_TO_PHYS(m) | PG_RW | PG_V | pgeflag;
if (oldpte) {
#ifdef I386_CPU
updateneeded = 1;
#else
- invlpg(ks + i * PAGE_SIZE);
+ invlpg(ks + (i * PAGE_SIZE));
#endif
}
OpenPOWER on IntegriCloud