Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSEP551
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Krishna Vinnakota
CSEP551
Commits
81d52199
Commit
81d52199
authored
18 years ago
by
kaashoek
Browse files
Options
Downloads
Patches
Plain Diff
bug in sbrk
test malloc
parent
bcfb84b6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
proc.c
+2
-3
2 additions, 3 deletions
proc.c
umalloc.c
+7
-1
7 additions, 1 deletion
umalloc.c
user.h
+1
-1
1 addition, 1 deletion
user.h
usertests.c
+39
-3
39 additions, 3 deletions
usertests.c
with
49 additions
and
8 deletions
proc.c
+
2
−
3
View file @
81d52199
...
...
@@ -151,10 +151,9 @@ growproc(int n)
oldmem
=
cp
->
mem
;
cp
->
mem
=
newmem
;
kfree
(
oldmem
,
cp
->
sz
);
cprintf
(
"growproc: added %d bytes to %d bytes
\n
"
,
n
,
cp
->
sz
);
cp
->
sz
+=
n
;
cprintf
(
"growproc: added %d bytes starting at address 0x%x
\n
"
,
n
,
newmem
+
cp
->
sz
-
n
);
return
newmem
+
cp
->
sz
-
n
;
return
cp
->
sz
-
n
;
}
// Per-CPU process scheduler.
...
...
This diff is collapsed.
Click to expand it.
umalloc.c
+
7
−
1
View file @
81d52199
...
...
@@ -25,7 +25,9 @@ void
free
(
void
*
ap
)
{
Header
*
bp
,
*
p
;
printf
(
1
,
"free
\n
"
);
bp
=
(
Header
*
)
ap
-
1
;
for
(
p
=
freep
;
!
(
bp
>
p
&&
bp
<
p
->
s
.
ptr
);
p
=
p
->
s
.
ptr
)
if
(
p
>=
p
->
s
.
ptr
&&
(
bp
>
p
||
bp
<
p
->
s
.
ptr
))
...
...
@@ -51,6 +53,7 @@ morecore(uint nu)
if
(
nu
<
PAGE
)
nu
=
PAGE
;
printf
(
1
,
"call sbrk
\n
"
);
cp
=
sbrk
(
nu
*
sizeof
(
Header
));
if
(
cp
==
(
char
*
)
-
1
)
return
0
;
...
...
@@ -66,6 +69,8 @@ malloc(uint nbytes)
Header
*
p
,
*
prevp
;
uint
nunits
;
printf
(
1
,
"malloc %d
\n
"
,
nbytes
);
nunits
=
(
nbytes
+
sizeof
(
Header
)
-
1
)
/
sizeof
(
Header
)
+
1
;
if
((
prevp
=
freep
)
==
0
)
{
base
.
s
.
ptr
=
freep
=
prevp
=
&
base
;
...
...
@@ -81,6 +86,7 @@ malloc(uint nbytes)
p
->
s
.
size
=
nunits
;
}
freep
=
prevp
;
printf
(
1
,
"malloc returns: %d
\n
"
,
(
int
)
(
p
+
1
));
return
(
void
*
)
(
p
+
1
);
}
if
(
p
==
freep
)
...
...
This diff is collapsed.
Click to expand it.
user.h
+
1
−
1
View file @
81d52199
...
...
@@ -30,5 +30,5 @@ void printf(int fd, char *fmt, ...);
char
*
gets
(
char
*
,
int
max
);
unsigned
int
strlen
(
char
*
);
void
*
memset
(
void
*
dst
,
int
c
,
unsigned
int
n
);
void
*
mall
i
c
(
uint
);
void
*
mall
o
c
(
uint
);
void
free
(
void
*
);
This diff is collapsed.
Click to expand it.
usertests.c
+
39
−
3
View file @
81d52199
...
...
@@ -117,14 +117,50 @@ exitwait(void)
puts
(
"exitwait ok
\n
"
);
}
void
mem
(
void
)
{
void
*
m
=
malloc
(
4096
);
void
*
m1
,
*
m2
;
free
(
m
+
3
*
1024
);
free
(
m
+
2
*
1024
);
free
(
m
+
1024
);
free
(
m
);
m1
=
malloc
(
4096
);
if
(
m1
!=
m
)
{
puts
(
"didn't coalesce
\n
"
);
exit
();
}
free
(
m1
);
m1
=
0
;
while
((
m2
=
malloc
(
1024
))
!=
0
)
{
*
(
char
**
)
m2
=
m1
;
m1
=
m2
;
}
while
(
m1
)
{
m2
=
*
(
char
**
)
m1
;
free
(
m1
);
m1
=
m2
;
}
m1
=
malloc
(
1024
*
20
);
if
(
m1
==
0
)
{
puts
(
"couldn't allocate mem?!!
\n
"
);
exit
();
}
free
(
m1
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
puts
(
"usertests starting
\n
"
);
pipe1
();
preempt
();
exitwait
();
// pipe1();
// preempt();
// exitwait();
mem
();
puts
(
"usertests finished
\n
"
);
exit
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment