Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FlightOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Armin Luntzer
FlightOS
Commits
3a799dca
Commit
3a799dca
authored
Dec 15, 2016
by
Armin Luntzer
Browse files
Options
Downloads
Patches
Plain Diff
add missing samples/mm
parent
d02c340a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
samples/mm/.gitignore
+1
-0
1 addition, 0 deletions
samples/mm/.gitignore
samples/mm/Makefile
+28
-0
28 additions, 0 deletions
samples/mm/Makefile
samples/mm/mm_demo.c
+102
-0
102 additions, 0 deletions
samples/mm/mm_demo.c
with
131 additions
and
0 deletions
samples/mm/.gitignore
0 → 100644
+
1
−
0
View file @
3a799dca
mm_demo
This diff is collapsed.
Click to expand it.
samples/mm/Makefile
0 → 100644
+
28
−
0
View file @
3a799dca
# kbuild trick to avoid linker error. Can be omitted if a module is built.
obj-
:=
dummy.o
hostprogs-$(CONFIG_SAMPLE_MM)
:=
mm_demo
# I guess I'm too stupid to figure out the proper way to do this
# (but maybe there is none)
ifdef
CROSS_COMPILE
HOSTCC
:=
$(
CROSS_COMPILE
)
gcc
HOSTLD
:=
$(
CROSS_COMPILE
)
ld
endif
HOSTCFLAGS_mm_demo.o
+=
-I
$(
objtree
)
/include
mm_demo-objs
:=
mm_demo.o
ifndef
CROSS_COMPILE
EXTRAPFLAG
=
-m32
else
EXTRAPFLAG
=
endif
HOSTCFLAGS_mm_demo.o
+=
$(
EXTRAFLAG
)
HOSTLOADLIBES_mm_demo
+=
$(
EXTRAFLAG
)
$(
objtree
)
/lib/lib.a
HOSTLOADLIBES_mm_demo
+=
$(
objtree
)
/kernel/built-in.o
always
:=
$(
hostprogs-y
)
This diff is collapsed.
Click to expand it.
samples/mm/mm_demo.c
0 → 100644
+
102
−
0
View file @
3a799dca
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdint.h>
#include
<string.h>
#include
<kernel/mm.h>
#include
<kernel/printk.h>
#include
<kernel/bitmap.h>
/* pool size (2^n) and granularity (same)*/
#define MM_BLOCK_ORDER_MAX 17
#define MM_BLOCK_ORDER_MIN 8
/* block size to allocate (must be at least 2^MM_BLOCK_ORDER_MIN) */
#define ALLOC_BYTES (1UL << MM_BLOCK_ORDER_MIN)
/* how many blocks to allocate in a loop */
#define TRY_BLOCKS 27
/* nothing to do here */
#define MM_NUM_BLOCKS MM_NUM_BLOCKS_TRACKABLE(MM_BLOCK_ORDER_MAX,\
MM_BLOCK_ORDER_MIN)
#define MM_LEN_BITMAP MM_BITMAP_LEN(MM_BLOCK_ORDER_MAX,\
MM_BLOCK_ORDER_MIN)
#define POOL_SIZE (1UL << MM_BLOCK_ORDER_MAX)
#define BLOCK_GRANULARITY (1UL << MM_BLOCK_ORDER_MIN)
unsigned
char
mm_init_alloc_order
[
MM_NUM_BLOCKS
];
unsigned
long
mm_init_bitmap
[
MM_LEN_BITMAP
];
struct
list_head
mm_init_block_order
[
MM_BLOCK_ORDER_MAX
+
1
];
int
main
(
void
)
{
int
j
;
void
*
pool
;
struct
mm_pool
mp
;
unsigned
long
i
[
TRY_BLOCKS
];
pool
=
malloc
(
POOL_SIZE
);
if
(
!
pool
)
return
0
;
/* mm_init() expects these to be all set */
mp
.
block_order
=
&
mm_init_block_order
[
0
];
mp
.
alloc_order
=
&
mm_init_alloc_order
[
0
];
mp
.
blk_free
=
&
mm_init_bitmap
[
0
];
if
(
mm_init
(
&
mp
,
pool
,
POOL_SIZE
,
BLOCK_GRANULARITY
))
{
printk
(
"Error initialising the memory manager
\n
"
);
return
-
1
;
}
mm_dump_stats
(
&
mp
);
printf
(
"---{ALLOCATING BLOCKS}---
\n
"
);
for
(
j
=
0
;
j
<
TRY_BLOCKS
;
j
++
)
{
i
[
j
]
=
(
unsigned
long
)
mm_alloc
(
&
mp
,
ALLOC_BYTES
);
bitmap_print
(
mm_init_bitmap
,
mp
.
n_blks
);
}
mm_dump_stats
(
&
mp
);
printf
(
"---{FREEING BLOCKS}---
\n
"
);
for
(
j
=
(
TRY_BLOCKS
-
1
);
j
>=
0
;
j
--
)
{
mm_free
(
&
mp
,
(
void
*
)
i
[
j
]);
bitmap_print
(
mm_init_bitmap
,
mp
.
n_blks
);
}
mm_dump_stats
(
&
mp
);
printf
(
"---{NULL FREE}---
\n
"
);
printf
(
"(valid, should give no response)
\n
"
);
mm_free
(
&
mp
,
NULL
);
printf
(
"---{DOUBLE FREE}---
\n
"
);
mm_free
(
&
mp
,
(
void
*
)
i
[
0
]);
printf
(
"---{INVALID FREE}---
\n
"
);
mm_free
(
&
mp
,
(
void
*
)
0xb19b00b5
);
mm_exit
(
&
mp
);
free
(
pool
);
return
0
;
}
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