Cursul 10
10
Linux kernel library
Linux kernel library
WinVFS
WinVFS architecture
Generic Windows filesystem driver
Linux VFS and block device adaptation layer
Filesystem drivers (ported from Linux)
EXT2
VFAT
MINIX
PITIX
WinVFS generic driver
I/O Manager
User space
Kernel space
Proof of concept results
Overview of bits that got pulled in
bitops.h config.h errno.h fd.h init.h minix_fs.h msdos_fs.h quota.h
slab.h time.h blkdev.h ctype.h ext2_fs.h file.h ioctl.h minix_fs_i.h
msdos_fs_i.h quotaops.h smp_lock.h types.h blk.h ext2_fs_i.h
fs.h kdev_t.h minix_fs_sb.h msdos_fs_sb.h rwsem.h spinlock.h
wait.h byteorder dcache.h ext2_fs_sb.h fs_struct.h kernel.h
mm.h nls.h rwsem-spinlock.h stat.h capability.h dirent.h
fat_cvf.h highmem.h list.h module.h pagemap.h sched.h
stddef.h compiler.h dnotify.h fcntl.h highuid.h locks.h mount.h
posix_types.h semaphore.h string.h ./mm/page_alloc.c
./mm/kmem_cache.c ./mm/filemap.c ./fs/inode.c ./fs/file_table.c
./fs/attr.c ./fs/namespace.c ./fs/bad_inode.c ./fs/dcache.c
./fs/namei.c ./fs/buffer.c ./fs/readdir.c ./fs/open.c ./fs/super.c ./fs/block_dev.c
./fs/read_write.c ./fs/devices.c ./lib/vsprintf.c ./lib/string.c ./lib/ctype.c
Later developments & decline
LKL goals
LKL design decisions
Architecture
Interface layer
Linux kernel
Arch port layer
Linux
Windows
Mac OS X
Native Operations
Application
Native operations
Memory management
Thread support
Threads control – forking
Fork
Create new thread
Lock(Thread2)
Thread1
Thread2
Linux operation
Native operation
Running thread
Stopped thread
Threads control – context switch
Unlock(Thread2)
Lock(Thread1)
Thread1
Thread2
Context switch
Linux operation
Native operation
Stopped thread
Running thread
Drivers
Examples of drivers
Interrupts
Time management
Native operations summary
void (*print)(const char *str, int len);
long (*panic_blink)(long time);
void* (*sem_alloc)(int count);
void (*sem_free)(void *sem);
void (*sem_up)(void *sem);
void (*sem_down)(void *sem);
void* (*thread_create)(void (*f)(void*), void *arg);
void (*thread_exit)(void *thread);
void* (*thread_id)(void);
void* (*mem_alloc)(unsigned int);
void (*mem_free)(void *);
void (*timer)(unsigned long delta);
unsigned long long (*time)(void);
int (*init)(void);
void (*halt)(void);
Execution environments
Interface layer
Linux kernel
POSIX
NT
NTK
APR
Linux
Windows
Mac OS X
Application
Arch port layer
NTK: semaphore operations
static void* sem_alloc(int count)
{
KSEMAPHORE *sem=ExAllocatePool(PagedPool, sizeof(*sem));
if (!sem) return NULL;
KeInitializeSemaphore(sem, count, 100);
return sem;
}
static void sem_up(void *sem)
{
KeReleaseSemaphore((KSEMAPHORE*)sem, 0, 1, 0);
}
static void sem_down(void *sem)
{
KeWaitForSingleObject((KSEMAPHORE*)sem, Executive, KernelMode,
FALSE, NULL);
}
static void sem_free(void *sem)
{
ExFreePool(sem);
}
NTK: threads & mem operations
static void* thread_create(void (*fn)(void*), void *arg)
{
void *thread;
if (PsCreateSystemThread(&thread, THREAD_ALL_ACCESS, NULL,
NULL, NULL, (void DDKAPI (*)(void*))fn,
arg) != STATUS_SUCCESS)
return NULL;
return thread;
}
static void thread_exit(void *arg)
{
PsTerminateSystemThread(0);
}
static void* mem_alloc(unsigned int size)
{
return ExAllocatePool(NonPagedPool, size);
}
static void mem_free(void *data)
{
ExFreePool(data);
}
Timer complications
Interface layer
Interactions
Application
core
LKL API
Linux kernel
Linux drivers
Native drivers
Native operations
Environment
A
B
C
D
E
F
H
I
G
FTP server for Linux FS access
FTP client
FTP client
LKL
APR – LKL conversion layer
APR
Disc image
Disc
FTP protocol
Native filesystem
Windows driver for Linux FS
Other neat ideas
Conclusions
http://github.com/lkl