Skip to content

Commit c19a508

Browse files
veltzerMark Veltzer
authored andcommitted
made kcpp work for new ubuntu
1 parent e5cdfc8 commit c19a508

File tree

9 files changed

+105
-10
lines changed

9 files changed

+105
-10
lines changed

Makefile

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# parameters #
33
##############
44

5+
# fill in the name of the module
6+
name:=kcpp
57
# fill in the object files which are part of the module
6-
obj-m:=kcpp.o
7-
kcpp-objs:=top.o ser_mem.o ser_print.o
8+
obj-m:=$(name).o
9+
$(name)-objs:=top.o ser_mem.o ser_print.o ser_empty.o
810
# fill in any extra compiler flags
911
EXTRA_CFLAGS+=-Werror -I.
10-
# fill in the name of the module
11-
name:=kcpp
1212
# fill in the name of the genrated ko file
1313
ko-m:=$(name).ko
1414
# fill in the version of the kernel for which you want the module compiled to
@@ -41,21 +41,26 @@ C_OBJECTS:=$(addsuffix .o,$(basename $(C_SOURCES)))
4141

4242
# this rule was also taken from running with V=1
4343
$(ko-m): top.o top.mod.o $(CC_OBJECTS) checkpatch
44-
$(Q)ld -r -m elf_i386 --build-id -o $(ko-m) $(C_OBJECTS) kcpp.mod.o $(CC_OBJECTS)
44+
$(info doing [$@])
45+
$(Q)ld -r -m elf_i386 --build-id -o $(ko-m) $(C_OBJECTS) $(name).mod.o $(CC_OBJECTS)
4546
# how was this monstrosity created?
4647
# I ran the build with V=1 and registered the command to compile via gcc.
4748
# picked the same version g++ and gave it the entire flag set (especially the -f stuff).
4849
# removed all -D, preprocessor and
4950
# -ffreestanding -Wno-pointer-sign -Wdeclaration-after-statement
5051
# -Werror-implicit-function-declaration -Wstrict-prototypes
5152
# which are not relevant to C++ (the compiler told me so!)
53+
# trying to add -fno-exceptions
5254
%.o: %.cc
53-
$(Q)g++ -nostdinc -Wall -Wundef -Wno-trigraphs -fno-strict-aliasing -fno-common -Os -fno-stack-protector -m32 -msoft-float -mregparm=3 -freg-struct-return -mpreferred-stack-boundary=2 -march=i686 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -fomit-frame-pointer -Werror -c -o $@ $<
55+
$(info doing [$@])
56+
$(Q)g++ -nostdinc -Wall -Wundef -Wno-trigraphs -fno-strict-aliasing -fno-common -fno-delete-null-pointer-checks -O2 -m32 -msoft-float -mregparm=3 -freg-struct-return -fno-pic -mpreferred-stack-boundary=2 -march=i686 -mtune=generic -maccumulate-outgoing-args -Wa,-mtune=generic32 -ffreestanding -fstack-protector -pipe -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-strict-overflow -fconserve-stack -fno-exceptions -Werror -c -o $@ $<
5457
top.o top.mod.o: top.c
58+
$(info doing [$@])
5559
$(Q)$(MAKE) -C $(KDIR) M=$(CURDIR) V=$(V) modules
5660
$(Q)-rm -f top.ko
5761
.PHONY: modules
5862
modules:
63+
$(info doing [$@])
5964
$(Q)$(MAKE) -C $(KDIR) M=$(CURDIR) V=$(V) modules
6065
.PHONY: modules_install
6166
modules_install:
@@ -65,36 +70,47 @@ clean:
6570
$(Q)$(MAKE) -C $(KDIR) M=$(CURDIR) V=$(V) clean
6671
.PHONY: help
6772
help:
73+
$(info doing [$@])
6874
$(Q)$(MAKE) -C $(KDIR) M=$(CURDIR) V=$(V) help
6975
.PHONY: insmod
7076
insmod:
77+
$(info doing [$@])
7178
$(Q)sudo insmod $(ko-m)
7279
.PHONY: lsmod
7380
lsmod:
81+
$(info doing [$@])
7482
$(Q)sudo lsmod | grep $(name)
7583
.PHONY: rmmod
7684
rmmod:
85+
$(info doing [$@])
7786
$(Q)sudo rmmod $(name)
7887
.PHONY: modinfo
7988
modinfo:
89+
$(info doing [$@])
8090
$(Q)sudo modinfo $(ko-m)
8191
.PHONY: last
8292
last:
93+
$(info doing [$@])
8394
$(Q)sudo tail /var/log/kern.log
8495
.PHONY: log
8596
log:
97+
$(info doing [$@])
8698
$(Q)sudo tail -f /var/log/kern.log
8799
.PHONY: cleanlog
88100
cleanlog:
101+
$(info doing [$@])
89102
$(Q)sudo dmesg -c > /dev/null
90103
.PHONY: halt
91104
halt:
105+
$(info doing [$@])
92106
$(Q)sudo halt
93107
.PHONY: reboot
94108
reboot:
109+
$(info doing [$@])
95110
$(Q)sudo reboot
96111
.PHONY: tips
97112
tips:
113+
$(info doing [$@])
98114
$(Q)echo "do make V=1 [target] to see more of what is going on"
99115
$(Q)echo
100116
$(Q)echo "in order for the operational targets to work you need to"
@@ -108,6 +124,9 @@ tips:
108124
$(Q)echo "or edit the file and permanently change the version"
109125
.PHONY: debug
110126
debug:
127+
$(info doing [$@])
128+
$(info name is $(name))
129+
$(info ko-m is $(ko-m))
111130
$(info V is $(V))
112131
$(info CURDIR is $(CURDIR))
113132
$(info KVER is $(KVER))
@@ -123,3 +142,7 @@ checkpatch:
123142
$(Q)scripts/wrapper.py ~/install/linux-3.6.3/scripts/checkpatch.pl --file top.c --root ~/install/linux-3.6.3
124143
$(Q)scripts/wrapper.py ~/install/linux-3.6.3/scripts/checkpatch.pl --file ser_mem.c --root ~/install/linux-3.6.3
125144
$(Q)scripts/wrapper.py ~/install/linux-3.6.3/scripts/checkpatch.pl --file ser_print.c --root ~/install/linux-3.6.3
145+
test_stress_insmod_rmmod: $(ko-m)
146+
$(info doing [$@])
147+
-sudo rmmod $(name)
148+
./scripts/test_stress_insmod_rmmod.pl $(ko-m) 1000

cpp_support.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include "services.h"
22

33
/* to satisfy the kernel dynamic linker */
4-
int __gxx_personality_v0;
5-
int _Unwind_Resume;
4+
//int __gxx_personality_v0;
5+
//int _Unwind_Resume;
6+
//int _GLOBAL_OFFSET_TABLE_;
67

78
/* support code for new and delete */
89
void *operator new(unsigned int x) {

doc/flags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fno-delete-null-pointer-checks -O2 -m32 -msoft-float -mregparm=3 -freg-struct-return -fno-pic -mpreferred-stack-boundary=2 -march=i686 -mtune=generic -maccumulate-outgoing-args -Wa,-mtune=generic32 -ffreestanding -fstack-protector -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -Wframe-larger-than=1024 -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -pg -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -DCC_HAVE_ASM_GOTO -Werror -I. -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(top)" -D"KBUILD_MODNAME=KBUILD_STR(kcpp)" -c -o /home/mark/git/branches/kcpp/.tmp_top.o /home/mark/git/branches/kcpp/top.c

driver.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ extern "C" {
1717
int cpp_init(void);
1818
void cpp_exit(void);
1919
}
20+
21+
void test_kmalloc(void) {
22+
void* p = service_malloc(1000);
23+
service_free(p);
24+
}
25+
2026
int cpp_init() {
27+
test_kmalloc();
28+
2129
driver = new Driver();
2230

2331
return(0);

kernel_helper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ static const char myname[]=MYNAME;
2020
#define WARNING(fmt,args...) printk(KERN_WARNING "WARNING: %s %s %s %d: " fmt "\n",myname,__BASE_FILE__,__FUNCTION__,__LINE__,## args);
2121

2222
// errors are always shown as KERN_ERR; ERROR does not do a BUG()
23-
#define ERROR(fmt,args...) printk(KERN_ERR "ERROR: %s %s %s %d: " fmt "\n",myname,__BASE_FILE__,__FUNCTION__,__LINE__,## args); BUG();
23+
#define ERROR(fmt,args...) do { printk(KERN_ERR "ERROR: %s %s %s %d: " fmt "\n",myname,__BASE_FILE__,__FUNCTION__,__LINE__,## args); BUG(); } while(0)
2424

2525
// fatals are always shown as KERN_ERR; FATAL also does a BUG()
26-
#define FATAL(fmt,args...) printk(KERN_ERR "FATAL: %s %s %s %d: " fmt "\n",myname,__BASE_FILE__,__FUNCTION__,__LINE__,## args); BUG();
26+
#define FATAL(fmt,args...) do { printk(KERN_ERR "FATAL: %s %s %s %d: " fmt "\n",myname,__BASE_FILE__,__FUNCTION__,__LINE__,## args); BUG(); } while(0)
2727

2828
// prints are always show as KERN_INFO
2929
#define PRINT(fmt,args...) printk(KERN_INFO "PRINT: %s %s %s %d: " fmt "\n",myname,__BASE_FILE__,__FUNCTION__,__LINE__,## args);

scripts/test_stress_insmod_rmmod.pl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/perl -w
2+
3+
# this is a stress testing script which runs many insmod/rmmod combinations
4+
# to check that there are no problems in loading/unloading the driver...
5+
# Mark Veltzer
6+
7+
use strict;
8+
use diagnostics;
9+
10+
my($module)=$ARGV[0];
11+
my($count)=$ARGV[1];
12+
print "module is [$module]\n";
13+
print "count is [$count]\n";
14+
15+
sub my_system($) {
16+
my($cmd)=$_[0];
17+
print "doing [$cmd]\n";
18+
my($res)=system($cmd);
19+
if($res!=0) {
20+
die("failed to do cmd [$cmd] with result [$res]");
21+
}
22+
#print "res is [$res]\n";
23+
}
24+
25+
for(my($i)=0;$i<$count;$i++) {
26+
my_system("sudo insmod $module");
27+
my_system("sudo rmmod $module");
28+
}

ser_empty.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <linux/kernel.h>
2+
#include <linux/module.h>
3+
#include <linux/pci.h>
4+
#include <linux/init.h>
5+
#include <linux/io.h>
6+
#include <linux/interrupt.h>
7+
#include <linux/cdev.h>
8+
#include <linux/uaccess.h>
9+
#include <linux/device.h>
10+
#include <linux/types.h>
11+
#include <linux/proc_fs.h>
12+
#include <linux/mm.h>
13+
#include <linux/timex.h>
14+
#include <linux/cpufreq.h>
15+
16+
#include "services.h"
17+
#include "kernel_helper.h"
18+
19+
void service_empty(void) {
20+
}

services.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ typedef void (*func_void_pvoid_pvoid_pvoid_pvoid)(void*,void*,void*,void*);
1414
extern "C" {
1515
#endif // __cplusplus
1616

17+
// empty class
18+
void service_empty(void);
19+
1720
// infrastructure calls
1821
void service_init(void);
1922
void service_finish(void);

top.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
#include <linux/module.h> /* for MODULE_* macros */
2+
#include <linux/slab.h> /* for kmalloc */
23
#include "connect.h"
34

5+
void *service_malloc2(unsigned int size)
6+
{
7+
void *p;
8+
p = kmalloc(size+1, GFP_KERNEL);
9+
return p;
10+
}
11+
412
static int __init link_init(void)
513
{
14+
char *p = kmalloc(1000, GFP_KERNEL);
15+
mb();
16+
kfree(p);
617
return cpp_init();
718
}
819

0 commit comments

Comments
 (0)