From ce8532d8277b9e464f6b0021b8c246c216c9f036 Mon Sep 17 00:00:00 2001 From: tavi Date: Wed, 2 Jan 2008 02:50:03 +0200 Subject: [PATCH] Update to latest LKL. --- .config | 206 +++++++++++++++++++++++++++++++++++ .gitignore | 8 ++ Makefile | 56 +++++----- disk.c | 36 ------- drivers/Makefile | 1 - drivers/console.c | 27 ----- drivers/disk.c | 108 ------------------- drivers/disk.h | 9 -- lklops.c | 246 ------------------------------------------ lklops.h | 10 -- lua_syscalls.c | 24 ++--- lua_syscalls.h | 1 + main.c | 113 ++++++++++--------- syscall_helpers.c | 38 ------- syscall_helpers.h | 10 -- syscalls.c | 270 ---------------------------------------------- syscalls.h | 39 ------- thread_wrapper.c | 93 ---------------- thread_wrapper.h | 19 ---- wapr_dirops.c | 19 ++-- wapr_fileops.c | 38 ++++--- wapr_fileops.h | 10 +- wapr_filestat.c | 31 +++--- wapr_user.c | 11 +- wapr_user.h | 5 +- 25 files changed, 364 insertions(+), 1064 deletions(-) create mode 100644 .config create mode 100644 .gitignore delete mode 100644 disk.c delete mode 100644 drivers/Makefile delete mode 100755 drivers/console.c delete mode 100644 drivers/disk.c delete mode 100644 drivers/disk.h delete mode 100644 lklops.c delete mode 100644 lklops.h delete mode 100644 syscall_helpers.c delete mode 100644 syscall_helpers.h delete mode 100644 syscalls.c delete mode 100644 syscalls.h delete mode 100644 thread_wrapper.c delete mode 100644 thread_wrapper.h diff --git a/.config b/.config new file mode 100644 index 0000000..edf62a4 --- /dev/null +++ b/.config @@ -0,0 +1,206 @@ +# +# Automatically generated make config: don't edit +# Linux kernel version: 2.6.22-rc7 +# Sat Dec 29 18:15:45 2007 +# +# CONFIG_ISA is not set +# CONFIG_ISAPNP is not set +# CONFIG_EISA is not set +# CONFIG_MCA is not set +# CONFIG_PCI is not set +# CONFIG_BLK_DEV_IO_TRACE is not set +CONFIG_RWSEM_GENERIC_SPINLOCK=y +# CONFIG_SMP is not set +# CONFIG_HIGHMEM is not set +CONFIG_SPLIT_PTLOCK_CPUS=0 +# CONFIG_MMU is not set +CONFIG_SEMAPHORE_SLEEPERS=y +CONFIG_GENERIC_TIME=y +CONFIG_GENERIC_FIND_NEXT_BIT=y +CONFIG_GENERIC_HWEIGHT=y +CONFIG_GENERIC_HARDIRQS=y +CONFIG_FLATMEM=y +CONFIG_FLAT_NODE_MEM_MAP=y +# CONFIG_SYSFS is not set +CONFIG_ZONE_DMA_FLAG=0x00 +# CONFIG_HAS_IOMEM is not set +# CONFIG_TINY_SHMEM is not set +# CONFIG_BLK_DEV_INITRD is not set +CONFIG_GENERIC_CLOCKEVENTS=y +CONFIG_NO_HZ=y +CONFIG_TICK_ONESHOT=y +CONFIG_LKL=y +# CONFIG_LKL_ENV_NONE is not set +# CONFIG_LKL_ENV_POSIX is not set +# CONFIG_LKL_ENV_NT is not set +# CONFIG_LKL_ENV_NTK is not set +CONFIG_LKL_ENV_APR=y +# CONFIG_LKL_ENV_LINUX is not set +CONFIG_LKL_DRV_DISK=y +CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" + +# +# Code maturity level options +# +# CONFIG_EXPERIMENTAL is not set +CONFIG_BROKEN_ON_SMP=y +CONFIG_INIT_ENV_ARG_LIMIT=32 + +# +# General setup +# +CONFIG_LOCALVERSION="" +# CONFIG_LOCALVERSION_AUTO is not set +# CONFIG_SYSVIPC is not set +# CONFIG_BSD_PROCESS_ACCT is not set +# CONFIG_UTS_NS is not set +# CONFIG_IKCONFIG is not set +CONFIG_LOG_BUF_SHIFT=14 +# CONFIG_SYSFS_DEPRECATED is not set +# CONFIG_RELAY is not set +CONFIG_SYSCTL=y +# CONFIG_EMBEDDED is not set +CONFIG_SYSCTL_SYSCALL=y +CONFIG_KALLSYMS=y +CONFIG_KALLSYMS_EXTRA_PASS=y +CONFIG_HOTPLUG=y +CONFIG_PRINTK=y +CONFIG_BUG=y +CONFIG_ELF_CORE=y +CONFIG_BASE_FULL=y +CONFIG_FUTEX=y +CONFIG_ANON_INODES=y +CONFIG_EPOLL=y +CONFIG_SIGNALFD=y +CONFIG_TIMERFD=y +CONFIG_EVENTFD=y +CONFIG_VM_EVENT_COUNTERS=y +CONFIG_SLAB=y +# CONFIG_SLUB is not set +# CONFIG_SLOB is not set +CONFIG_RT_MUTEXES=y +CONFIG_BASE_SMALL=0 + +# +# Loadable module support +# +# CONFIG_MODULES is not set + +# +# Block layer +# +CONFIG_BLOCK=y +# CONFIG_LBD is not set +# CONFIG_LSF is not set + +# +# IO Schedulers +# +CONFIG_IOSCHED_NOOP=y +# CONFIG_IOSCHED_AS is not set +# CONFIG_IOSCHED_DEADLINE is not set +# CONFIG_IOSCHED_CFQ is not set +# CONFIG_DEFAULT_AS is not set +# CONFIG_DEFAULT_DEADLINE is not set +# CONFIG_DEFAULT_CFQ is not set +CONFIG_DEFAULT_NOOP=y +CONFIG_DEFAULT_IOSCHED="noop" + +# +# Networking +# +# CONFIG_NET is not set + +# +# Generic Driver Options +# +CONFIG_STANDALONE=y +CONFIG_PREVENT_FIRMWARE_BUILD=y +# CONFIG_FW_LOADER is not set +# CONFIG_SYS_HYPERVISOR is not set + +# +# File systems +# +# CONFIG_EXT2_FS is not set +CONFIG_EXT3_FS=y +# CONFIG_EXT3_FS_XATTR is not set +CONFIG_JBD=y +# CONFIG_JBD_DEBUG is not set +# CONFIG_REISERFS_FS is not set +# CONFIG_JFS_FS is not set +# CONFIG_FS_POSIX_ACL is not set +# CONFIG_XFS_FS is not set +# CONFIG_MINIX_FS is not set +# CONFIG_ROMFS_FS is not set +# CONFIG_INOTIFY is not set +# CONFIG_QUOTA is not set +CONFIG_DNOTIFY=y +# CONFIG_AUTOFS_FS is not set +# CONFIG_AUTOFS4_FS is not set +# CONFIG_FUSE_FS is not set + +# +# CD-ROM/DVD Filesystems +# +# CONFIG_ISO9660_FS is not set +# CONFIG_UDF_FS is not set + +# +# DOS/FAT/NT Filesystems +# +# CONFIG_MSDOS_FS is not set +# CONFIG_VFAT_FS is not set +# CONFIG_NTFS_FS is not set + +# +# Pseudo filesystems +# +CONFIG_PROC_FS=y +CONFIG_PROC_SYSCTL=y +# CONFIG_TMPFS is not set +# CONFIG_HUGETLB_PAGE is not set +CONFIG_RAMFS=y + +# +# Miscellaneous filesystems +# +# CONFIG_HFSPLUS_FS is not set +# CONFIG_CRAMFS is not set +# CONFIG_VXFS_FS is not set +# CONFIG_HPFS_FS is not set +# CONFIG_QNX4FS_FS is not set +# CONFIG_SYSV_FS is not set +# CONFIG_UFS_FS is not set + +# +# Partition Types +# +# CONFIG_PARTITION_ADVANCED is not set +CONFIG_MSDOS_PARTITION=y + +# +# Native Language Support +# +# CONFIG_NLS is not set + +# +# Security options +# +# CONFIG_KEYS is not set + +# +# Cryptographic options +# +# CONFIG_CRYPTO is not set + +# +# Library routines +# +# CONFIG_CRC_CCITT is not set +# CONFIG_CRC16 is not set +# CONFIG_CRC_ITU_T is not set +# CONFIG_CRC32 is not set +# CONFIG_LIBCRC32C is not set +CONFIG_PLIST=y +CONFIG_HAS_DMA=y diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f6f8115 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*~ +*.o +include/ +disk +daemon.out +lkl +.deps +include diff --git a/Makefile b/Makefile index adc17b8..b6a4ad7 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ #uncoment the next 2 lines to get LKL's file APIs. This currently works on linux only .PHONY=clean -LKL_DEFINES+=-DLKL_FILE_APIS -LKL=lkl/vmlinux +LKL_DEFINES+=-DLKL_FILE_APIS -Iinclude +LKL=$(CROSS)lkl/vmlinux $(CROSS)lkl/env.a -APR_LIN_CFLAGS=`apr-config --includes --cppflags` +APR_LIN_CFLAGS=$(shell apr-config --includes --cppflags) APR_WIN_CFLAGS=-Iapr_win/include/ APR_LIN_LIB=-lapr-1 @@ -49,41 +49,35 @@ include/linux: -$(MKDIR) `dirname $@` ln -s $(LINUX)/include/linux include/linux -%.config: $(LINUX)/arch/lkl/defconfig - -mkdir `dirname $@` - cp $^ $@ - INC=include/asm include/asm-generic include/asm-i386 include/linux -lkl/vmlinux: lkl/.config drivers/*.c drivers/Makefile - cd $(LINUX) && \ - $(MAKE) O=$(HERE)/`dirname $@` ARCH=lkl \ - LKL_DRIVERS=$(HERE)/drivers \ - vmlinux +$(CROSS)lkl/.config: .config + mkdir -p $(CROSS)lkl && \ + cp $< $@ -lkl-nt/vmlinux: lkl-nt/.config +$(CROSS)lkl/vmlinux: $(CROSS)lkl/.config cd $(LINUX) && \ - $(MAKE) O=$(HERE)/`dirname $@` ARCH=lkl CROSS_COMPILE=i586-mingw32msvc- \ - LKL_DRIVERS=$(HERE)/drivers \ - vmlinux - -CFLAGS=-Wall -g -DFILE_DISK_MAJOR=42 $(LKL_DEFINES) $(CFLAGS_OS) + $(MAKE) O=$(HERE)/$(CROSS)lkl ARCH=lkl \ + CROSS_COMPILE=$(CROSS) \ + vmlinux -syscalls.o: syscalls.c $(INC) - $(CC) -c $(CFLAGS) -Iinclude $< +$(CROSS)lkl/env.a: $(CROSS)lkl/.config + cd $(LINUX) && \ + $(MAKE) O=$(HERE)/$(CROSS)lkl ARCH=lkl \ + CROSS_COMPILE=$(CROSS) \ + EXTRA_CFLAGS="$(CFLAGS_OS)" \ + env.a +CFLAGS=-Wall -g $(CFLAGS_OS) $(LKL_DEFINES) %.o: %.c $(INC) $(CC) -c $(CFLAGS) $< - -AOUT=$(OBJS) lkl/vmlinux -AEXE=$(OBJS) lkl-nt/vmlinux +AOUT=$(OBJS) $(LKL) +AEXE=$(OBJS) $(LKL) clean: - -rm -rf daemon.out daemon.exe include - -rm -rf *.o drivers/*.o drivers/built-in* - -rm -rf drivers/.*.cmd .deps/ *~ + -rm -rf daemon.out daemon.exe include *.o drivers/*.o drivers/built-in* drivers/.*.cmd .deps/ *~ clean-all: clean -rm -rf lkl lkl-nt @@ -91,11 +85,13 @@ clean-all: clean TAGS: etags *.c drivers/*.c -daemon.out: $(AOUT) $(INC) include/asm - $(CC) $(CFLAGS) $(AOUT) $(APR_LIN_LIB) $(LUA_LIN_LIB) -o $@ +daemon.out: $(AOUT) $(INC) + $(CC) $(AOUT) $(APR_LIN_LIB) $(LUA_LIN_LIB) -o $@ + +daemon.exe: CROSS=i586-mingw32msvc- -daemon.exe: $(AEXE) $(INC) - i586-mingw32msvc-gcc $(CFLAGS) $(AEXE) $(APR_WIN_LIB) $(LUA_WIN_LIB) -o $@ +daemon.exe: $(AEXE) $(INC) + $(CROSS)gcc $(AEXE) $(APR_WIN_LIB) $(LUA_WIN_LIB) -o $@ .deps/%.d: %.c mkdir -p .deps/$(dir $<) diff --git a/disk.c b/disk.c deleted file mode 100644 index 0532ec3..0000000 --- a/disk.c +++ /dev/null @@ -1,36 +0,0 @@ -#include - -#include "drivers/disk.h" - -unsigned long lkl_disk_get_sectors(void *file) -{ - apr_finfo_t finfo; - - - if (apr_file_info_get(&finfo, APR_FINFO_SIZE, (apr_file_t*)file) != APR_SUCCESS) - return 0; - - return finfo.size/512; -} - -int lkl_disk_do_rw(void *_file, unsigned long sector, unsigned long nsect, - char *buffer, int dir) -{ - apr_off_t offset=sector*512; - apr_size_t len=nsect*512; - apr_file_t *file=(apr_file_t*)_file; - apr_status_t status; - - if (apr_file_seek(file, APR_SET, &offset) != APR_SUCCESS) - return 0; - - if (dir) - status=apr_file_write_full(file, buffer, len, NULL); - else - status=apr_file_read_full(file, buffer, len, NULL); - - return (status == APR_SUCCESS); -} - - - diff --git a/drivers/Makefile b/drivers/Makefile deleted file mode 100644 index a9ccf4e..0000000 --- a/drivers/Makefile +++ /dev/null @@ -1 +0,0 @@ -obj-y := console.o disk.o diff --git a/drivers/console.c b/drivers/console.c deleted file mode 100755 index b532331..0000000 --- a/drivers/console.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include - -extern int write(int, const char*, unsigned); - -static void console_write(struct console *con, const char *str, unsigned len) -{ - write(1, str, len); -} - -static struct console console = { - .name = "stdio_console", - .write = console_write, - .flags = CON_PRINTBUFFER, - .index = -1, -}; - -static int __init console_init(void) -{ - register_console(&console); - return 0; -} - -late_initcall(console_init); - - diff --git a/drivers/disk.c b/drivers/disk.c deleted file mode 100644 index 4074982..0000000 --- a/drivers/disk.c +++ /dev/null @@ -1,108 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "disk.h" - -struct lkl_disk_dev { - void *file; - spinlock_t lock; /* For mutual exclusion */ - struct request_queue *queue; /* The device request queue */ - struct gendisk *gd; /* The gendisk structure */ -}; - -static void lkl_disk_request(request_queue_t *q) -{ - struct request *req; - - while ((req = elv_next_request(q)) != NULL) { - struct lkl_disk_dev *dev = req->rq_disk->private_data; - int status; - - if (! blk_fs_request(req)) { - printk (KERN_NOTICE "Skip non-fs request\n"); - end_request(req, 0); - continue; - } - - status=lkl_disk_do_rw(dev->file, req->sector, req->current_nr_sectors, - req->buffer, rq_data_dir(req)); - end_request(req, status); - } -} - -static int lkl_disk_open(struct inode *inode, struct file *filp) -{ - struct lkl_disk_dev *dev = inode->i_bdev->bd_disk->private_data; - - filp->private_data = dev; - return 0; -} - -static struct block_device_operations lkl_disk_ops = { - .owner = THIS_MODULE, - .open = lkl_disk_open, -}; - - -static int major; -static int which=0; - -int lkl_disk_add_disk(void *file, dev_t *devno) -{ - struct lkl_disk_dev *dev=kmalloc(sizeof(*dev), GFP_KERNEL); - unsigned long sectors; - - BUG_ON(dev == NULL); - - memset (dev, 0, sizeof(*dev)); - - dev->file=file; - BUG_ON(dev->file == NULL); - - spin_lock_init(&dev->lock); - - dev->queue = blk_init_queue(lkl_disk_request, &dev->lock); - BUG_ON(dev->queue == NULL); - - blk_queue_hardsect_size(dev->queue, 512); - dev->queue->queuedata = dev; - - dev->gd = alloc_disk(1); - BUG_ON(dev->gd == NULL); - - dev->gd->major = major; - dev->gd->first_minor = which++; - dev->gd->fops = &lkl_disk_ops; - dev->gd->queue = dev->queue; - dev->gd->private_data = dev; - snprintf (dev->gd->disk_name, 32, "lkl_disk_%d", dev->gd->first_minor); - if (!(sectors=lkl_disk_get_sectors(dev->file))) - return -1; - set_capacity(dev->gd, sectors); - - add_disk(dev->gd); - - printk("lkldisk: attached %s @ dev=%d:%d\n", dev->gd->disk_name, dev->gd->major, dev->gd->first_minor); - *devno=new_encode_dev(MKDEV(dev->gd->major, dev->gd->first_minor)); - - return 0; -} - -static int __init lkl_disk_init(void) -{ - major = register_blkdev(0, "fd"); - if (major < 0) { - printk(KERN_ERR "fd: unable to register_blkdev: %d\n", major); - return -EBUSY; - } - - return 0; -} - -late_initcall(lkl_disk_init); - diff --git a/drivers/disk.h b/drivers/disk.h deleted file mode 100644 index 4c1c33d..0000000 --- a/drivers/disk.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _FILE_DISK_H -#define _FILE_DISK_H - -int lkl_disk_do_rw(void *file, unsigned long sector, unsigned long nsect, - char *buffer, int dir); -unsigned long lkl_disk_get_sectors(void*); -int lkl_disk_add_disk(void *f, dev_t *devno); - -#endif diff --git a/lklops.c b/lklops.c deleted file mode 100644 index f873db0..0000000 --- a/lklops.c +++ /dev/null @@ -1,246 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "include/asm/callbacks.h" -#include "lklops.h" -#include "thread_wrapper.h" - - -volatile int shutting_down = 0; -static apr_pool_t *pool; - -struct apr_thread_wrapper_t; - -struct _thread_info { - apr_thread_wrapper_t *thread; - apr_thread_mutex_t *sched_mutex; - int dead; -}; - -struct kernel_thread_helper_arg { - int (*fn)(void*); - void *arg; - struct _thread_info *pti; -}; - -static int debug_thread_count=0; - -void* linux_thread_info_alloc(void) -{ - struct _thread_info *pti=malloc(sizeof(*pti)); - - assert(pti != NULL); - - apr_thread_mutex_create(&pti->sched_mutex, APR_THREAD_MUTEX_UNNESTED, pool); - apr_thread_mutex_lock(pti->sched_mutex); - pti->dead=0; - - return pti; -} - -void linux_context_switch(void *prev, void *next) -{ - struct _thread_info *_prev=(struct _thread_info*)prev; - struct _thread_info *_next=(struct _thread_info*)next; - - apr_thread_mutex_unlock(_next->sched_mutex); - apr_thread_mutex_lock(_prev->sched_mutex); - if (_prev->dead) { - apr_thread_wrapper_t *thread=_prev->thread; - apr_thread_mutex_destroy(_prev->sched_mutex); - free(_prev); - debug_thread_count--; - wrapper_apr_thread_exit(thread, 0); - } -} - -apr_thread_mutex_t *kth_mutex; - -void* APR_THREAD_FUNC kernel_thread_helper(apr_thread_t *thr, void *arg) -{ - struct kernel_thread_helper_arg *ktha=(struct kernel_thread_helper_arg*)arg; - int (*fn)(void*)=ktha->fn; - void *farg=ktha->arg; - struct _thread_info *pti=ktha->pti; - - apr_thread_mutex_unlock(kth_mutex); - apr_thread_mutex_lock(pti->sched_mutex); - return (void*)fn(farg); -} - -void linux_free_thread(void *arg) -{ - struct _thread_info *pti=(struct _thread_info*)arg; - pti->dead=1; - apr_thread_mutex_unlock(pti->sched_mutex); -} - -int linux_new_thread(int (*fn)(void*), void *arg, void *pti) -{ - struct kernel_thread_helper_arg ktha = { - .fn = fn, - .arg = arg, - .pti = (struct _thread_info*)pti - }; - int rc; - - debug_thread_count++; - rc = wrapper_apr_thread_create(&ktha.pti->thread, NULL, &kernel_thread_helper, &ktha, pool); - apr_thread_mutex_lock(kth_mutex); - return rc; -} - -typedef struct { - apr_thread_mutex_t *lock; - int count; - apr_thread_cond_t *cond; -} apr_sem_t; - -unsigned long long linux_time(void) -{ - return apr_time_now()*1000; -} - - -/* - * APR does not provide timers -- the reason for this ugly hack. - */ -static unsigned long long timer_exp; -static apr_file_t *events_pipe_in, *events_pipe_out; -static apr_pollset_t *pollset; - -void linux_timer(unsigned long delta) -{ - if (delta) - timer_exp=linux_time()+delta; - else - timer_exp=0; -} - -void linux_exit_idle(void) -{ - char c = 0; - apr_size_t n=1; - - apr_file_write(events_pipe_out, &c, &n); -} - -void linux_enter_idle(int halted) -{ - signed long long delta=timer_exp-linux_time(); - apr_int32_t num=0; - const apr_pollfd_t *descriptors; - - if (!timer_exp && !halted) - apr_pollset_poll(pollset, 0, &num, &descriptors); - else { - if (delta > 0 && !halted) { - apr_pollset_poll(pollset, delta/1000, &num, &descriptors); - } - } - - if (num > 0) { - char c; - apr_size_t n=1; - apr_file_read(events_pipe_in, &c, &n); - } - - if (timer_exp <= linux_time()) { - timer_exp=0; - linux_trigger_irq(TIMER_IRQ); - } -} - -long linux_panic_blink(long time) -{ - assert(0); - return 0; -} - -static void *_phys_mem; - -void linux_mem_init(unsigned long *phys_mem, unsigned long *phys_mem_size) -{ - *phys_mem_size=16*1024*1024; - *phys_mem=(unsigned long)malloc(*phys_mem_size); -} - -void linux_halt(void) -{ - free(_phys_mem); -} -static struct linux_native_operations lnops = { - .panic_blink = linux_panic_blink, - .mem_init = linux_mem_init, - .halt = linux_halt, - .thread_info_alloc = linux_thread_info_alloc, - .new_thread = linux_new_thread, - .free_thread = linux_free_thread, - .context_switch = linux_context_switch, - .enter_idle = linux_enter_idle, - .exit_idle = linux_exit_idle, - .time = linux_time, - .timer = linux_timer -}; - - - -void* APR_THREAD_FUNC init_thread(apr_thread_t *thr, void *arg) -{ - linux_start_kernel(&lnops, ""); - apr_thread_exit(thr, 0); - return NULL; -} -static apr_thread_t *init_thread_handle; -void lkl_init(int (*init_2)(void)) -{ - - lnops.init=init_2; - - apr_pool_create(&pool, NULL); - - - wrapper_apr_thread_init(pool); - apr_thread_mutex_create(&kth_mutex, APR_THREAD_MUTEX_UNNESTED, pool); - apr_thread_mutex_lock(kth_mutex); - - apr_pollset_create(&pollset, 1, pool, 0); - apr_file_pipe_create(&events_pipe_in, &events_pipe_out, pool); - apr_pollfd_t apfd = { - .p = pool, - .desc_type = APR_POLL_FILE, - .reqevents = APR_POLLIN, - .desc = { - .f = events_pipe_in - } - }; - apr_pollset_add(pollset, &apfd); - - apr_thread_create(&init_thread_handle, NULL, init_thread, NULL, pool); -} - -extern long wrapper_sys_halt(); -extern long wrapper_sys_sync(); -extern long wrapper_sys_umount(const char*, int); - - -void lkl_fini(unsigned int flag) -{ - apr_status_t rc; - shutting_down = 1; - if(0 == (flag & LKL_FINI_DONT_UMOUNT_ROOT)) - wrapper_sys_umount("/", 0); - wrapper_sys_halt(); - wrapper_apr_thread_join_all(); - apr_thread_join(&rc, init_thread_handle); -} diff --git a/lklops.h b/lklops.h deleted file mode 100644 index 4e553e2..0000000 --- a/lklops.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef LKLOPS_H__ -#define LKLOPS_H__ - -#define LKL_FINI_DONT_UMOUNT_ROOT 1 - -void lkl_init(int (*)(void)); -void lkl_fini(unsigned int flag); - -#endif - diff --git a/lua_syscalls.c b/lua_syscalls.c index e880de7..6b32b1c 100644 --- a/lua_syscalls.c +++ b/lua_syscalls.c @@ -1,20 +1,16 @@ #include "lua_syscalls.h" -#include "syscalls.h" #include "utils.h" #include "lualib.h" #include "lauxlib.h" #include "wapr_user.h" -#include -#include -#include int lusys_change_dir (lua_State *L) { apr_status_t rc; const char *path = luaL_checkstring(L, 1); - rc = wrapper_sys_chdir(path); + rc = lkl_sys_chdir(path); if (0 != rc) { lua_pushnil (L); @@ -40,7 +36,7 @@ int lusys_get_dir (lua_State *L) char path[255+2]; apr_status_t rc; - rc = wrapper_sys_getcwd(path, 255); + rc = lkl_sys_getcwd(path, 255); printf("wrapper_sys_getcwd ret [%d], [%s]\n", rc, path); if (rc <= 0) { @@ -59,8 +55,8 @@ int lusys_mkdir (lua_State *L) { const char *path = luaL_checkstring (L, 1); int fail; - mode_t oldmask = wrapper_sys_umask( (mode_t)0 ); - fail = wrapper_sys_mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | + __kernel_mode_t oldmask = lkl_sys_umask( (mode_t)0 ); + fail = lkl_sys_mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH ); if (fail) { @@ -68,7 +64,7 @@ int lusys_mkdir (lua_State *L) lua_pushfstring (L, "%s", lfd_apr_strerror_thunsafe(fail)); return 2; } - wrapper_sys_umask (oldmask); + lkl_sys_umask (oldmask); lua_pushboolean (L, 1); return 1; } @@ -78,7 +74,7 @@ int lusys_rmdir (lua_State *L) const char *path = luaL_checkstring (L, 1); int fail; - fail = wrapper_sys_rmdir (path); + fail = lkl_sys_rmdir (path); if (fail) { lua_pushnil (L); @@ -96,7 +92,7 @@ int lusys_rmdir (lua_State *L) int lusys_utime (lua_State *L) { const char *file = luaL_checkstring (L, 1); - struct utimbuf utb, *buf; + struct __kernel_utimbuf utb, *buf; apr_status_t rc; if (lua_gettop (L) == 1) /* set to current date/time */ @@ -107,7 +103,7 @@ int lusys_utime (lua_State *L) utb.modtime = (time_t)luaL_optnumber (L, 3, utb.actime); buf = &utb; } - rc = wrapper_sys_utime (file, buf); + rc = lkl_sys_utime (file, buf); if (0 != rc) { lua_pushnil (L); @@ -126,7 +122,7 @@ int lusys_utime (lua_State *L) int lusys_utimes (lua_State *L) { const char *file = luaL_checkstring (L, 1); - struct timeval utb, *buf; + struct __kernel_timeval utb, *buf; apr_status_t rc; if (lua_gettop (L) == 1) /* set to current date/time */ @@ -137,7 +133,7 @@ int lusys_utimes (lua_State *L) utb.tv_usec = (long)luaL_optnumber (L, 3, 0); buf = &utb; } - rc = wrapper_sys_utimes (file, buf); + rc = lkl_sys_utimes (file, buf); if (0 != rc) { lua_pushnil (L); diff --git a/lua_syscalls.h b/lua_syscalls.h index 4c9e887..a7dc3c7 100644 --- a/lua_syscalls.h +++ b/lua_syscalls.h @@ -3,6 +3,7 @@ #include "lua.h" +#include int lusys_change_dir (lua_State *L); int lusys_get_dir (lua_State *L); diff --git a/main.c b/main.c index e75a8c9..eb94a6a 100644 --- a/main.c +++ b/main.c @@ -10,51 +10,78 @@ #include #include #include +#include + +#include +#include +#include -#include "include/asm/callbacks.h" -#include "syscalls.h" -#include "syscall_helpers.h" #include "utils.h" #include "lua_main.h" -#include "lklops.h" -#include "drivers/disk.h" apr_pool_t * root_pool; - static const char *script_name="default.lua"; -static const char *disk_image="disk"; -static const char *fs_type; -static int ro=0; #ifdef LKL_FILE_APIS -static dev_t devno; +static const char *disk_image="disk"; +static const char *fs_type="ext3"; +static int ro=0; +static __kernel_dev_t devno; static apr_file_t *disk_file; -static int init_err; - - -apr_thread_mutex_t *wait_init; - -int lkl_init_2(void) +int lkl_init(void) { + apr_finfo_t fi; apr_status_t rc; - if ((rc=apr_file_open(&disk_file, disk_image, APR_FOPEN_READ|(ro?0:APR_FOPEN_WRITE)|APR_FOPEN_BINARY, - APR_OS_DEFAULT, root_pool)) != APR_SUCCESS) { + rc=apr_stat(&fi, disk_image, APR_FINFO_SIZE, root_pool); + if (rc != APR_SUCCESS) { + lfd_log(LFD_ERROR, "failed to stat disk image '%s': %s", disk_image, lfd_apr_strerror_thunsafe(rc)); + return -1; + } + + rc=apr_file_open(&disk_file, disk_image, + APR_FOPEN_READ| (ro?0:APR_FOPEN_WRITE)| + APR_FOPEN_BINARY, APR_OS_DEFAULT, + root_pool); + if (rc != APR_SUCCESS) { lfd_log(LFD_ERROR, "failed to open disk image '%s': %s", disk_image, lfd_apr_strerror_thunsafe(rc)); - init_err=-1; - goto out; + return -1; } - if (lkl_disk_add_disk(disk_file, &devno)) { - init_err=-1; - goto out; + devno=lkl_disk_add_disk(disk_file, disk_image, 0, fi.size/512); + if (devno == 0) { + apr_file_close(disk_file); + return -1; } - -out: - apr_thread_mutex_unlock(wait_init); - return init_err; + return 0; +} + +int lkl_mount(void) +{ + char dev_str[]= { "/dev/xxxxxxxxxxxxxxxx" }; + int err; + + snprintf(dev_str, sizeof(dev_str), "/dev/%016x", devno); + err=lkl_sys_mknod(dev_str, S_IFBLK|0600, devno); + if (err != 0) + return err; + + + err=lkl_sys_mount(dev_str, "/root", (char*)fs_type, 0, 0); + if (err != 0) + return err; + + err=lkl_sys_chdir("/root"); + if (err != 0) + return err; + + err=lkl_sys_chroot("."); + if (err != 0) + return err; + + return 0; } #endif @@ -65,7 +92,7 @@ static const apr_getopt_option_t opt_option[] = { { "fs-type", 't', TRUE, "filesystem type (ext3, etc.)" }, { "diskname", 'd', TRUE, "path to disk (image) to use, default='disk'" }, #endif - { "file", 'f', TRUE, "path to script file to run, default='default.lua'" }, + { "file", 'f', TRUE, "path to script file to run, default='default.lua'" }, { "help", 'h', 0, "display this help and exit" }, { NULL, 0, 0, NULL }, }; @@ -97,6 +124,7 @@ static int parse_command_line(int argc, char const *const * argv) { switch (optch) { +#ifdef LKL_APIS case 'r': ro=1; break; @@ -106,6 +134,7 @@ static int parse_command_line(int argc, char const *const * argv) case 'd': disk_image=optarg; break; +#endif case 'f': script_name=optarg; break; @@ -146,35 +175,20 @@ int main(int argc, char const *const * argv, char const *const * engv) if (parse_command_line(argc, argv) != 0) return 3; - apr_atomic_init(root_pool); - syscall_helpers_init(); - #ifdef LKL_FILE_APIS - apr_thread_mutex_create(&wait_init, APR_THREAD_MUTEX_UNNESTED, root_pool); - apr_thread_mutex_lock(wait_init); - lkl_init(lkl_init_2); - apr_thread_mutex_lock(wait_init); - - if (init_err != 0) { - lkl_fini(LKL_FINI_DONT_UMOUNT_ROOT); - return -1; - } - - if ((rc=wrapper_sys_mkdir("/mnt", 0700))) { - lfd_log(LFD_ERROR, "failed to mkdir /mnt: %d", rc); - lkl_fini(LKL_FINI_DONT_UMOUNT_ROOT); + if (lkl_env_init(lkl_init, 16*1024*1024) != 0) return -1; - } - if ((rc=wrapper_sys_mount(disk_file, devno, NULL, ro)) < 0) { + if ((rc=lkl_mount()) < 0) { //FIXME: add string error code; note that the error code is not //compatible with apr (unless you are running on linux/i386); we //most likely need error codes strings in lkl itself; need to //fix other cases as well + lkl_sys_halt(); + apr_file_close(disk_file); lfd_log(LFD_ERROR, "failed to mount disk: %d", rc); - lkl_fini(LKL_FINI_DONT_UMOUNT_ROOT); return -1; } #endif @@ -184,11 +198,10 @@ int main(int argc, char const *const * argv, char const *const * engv) printf("LUA code is not running any more. All will be obliterated.\n"); #ifdef LKL_FILE_APIS - lkl_fini(0); + lkl_sys_umount("/", 0); + lkl_sys_halt(); apr_file_close(disk_file); #endif - - syscall_helpers_fini(); return 0; } diff --git a/syscall_helpers.c b/syscall_helpers.c deleted file mode 100644 index 42a2867..0000000 --- a/syscall_helpers.c +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include - -static apr_thread_mutex_t *syscall_mutex; -static apr_pool_t *syscall_pool; -static apr_thread_mutex_t *wait_syscall_mutex; - -void syscall_helpers_init(void) -{ - apr_pool_create(&syscall_pool, NULL); - apr_thread_mutex_create(&syscall_mutex, APR_THREAD_MUTEX_UNNESTED, syscall_pool); - apr_thread_mutex_create(&wait_syscall_mutex, APR_THREAD_MUTEX_UNNESTED, syscall_pool); - apr_thread_mutex_lock(wait_syscall_mutex); -} - -void syscall_helpers_fini(void) -{ - apr_thread_mutex_destroy(syscall_mutex); - apr_pool_destroy(syscall_pool); -} - - -void syscall_done(void *arg) -{ - apr_thread_mutex_unlock(wait_syscall_mutex); -} - -void syscall_enter(void) -{ - apr_thread_mutex_lock(syscall_mutex); -} - -void syscall_exit(void) -{ - apr_thread_mutex_lock(wait_syscall_mutex); - apr_thread_mutex_unlock(syscall_mutex); -} - diff --git a/syscall_helpers.h b/syscall_helpers.h deleted file mode 100644 index 97e5d75..0000000 --- a/syscall_helpers.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SYSCALL_HELPERS_H__ -#define SYSCALL_HELPERS_H__ - -void syscall_helpers_init(void); -void syscall_helpers_fini(void); -void syscall_enter(void); -void syscall_exit(void); -void syscall_done(void *arg); - -#endif diff --git a/syscalls.c b/syscalls.c deleted file mode 100644 index 8b459e1..0000000 --- a/syscalls.c +++ /dev/null @@ -1,270 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "syscall_helpers.h" - - -#define SYSCALL_REQ(_syscall, _params...) \ - struct linux_syscall_request sr = { \ - .syscall = __NR_##_syscall, \ - .params = { _params }, \ - .done = syscall_done \ - }; \ - syscall_enter(); \ - linux_trigger_irq_with_data(SYSCALL_IRQ, &sr); \ - syscall_exit(); \ - return sr.ret; \ - -struct utimbuf; - - -long wrapper_sys_sync(void) -{ - SYSCALL_REQ(sync); -} - -static struct linux_syscall_request halt_sr = { - .syscall = __NR_reboot, -}; - - -long wrapper_sys_halt(void) -{ - linux_trigger_irq_with_data(SYSCALL_IRQ, &halt_sr); - return 0; -} - -long wrapper_sys_umount(const char *path, int flags) -{ - SYSCALL_REQ(umount, (long)path, flags); -} - -ssize_t wrapper_sys_write(unsigned int fd, const char *buf, size_t count) -{ - SYSCALL_REQ(write, fd, (long)buf, count); -} - -long wrapper_sys_close(unsigned int fd) -{ - SYSCALL_REQ(close, fd); -} - -long wrapper_sys_unlink(const char *pathname) -{ - SYSCALL_REQ(unlink, (long)pathname); -} - -long wrapper_sys_open(const char *filename, int flags, int mode) -{ - SYSCALL_REQ(open, (long)filename, flags, mode); -} - -long wrapper_sys_poll(struct pollfd *ufds, unsigned int nfds, long timeout) -{ - SYSCALL_REQ(poll, (long)ufds, nfds, timeout); -} - -ssize_t wrapper_sys_read(unsigned int fd, char *buf, size_t count) -{ - SYSCALL_REQ(read, fd, (long)buf, count); -} - -off_t wrapper_sys_lseek(unsigned int fd, off_t offset, unsigned int origin) -{ - SYSCALL_REQ(lseek, fd, offset, origin); -} - -long wrapper_sys_rename(const char *oldname, const char *newname) -{ - SYSCALL_REQ(rename, (long)oldname, (long)newname); -} - -long wrapper_sys_flock(unsigned int fd, unsigned int cmd) -{ - SYSCALL_REQ(flock, fd, cmd); -} - -long wrapper_sys_newfstat(unsigned int fd, struct stat *statbuf) -{ - SYSCALL_REQ(newfstat, fd, (long)statbuf); -} - -long wrapper_sys_chmod(const char *filename, mode_t mode) -{ - SYSCALL_REQ(chmod, (long)filename, mode); -} - -long wrapper_sys_newlstat(char *filename, struct stat *statbuf) -{ - SYSCALL_REQ(newlstat, (long)filename, (long)statbuf); -} - -long wrapper_sys_mkdir(const char *pathname, int mode) -{ - SYSCALL_REQ(mkdir, (long)pathname, mode); -} - -long wrapper_sys_rmdir(const char *pathname) -{ - SYSCALL_REQ(rmdir, (long)pathname); -} - -long wrapper_sys_getdents(unsigned int fd, struct linux_dirent *dirent, unsigned int count) -{ - SYSCALL_REQ(getdents, fd, (long)dirent, count); -} - -long wrapper_sys_newstat(char *filename, struct stat *statbuf) -{ - SYSCALL_REQ(newstat, (long)filename, (long)statbuf); -} - -long wrapper_sys_utimes(const char *filename, struct timeval *utimes) -{ - SYSCALL_REQ(utime, (long)filename, (long)utimes); -} - -long wrapper_sys_utime(const char *filename, const struct utimbuf *buf) -{ - SYSCALL_REQ(utime, (long)filename, (long)buf); -} - -long _wrapper_sys_mount(const char *dev, const char *mnt_point, const char *fs, int flags, void *data) -{ - SYSCALL_REQ(mount, (long)dev, (long)mnt_point, (long)fs, flags, (long)data); -} - - -long wrapper_sys_chdir(const char *dir) -{ - SYSCALL_REQ(chdir, (long)dir); -} - - -long wrapper_sys_getcwd(char *buf, unsigned long size) -{ - SYSCALL_REQ(getcwd, (long)buf, (long) size); -} - - -long wrapper_sys_mknod(const char *filename, int mode, unsigned dev) -{ - SYSCALL_REQ(mknod, (long)filename, mode, dev); -} - - -long wrapper_sys_chroot(const char *dir) -{ - SYSCALL_REQ(chroot, (long)dir); -} - - -int get_filesystem_list(char * buf); - -static void get_fs_names(char *page) -{ - char *s = page; - int len = get_filesystem_list(page); - char *p, *next; - - page[len] = '\0'; - for (p = page-1; p; p = next) { - next = strchr(++p, '\n'); - if (*p++ != '\t') - continue; - while ((*s++ = *p++) != '\n') - ; - s[-1] = '\0'; - } - - *s = '\0'; -} - -static int try_mount(char *fstype, char *devno_str, char *mnt, int flags, void *data) -{ - int err; - char *p, *fs_names; - - if (fstype) - return _wrapper_sys_mount(devno_str, mnt, fstype, flags, data); - - fs_names=malloc(PAGE_SIZE); - get_fs_names(fs_names); -retry: - for (p = fs_names; *p; p += strlen(p)+1) { - err = _wrapper_sys_mount(devno_str, mnt, p, flags, data); - switch (err) { - case 0: - goto out; - case -EACCES: - flags |= MS_RDONLY; - goto retry; - case -EINVAL: - continue; - } - } -out: - free(fs_names); - - return err; -} - - -long wrapper_sys_mount(void *file, int devno, char *fstype, int ro) -{ - char devno_str[] = { "/dev/xxxxxxxxxxxxxxxx" }; - char mnt[] = { "/mnt/xxxxxxxxxxxxxxxx" }; - - /* create /dev/dev */ - snprintf(devno_str, sizeof(devno_str), "/dev/%016x", devno); - if (wrapper_sys_mknod(devno_str, S_IFBLK|0600, devno)) - goto out_error; - - /* create /mnt/filename */ - sprintf(mnt, "/mnt/%016x", devno); - if (wrapper_sys_mkdir(mnt, 0700)) - goto out_del_dev; - - if (try_mount(fstype, devno_str, mnt, ro?MS_RDONLY:0, 0)) - goto out_del_mnt_dir; - - wrapper_sys_chdir(mnt); - _wrapper_sys_mount(".", "/", NULL, MS_MOVE, NULL); - wrapper_sys_chroot("."); - - return 0; - -out_del_mnt_dir: - wrapper_sys_unlink(mnt); -out_del_dev: - wrapper_sys_unlink(devno_str); -out_error: - return -1; -} - - -long wrapper_sys_getgid(void) -{ - SYSCALL_REQ(getgid); -} - - -long wrapper_sys_getuid(void) -{ - SYSCALL_REQ(getuid); -} - - -long wrapper_sys_umask(mode_t size) -{ - SYSCALL_REQ(umask, (long)size); -} - diff --git a/syscalls.h b/syscalls.h deleted file mode 100644 index 097e63f..0000000 --- a/syscalls.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef LKLFTD_SYSCALLS_H__ -#define LKLFTD_SYSCALLS_H__ - -#include -#include - -struct pollfd; -struct stat; -struct linux_dirent; -struct utimbuf; - -long wrapper_sys_sync(void); -long wrapper_sys_mount(void *disk, int devno, char *fstype, int ro); -long wrapper_sys_halt(); -ssize_t wrapper_sys_write(unsigned int fd, const char *buf, size_t count); -long wrapper_sys_close(unsigned int fd); -long wrapper_sys_unlink(const char *pathname); -long wrapper_sys_open(const char *filename, int flags, int mode); -long wrapper_sys_poll(struct pollfd *ufds, unsigned int nfds, long timeout); -ssize_t wrapper_sys_read(unsigned int fd, char *buf, size_t count); -off_t wrapper_sys_lseek(unsigned int fd, off_t offset, unsigned int origin); -long wrapper_sys_rename(const char *oldname, const char *newname); -long wrapper_sys_flock(unsigned int fd, unsigned int cmd); -long wrapper_sys_newfstat(unsigned int fd, struct stat *statbuf); -long wrapper_sys_chmod(const char *filename, mode_t mode); -long wrapper_sys_newlstat(char *filename, struct stat *statbuf); -long wrapper_sys_mkdir(const char *pathname, int mode); -long wrapper_sys_rmdir(const char *pathname); -long wrapper_sys_getdents(unsigned int fd, struct linux_dirent *dirent, unsigned int count); -long wrapper_sys_newstat(char *filename, struct stat *statbuf); -long wrapper_sys_utimes(const char *filename, struct timeval *utimes); -long wrapper_sys_utime(const char *filename, const struct utimbuf *buf); -long wrapper_sys_umount(const char *path, int flags); -long wrapper_sys_getgid(void); -long wrapper_sys_getuid(void); -long wrapper_sys_chdir(const char *dir); -long wrapper_sys_getcwd(char *buf, unsigned long size); -long wrapper_sys_umask(mode_t size); -#endif diff --git a/thread_wrapper.c b/thread_wrapper.c deleted file mode 100644 index 85f62f3..0000000 --- a/thread_wrapper.c +++ /dev/null @@ -1,93 +0,0 @@ -#include "thread_wrapper.h" - -#include -#include -struct apr_thread_wrapper_t -{ - struct apr_thread_wrapper_t*prev,*next; - apr_thread_t * thd; -}; - -struct apr_thread_wrapper_t thread_list; -apr_thread_mutex_t * thread_list_mutex; -volatile int thread_list_counter = 0; -volatile int system_preparing_to_go_down = 0; - -static void thread_list_add(struct apr_thread_wrapper_t * list) -{ - apr_thread_mutex_lock(thread_list_mutex); - { - list->next = thread_list.next; - thread_list.next->prev = list; - list->prev = &thread_list; - thread_list.next = list; - thread_list_counter++; - } - apr_thread_mutex_unlock(thread_list_mutex); -} - -static void thread_list_rem(struct apr_thread_wrapper_t * list) -{ - if(thread_list_counter && system_preparing_to_go_down==0) - { - apr_thread_mutex_lock(thread_list_mutex); - { - thread_list_counter--; - list->next->prev = list->prev; - list->prev->next = list->next; - free(list); - } - apr_thread_mutex_unlock(thread_list_mutex); - } -} - -apr_status_t wrapper_apr_thread_init(apr_pool_t * pool) -{ - apr_status_t rc; - rc = apr_thread_mutex_create(&thread_list_mutex, APR_THREAD_MUTEX_UNNESTED, pool); - if(APR_SUCCESS != rc) - return rc; - thread_list.prev = thread_list.next = &thread_list; - return APR_SUCCESS; -} - - -apr_status_t wrapper_apr_thread_create (apr_thread_wrapper_t **new_thread, apr_threadattr_t *attr, - apr_thread_start_t func, void *data, apr_pool_t *cont) -{ - apr_status_t rc; - apr_thread_wrapper_t * l = (apr_thread_wrapper_t *)malloc(sizeof(apr_thread_wrapper_t)); - *new_thread = l; - thread_list_add(l); - rc = apr_thread_create (&l->thd, attr, func, data, cont); - if(APR_SUCCESS != rc) - thread_list_rem(l); - return rc; -} - - -apr_status_t wrapper_apr_thread_exit (apr_thread_wrapper_t *thw, apr_status_t retval) -{ - apr_thread_t * thd = thw->thd; - //thread_list_rem(thw); - return apr_thread_exit(thd, retval); -} - -void wrapper_apr_thread_join_all() -{ - struct apr_thread_wrapper_t * list; - struct apr_thread_wrapper_t * old_list; - apr_status_t rc; - system_preparing_to_go_down = 1; - list = thread_list.next; - while(list != &thread_list) - { - if(NULL != list->thd) - { - apr_thread_join(&rc, list->thd); - } - old_list = list; - list = list->next; - free(old_list); - } -} diff --git a/thread_wrapper.h b/thread_wrapper.h deleted file mode 100644 index 500f3e7..0000000 --- a/thread_wrapper.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef LKLFTPD_THREAD_WRAPPER_H__ -#define LKLFTPD_THREAD_WRAPPER_H__ - - -#include -struct apr_thread_wrapper_t; -typedef struct apr_thread_wrapper_t apr_thread_wrapper_t; - -#define APR_THREAD_WRAPPER_FUNC -typedef void* (APR_THREAD_WRAPPER_FUNC apr_thread_wrapper_start_t) (struct apr_thread_wrapper_t * thd, void*param); - -extern volatile int shutting_down; -apr_status_t wrapper_apr_thread_init(apr_pool_t * pool); -apr_status_t wrapper_apr_thread_create (apr_thread_wrapper_t **new_thread, apr_threadattr_t *attr, - apr_thread_start_t func, void *data, apr_pool_t *cont); -void wrapper_apr_thread_join_all(void); -apr_status_t wrapper_apr_thread_exit (apr_thread_wrapper_t *thd, apr_status_t retval); - -#endif//LKLFTPD_THREAD_WRAPPER_H__ diff --git a/wapr_dirops.c b/wapr_dirops.c index 0f4c6bc..c53065f 100644 --- a/wapr_dirops.c +++ b/wapr_dirops.c @@ -1,7 +1,6 @@ #ifdef LKL_FILE_APIS #include "wapr_fileops.h" -#include "syscalls.h" #define BUF_SIZE 4096 @@ -11,14 +10,14 @@ static apr_status_t dir_cleanup(void *thedir) wapr_dir_t *dir = thedir; apr_status_t rc; - rc = wrapper_sys_close(dir->fd); + rc = lkl_sys_close(dir->fd); return rc; } apr_status_t wapr_dir_open(wapr_dir_t **new, const char *dirname, apr_pool_t *pool) { - int dir = wrapper_sys_open(dirname,O_RDONLY|O_DIRECTORY|O_LARGEFILE, 0); + int dir = lkl_sys_open(dirname,O_RDONLY|O_DIRECTORY|O_LARGEFILE, 0); if (dir < 0) return APR_EINVAL; @@ -29,7 +28,7 @@ apr_status_t wapr_dir_open(wapr_dir_t **new, const char *dirname, (*new)->size = 0; (*new)->offset = 0; (*new)->entry = NULL; - (*new)->data = (struct linux_dirent*) apr_pcalloc(pool,BUF_SIZE); + (*new)->data = (struct __kernel_dirent*) apr_pcalloc(pool,BUF_SIZE); apr_pool_cleanup_register((*new)->pool, *new, dir_cleanup, apr_pool_cleanup_null); @@ -48,7 +47,7 @@ apr_status_t wapr_dir_make(const char *path, apr_fileperms_t perm, apr_status_t rc; mode_t mode = wapr_unix_perms2mode(perm); - rc = wrapper_sys_mkdir(path, mode); + rc = lkl_sys_mkdir(path, mode); return -rc; } @@ -118,25 +117,25 @@ apr_status_t wapr_dir_remove(const char *path, apr_pool_t *pool) { apr_status_t rc; - rc = wrapper_sys_rmdir(path); + rc = lkl_sys_rmdir(path); return -rc; } -struct dirent * wapr_readdir(wapr_dir_t *thedir) +struct __kernel_dirent * wapr_readdir(wapr_dir_t *thedir) { - struct dirent * de; + struct __kernel_dirent * de; if(thedir->offset >= thedir->size) { /* We've emptied out our buffer. Refill it. */ - int bytes = wrapper_sys_getdents(thedir->fd, thedir->data, BUF_SIZE); + int bytes = lkl_sys_getdents(thedir->fd, thedir->data, BUF_SIZE); if(bytes <= 0) return NULL; thedir->size = bytes; thedir->offset = 0; } - de = (struct dirent*) ((char*) thedir->data+thedir->offset); + de = (struct __kernel_dirent*) ((char*) thedir->data+thedir->offset); thedir->offset += de->d_reclen; return de; diff --git a/wapr_fileops.c b/wapr_fileops.c index 1e744c9..78e9685 100644 --- a/wapr_fileops.c +++ b/wapr_fileops.c @@ -1,9 +1,7 @@ //here we implement the lkl-based file wrappers. #ifdef LKL_FILE_APIS -#include "syscalls.h" #include "wapr_fileops.h" -#include #define APR_FILE_BUFSIZE 4096 @@ -17,7 +15,7 @@ apr_status_t wapr_file_flush_locked(wapr_file_t *thefile) do { - written = wrapper_sys_write(thefile->filedes, thefile->buffer, thefile->bufpos); + written = lkl_sys_write(thefile->filedes, thefile->buffer, thefile->bufpos); } while (written == -EINTR); if (written < 0) @@ -52,12 +50,12 @@ static apr_status_t file_cleanup(wapr_file_t *file) apr_status_t rv = APR_SUCCESS; int rc; - rc = wrapper_sys_close(file->filedes); + rc = lkl_sys_close(file->filedes); if (0 == rc) { file->filedes = -1; if (file->flags & APR_DELONCLOSE) - wrapper_sys_unlink(file->fname); + lkl_sys_unlink(file->fname); if (file->thlock) rv = apr_thread_mutex_destroy(file->thlock); } @@ -155,11 +153,11 @@ apr_status_t wapr_file_open(wapr_file_t **new, const char *fname, if (perm == APR_OS_DEFAULT) { - fd = wrapper_sys_open(fname, oflags, 0666); + fd = lkl_sys_open(fname, oflags, 0666); } else { - fd = wrapper_sys_open(fname, oflags, wapr_unix_perms2mode(perm)); + fd = lkl_sys_open(fname, oflags, wapr_unix_perms2mode(perm)); } if (fd < 0) return APR_EINVAL; @@ -220,7 +218,7 @@ static apr_status_t wapr_wait_for_io_or_timeout(wapr_file_t *f, int for_read) do { - rc = wrapper_sys_poll(&pfd, 1, timeout); + rc = lkl_sys_poll(&pfd, 1, timeout); } while (rc == -EINTR); if (!rc) @@ -261,7 +259,7 @@ static apr_status_t file_read_buffered(wapr_file_t *thefile, void *buf, { if (thefile->bufpos >= thefile->dataRead) { - int bytesread = wrapper_sys_read(thefile->filedes, thefile->buffer, APR_FILE_BUFSIZE); + int bytesread = lkl_sys_read(thefile->filedes, thefile->buffer, APR_FILE_BUFSIZE); if (bytesread == 0) { thefile->eof_hit = 1; @@ -330,7 +328,7 @@ apr_status_t wapr_file_read(wapr_file_t *thefile, void *buf, do { - rv = wrapper_sys_read(thefile->filedes, buf, *nbytes); + rv = lkl_sys_read(thefile->filedes, buf, *nbytes); } while (rv == -EINTR); // WAIT FOR IO @@ -346,7 +344,7 @@ apr_status_t wapr_file_read(wapr_file_t *thefile, void *buf, { do { - rv = wrapper_sys_read(thefile->filedes, buf, *nbytes); + rv = lkl_sys_read(thefile->filedes, buf, *nbytes); } while (rv == -EINTR); } @@ -387,7 +385,7 @@ apr_status_t wapr_file_write(wapr_file_t *thefile, const void *buf, // apr_int64_t offset = thefile->filePtr - thefile->dataRead + thefile->bufpos; if (offset != thefile->filePtr) - wrapper_sys_lseek(thefile->filedes, offset, SEEK_SET); + lkl_sys_lseek(thefile->filedes, offset, SEEK_SET); thefile->bufpos = thefile->dataRead = 0; thefile->direction = 1; } @@ -414,7 +412,7 @@ apr_status_t wapr_file_write(wapr_file_t *thefile, const void *buf, { do { - rv = wrapper_sys_write(thefile->filedes, buf, *nbytes); + rv = lkl_sys_write(thefile->filedes, buf, *nbytes); } while (rv == -EINTR); // USE WAIT FOR IO @@ -432,7 +430,7 @@ apr_status_t wapr_file_write(wapr_file_t *thefile, const void *buf, { do { - rv = wrapper_sys_write(thefile->filedes, buf, *nbytes); + rv = lkl_sys_write(thefile->filedes, buf, *nbytes); } while (rv == -EINTR); if ((rv == -EAGAIN || rv == -EWOULDBLOCK)) @@ -525,7 +523,7 @@ static apr_status_t setptr(wapr_file_t *thefile, apr_off_t pos ) } else { - rv = wrapper_sys_lseek(thefile->filedes, pos, SEEK_SET); + rv = lkl_sys_lseek(thefile->filedes, pos, SEEK_SET); if (rv >= 0) { thefile->bufpos = thefile->dataRead = 0; @@ -576,7 +574,7 @@ apr_status_t wapr_file_seek(wapr_file_t *thefile, apr_seek_where_t where, apr_of } else { - rv = wrapper_sys_lseek(thefile->filedes, *offset, where); + rv = lkl_sys_lseek(thefile->filedes, *offset, where); if (rv < 0) { *offset = -1; @@ -602,7 +600,7 @@ apr_status_t wapr_file_remove(const char *path, apr_pool_t *pool) { apr_status_t rc; - rc = wrapper_sys_unlink(path); + rc = lkl_sys_unlink(path); return -rc; } @@ -611,7 +609,7 @@ apr_status_t wapr_file_rename(const char *from_path, const char *to_path, { apr_status_t rc; - rc = wrapper_sys_rename(from_path, to_path); + rc = lkl_sys_rename(from_path, to_path); return -rc; } @@ -628,7 +626,7 @@ apr_status_t wapr_file_lock(wapr_file_t *thefile, int type) ltype |= LOCK_NB; /* keep trying if flock() gets interrupted (by a signal) */ - while ((rc = wrapper_sys_flock(thefile->filedes, ltype)) == -EINTR) + while ((rc = lkl_sys_flock(thefile->filedes, ltype)) == -EINTR) continue; if (rc < 0) @@ -640,7 +638,7 @@ apr_status_t wapr_file_unlock(wapr_file_t *thefile) { int rc; - while ((rc = wrapper_sys_flock(thefile->filedes, LOCK_UN)) == -EINTR) + while ((rc = lkl_sys_flock(thefile->filedes, LOCK_UN)) == -EINTR) continue; if (rc < 0) diff --git a/wapr_fileops.h b/wapr_fileops.h index 49dfda2..c92f7b5 100644 --- a/wapr_fileops.h +++ b/wapr_fileops.h @@ -63,10 +63,7 @@ #include #include -#include -#include -#include - +#include #ifdef __cplusplus extern "C" { @@ -94,16 +91,15 @@ struct wapr_file_t }; typedef struct wapr_file_t wapr_file_t; -struct linux_dirent; struct wapr_dir_t { apr_pool_t *pool; char * dirname; // dir name int fd; // file descriptor - struct linux_dirent * data; // dir block + struct __kernel_dirent * data; // dir block int offset; // current offset int size; // total valid data - struct dirent *entry; // current entry + struct __kernel_dirent *entry; // current entry }; typedef struct wapr_dir_t wapr_dir_t; diff --git a/wapr_filestat.c b/wapr_filestat.c index 771b581..0061047 100644 --- a/wapr_filestat.c +++ b/wapr_filestat.c @@ -1,13 +1,6 @@ #ifdef LKL_FILE_APIS -#define __KERNEL__ - -#include -#include - #include "wapr_fileops.h" -#include "syscalls.h" - apr_fileperms_t wapr_unix_mode2perms(mode_t mode) { @@ -111,7 +104,7 @@ static apr_filetype_e filetype_from_mode(mode_t mode) } -static void fill_out_finfo(apr_finfo_t *finfo, struct stat *info,apr_int32_t wanted) +static void fill_out_finfo(apr_finfo_t *finfo, struct __kernel_stat *info,apr_int32_t wanted) { finfo->valid = APR_FINFO_MIN | APR_FINFO_IDENT | APR_FINFO_NLINK | APR_FINFO_OWNER | APR_FINFO_PROT; @@ -132,7 +125,7 @@ static void fill_out_finfo(apr_finfo_t *finfo, struct stat *info,apr_int32_t wan apr_status_t wapr_file_info_get_locked(apr_finfo_t *finfo, apr_int32_t wanted, wapr_file_t *thefile) { - struct stat info; + struct __kernel_stat info; apr_status_t rc; if (thefile->buffered) @@ -141,7 +134,7 @@ apr_status_t wapr_file_info_get_locked(apr_finfo_t *finfo, apr_int32_t wanted, if (rv != APR_SUCCESS) return rv; } - rc = wrapper_sys_newfstat(thefile->filedes, &info); + rc = lkl_sys_newfstat(thefile->filedes, &info); if (!rc) { finfo->pool = thefile->pool; @@ -155,7 +148,7 @@ apr_status_t wapr_file_info_get_locked(apr_finfo_t *finfo, apr_int32_t wanted, apr_status_t wapr_file_info_get(apr_finfo_t *finfo, apr_int32_t wanted, wapr_file_t *thefile) { - struct stat info; + struct __kernel_stat info; int rc; if (thefile->buffered) @@ -164,7 +157,7 @@ apr_status_t wapr_file_info_get(apr_finfo_t *finfo, apr_int32_t wanted, wapr_fil if (rv != APR_SUCCESS) return rv; } - rc = wrapper_sys_newfstat(thefile->filedes, &info); + rc = lkl_sys_newfstat(thefile->filedes, &info); if (0 == rc) { finfo->pool = thefile->pool; @@ -180,7 +173,7 @@ apr_status_t wapr_file_perms_set(const char *fname, apr_fileperms_t perms) apr_status_t rc; mode_t mode = wapr_unix_perms2mode(perms); - rc = wrapper_sys_chmod(fname, mode); + rc = lkl_sys_chmod(fname, mode); if (rc) return -rc; @@ -251,14 +244,14 @@ apr_status_t wapr_file_mtime_set(const char *fname, apr_time_t mtime, return status; { - struct timeval tvp[2]; + struct __kernel_timeval tvp[2]; tvp[0].tv_sec = apr_time_sec(finfo.atime); tvp[0].tv_usec = apr_time_usec(finfo.atime); tvp[1].tv_sec = apr_time_sec(mtime); tvp[1].tv_usec = apr_time_usec(mtime); - status = wrapper_sys_utimes(fname, tvp); + status = lkl_sys_utimes(fname, tvp); if (status) return status; } @@ -267,14 +260,14 @@ apr_status_t wapr_file_mtime_set(const char *fname, apr_time_t mtime, apr_status_t wapr_stat(apr_finfo_t *finfo,const char *fname, apr_int32_t wanted, apr_pool_t *pool) { - struct stat info; + struct __kernel_stat info; int srv =0; - memset(&info,0,sizeof(struct stat)); + memset(&info,0,sizeof(struct __kernel_stat)); if (wanted & APR_FINFO_LINK) - srv = wrapper_sys_newlstat((char*)fname, &info); + srv = lkl_sys_newlstat((char*)fname, &info); else - srv = wrapper_sys_newstat((char*)fname, &info); + srv = lkl_sys_newstat((char*)fname, &info); if (0 == srv) { diff --git a/wapr_user.c b/wapr_user.c index 980dec4..471a0b6 100644 --- a/wapr_user.c +++ b/wapr_user.c @@ -1,7 +1,6 @@ #ifdef LKL_FILE_APIS #include #include "wapr_user.h" -#include "syscalls.h" /** * Get the userid (and groupid) of the calling process @@ -14,8 +13,8 @@ APR_DECLARE(apr_status_t) wapr_uid_current(wapr_uid_t *userid, wapr_gid_t *groupid, apr_pool_t *p) { - *userid = wrapper_sys_getuid(); - *groupid = wrapper_sys_getgid(); + *userid = lkl_sys_getuid(); + *groupid = lkl_sys_getgid(); return APR_SUCCESS; } @@ -46,8 +45,8 @@ APR_DECLARE(apr_status_t) wapr_uid_get(wapr_uid_t *userid, wapr_gid_t *groupid, const char *username, apr_pool_t *p) { //TODO:FIXME: we currently find the CURRENT uid and gid, the function should find the uid and gid for the specified USERNAME. - *userid = wrapper_sys_getuid(); - *groupid = wrapper_sys_getgid(); + *userid = lkl_sys_getuid(); + *groupid = lkl_sys_getgid(); return APR_SUCCESS; } @@ -93,7 +92,7 @@ APR_DECLARE(apr_status_t) wapr_gid_get(wapr_gid_t *groupid, const char *groupname, apr_pool_t *p) { //TODO:FIXME: we return the current user's GID because we don;t have a mappig between usernames and gids - *groupid = wrapper_sys_getgid(); + *groupid = lkl_sys_getgid(); return APR_SUCCESS; } diff --git a/wapr_user.h b/wapr_user.h index 3f495e8..9202c80 100644 --- a/wapr_user.h +++ b/wapr_user.h @@ -25,17 +25,18 @@ #include #include +#include /** * Structure for determining user ownership. */ -typedef uid_t wapr_uid_t; +typedef __kernel_uid_t wapr_uid_t; /** * Structure for determining group ownership. */ -typedef gid_t wapr_gid_t; +typedef __kernel_gid_t wapr_gid_t; /**