Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
chickadee
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Elon Bontemps
chickadee
Commits
d57d38c5
Commit
d57d38c5
authored
Feb 08, 2018
by
Eddie Kohler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add p-allocexit program.
parent
0574b673
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
2 deletions
+58
-2
GNUmakefile
GNUmakefile
+4
-2
p-allocexit.cc
p-allocexit.cc
+54
-0
No files found.
GNUmakefile
View file @
d57d38c5
...
...
@@ -49,9 +49,11 @@ KERNEL_OBJS = $(OBJDIR)/k-exception.ko \
$(OBJDIR)
/k-memviewer.ko
$(OBJDIR)
/lib.ko
PROCESS_LIB_OBJS
=
$(OBJDIR)
/lib.o
$(OBJDIR)
/p-lib.o
PROCESS_OBJS
=
$(OBJDIR)
/p-allocator.o
$(PROCESS_LIB_OBJS)
PROCESS_OBJS
=
$(PROCESS_LIB_OBJS)
\
$(OBJDIR)
/p-allocator.o
\
$(OBJDIR)
/p-allocexit.o
FLATFS_CONTENTS
=
obj/p-allocator
FLATFS_CONTENTS
=
obj/p-allocator
obj/p-allocexit
# How to make object files
...
...
p-allocexit.cc
0 → 100644
View file @
d57d38c5
#include "p-lib.hh"
#define ALLOC_SLOWDOWN 100
extern
uint8_t
end
[];
uint8_t
*
heap_top
;
uint8_t
*
stack_bottom
;
void
process_main
(
void
)
{
// Process 1 never allocates; it alternates between forking children
// and yielding. Each forked child allocates.
while
(
1
)
{
if
(
rand
(
0
,
ALLOC_SLOWDOWN
-
1
)
==
0
)
{
if
(
sys_fork
()
==
0
)
{
break
;
}
}
else
{
sys_yield
();
}
}
pid_t
p
=
sys_getpid
();
srand
(
p
);
// The heap starts on the page right after the 'end' symbol,
// whose address is the first address not allocated to process code
// or data.
heap_top
=
ROUNDUP
((
uint8_t
*
)
end
,
PAGESIZE
);
// The bottom of the stack is the first address on the current
// stack page (this process never needs more than one stack page).
stack_bottom
=
ROUNDDOWN
((
uint8_t
*
)
read_rsp
()
-
1
,
PAGESIZE
);
// Allocate heap pages until (1) hit the stack (out of address space)
// or (2) allocation fails (out of physical memory).
while
(
1
)
{
int
x
=
rand
(
0
,
8
*
ALLOC_SLOWDOWN
-
1
);
if
(
x
<
8
*
p
&&
heap_top
!=
stack_bottom
)
{
if
(
sys_page_alloc
(
heap_top
)
>=
0
)
{
*
heap_top
=
p
;
// check we have write access to new page
heap_top
+=
PAGESIZE
;
}
}
else
if
(
x
==
8
*
p
)
{
if
(
sys_fork
()
==
0
)
{
p
=
sys_getpid
();
}
}
else
if
(
x
==
8
*
p
+
1
||
(
x
<
p
&&
heap_top
==
stack_bottom
))
{
sys_exit
(
0
);
}
else
{
sys_yield
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment