Skip to content

Commit

Permalink
split out tracks to individual object files
Browse files Browse the repository at this point in the history
In order to reduce the memory requirements for building the
kernel module, build each track into an object file individually.

For this purpose, each "track object" exports the data array and its
length explicitly, which can then be used from netcat_main.c.

Signed-off-by: Philipp A. Hartmann <pah@qo.cx>
  • Loading branch information
pah committed Apr 24, 2014
1 parent f5c7d94 commit 1839efa
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 30 deletions.
6 changes: 6 additions & 0 deletions Makefile
@@ -1,5 +1,11 @@
obj-m += netcat.o
netcat-y = netcat_main.o
netcat-y+= tracks/trk1.o
netcat-y+= tracks/trk2.o
netcat-y+= tracks/trk3.o
netcat-y+= tracks/trk4.o
netcat-y+= tracks/trk5.o
netcat-y+= tracks/trk6.o

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
Expand Down
46 changes: 22 additions & 24 deletions netcat_main.c
Expand Up @@ -7,22 +7,6 @@
#include <linux/miscdevice.h>
#include <linux/slab.h>

/* Brandon's compiler crashes unless we include them in
* this order.
*
* __ __
* _/ |_ ____ ____ _____ _____/ |_
* \ __\/ __ \ / \\__ \ _/ ___\ __\
* | | \ ___/| | \/ __ \\ \___| |
* |__| \___ >___| (____ /\___ >__|
* \/ \/ \/ \/
*/
#include "tracks/trk4.c"
#include "tracks/trk5.c"
#include "tracks/trk6.c"
#include "tracks/trk1.c"
#include "tracks/trk2.c"
#include "tracks/trk3.c"

#define DEVICE_NAME "netcat" /* Dev name as it appears in /proc/devices */

Expand All @@ -32,6 +16,20 @@ struct netcat {
int current_track;
};

extern char netcat_cpi_trk1[];
extern char netcat_cpi_trk2[];
extern char netcat_cpi_trk3[];
extern char netcat_cpi_trk4[];
extern char netcat_cpi_trk5[];
extern char netcat_cpi_trk6[];

extern unsigned long netcat_cpi_trk1_len;
extern unsigned long netcat_cpi_trk2_len;
extern unsigned long netcat_cpi_trk3_len;
extern unsigned long netcat_cpi_trk4_len;
extern unsigned long netcat_cpi_trk5_len;
extern unsigned long netcat_cpi_trk6_len;

static char *tracks[] = {netcat_cpi_trk1,
netcat_cpi_trk2,
netcat_cpi_trk3,
Expand All @@ -46,12 +44,12 @@ static char *tracknames[] = {"Interrupt 0x7f",
"Interrupt 0xbb",
"Approximating the Circumference of the Earth"};

static unsigned long tracklens[] = {NETCAT_CPI_TRK1_LEN,
NETCAT_CPI_TRK2_LEN,
NETCAT_CPI_TRK3_LEN,
NETCAT_CPI_TRK4_LEN,
NETCAT_CPI_TRK5_LEN,
NETCAT_CPI_TRK6_LEN};
static unsigned long *tracklens[] = {&netcat_cpi_trk1_len,
&netcat_cpi_trk2_len,
&netcat_cpi_trk3_len,
&netcat_cpi_trk4_len,
&netcat_cpi_trk5_len,
&netcat_cpi_trk6_len};


static int device_open(struct inode *inode, struct file *file)
Expand Down Expand Up @@ -92,7 +90,7 @@ static ssize_t device_read(struct file *file,
netcat->first_time = false;
}

if (netcat->msg - tracks[current_track] >= tracklens[current_track]) {
if (netcat->msg - tracks[current_track] >= *tracklens[current_track]) {
/* End of Track. Skip to next track, or finish if it's track 6 */
current_track++;
if (current_track >= 6)
Expand All @@ -105,7 +103,7 @@ static ssize_t device_read(struct file *file,

while (length &&
(netcat->msg - tracks[current_track]) <
tracklens[current_track]) {
*tracklens[current_track]) {
put_user(*(netcat->msg++), buffer++);

length--;
Expand Down
3 changes: 2 additions & 1 deletion tracks/trk1.c
@@ -1,6 +1,7 @@
#define NETCAT_CPI_TRK1_LEN 624344
static char netcat_cpi_trk1[] = {
char netcat_cpi_trk1[] = {

#include "trk1data.h"

};
unsigned long netcat_cpi_trk1_len = NETCAT_CPI_TRK1_LEN;
3 changes: 2 additions & 1 deletion tracks/trk2.c
@@ -1,6 +1,7 @@
#define NETCAT_CPI_TRK2_LEN 11659615
static char netcat_cpi_trk2[] = {
char netcat_cpi_trk2[] = {

#include "trk2data.h"

};
unsigned long netcat_cpi_trk2_len = NETCAT_CPI_TRK2_LEN;
3 changes: 2 additions & 1 deletion tracks/trk3.c
@@ -1,6 +1,7 @@
#define NETCAT_CPI_TRK3_LEN 829971
static char netcat_cpi_trk3[] = {
char netcat_cpi_trk3[] = {

#include "trk3data.h"

};
unsigned long netcat_cpi_trk3_len = NETCAT_CPI_TRK3_LEN;
3 changes: 2 additions & 1 deletion tracks/trk4.c
@@ -1,6 +1,7 @@
#define NETCAT_CPI_TRK4_LEN 10788741
static char netcat_cpi_trk4[] = {
char netcat_cpi_trk4[] = {

#include "trk4data.h"

};
unsigned long netcat_cpi_trk4_len = NETCAT_CPI_TRK4_LEN;
3 changes: 2 additions & 1 deletion tracks/trk5.c
@@ -1,6 +1,7 @@
#define NETCAT_CPI_TRK5_LEN 858054
static char netcat_cpi_trk5[] = {
char netcat_cpi_trk5[] = {

#include "trk5data.h"

};
unsigned long netcat_cpi_trk5_len = NETCAT_CPI_TRK5_LEN;
3 changes: 2 additions & 1 deletion tracks/trk6.c
@@ -1,6 +1,7 @@
#define NETCAT_CPI_TRK6_LEN 13025371
static char netcat_cpi_trk6[] = {
char netcat_cpi_trk6[] = {

#include "trk6data.h"

};
unsigned long netcat_cpi_trk6_len = NETCAT_CPI_TRK6_LEN;

0 comments on commit 1839efa

Please sign in to comment.