Re: [LINUX-KERNEL] C++ in linux kernel
http://www.vmware.com/download/server/open_source.html On Feb 11, 2008 5:07 PM, rohit h <[EMAIL PROTECTED]> wrote: > > On Feb 8, 2008 9:24 PM, Jan Engelhardt <[EMAIL PROTECTED]> wrote: > > > > On Feb 9 2008 00:14, Joonwoo Park wrote: > > >2008/2/8, rohit h <[EMAIL PROTECTED]>: > > >> Hi, > > >> I am a kernel newbie. > > >> I tried to insmod a C++ module containing classes, inheritance. > > >> I am getting 'unresolved symbol' error when I use the 'new' keyword. > > >> What could the problem be? > > >> > > >> What kind of runtime support is needed ( arm linux kernel)? Is a > > >> patch available for it? > > >> > > >Please take a look at click modular router which is using c++ as a > > >linux kernel module. > > >http://www.read.cs.ucla.edu/click/ > > >The lib/glue.cc provides custom operator new. > > > > Uh, let's not make the world worse :) > > Just call malloc from C++, and carefully select what C++ features > > you are going to use. The VMware source for example does it right. > > > > From the links given, I dig that following C++ features need runtime support: > a. Pure virtual functions > b. Global objects : Needs compiler dependent changes > c. new & delete : Can use kmalloc / kfree instead > d. Run time type info > e. Exceptions > I guess features d & e need considerable effort. > Apart from these, am I free to use other C++ features? > Where could I see the VMWare sources? > > > > > Compiling the kernel module with g++ is not a simple work, you may > > need big patch for kernel itself. > > I don't want to compile entire kernel. > I only want to compile my module with g++ and insmod it. > Any hint on how to write the Makefile. > > Thanks in advance, > Rohit > > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to [EMAIL PROTECTED] > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > -- -- "Why is it that every time I'm with you, makes me believe in magic?" -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [LINUX-KERNEL] C++ in linux kernel
http://www.vmware.com/download/server/open_source.html On Feb 11, 2008 5:07 PM, rohit h [EMAIL PROTECTED] wrote: On Feb 8, 2008 9:24 PM, Jan Engelhardt [EMAIL PROTECTED] wrote: On Feb 9 2008 00:14, Joonwoo Park wrote: 2008/2/8, rohit h [EMAIL PROTECTED]: Hi, I am a kernel newbie. I tried to insmod a C++ module containing classes, inheritance. I am getting 'unresolved symbol' error when I use the 'new' keyword. What could the problem be? What kind of runtime support is needed ( arm linux kernel)? Is a patch available for it? Please take a look at click modular router which is using c++ as a linux kernel module. http://www.read.cs.ucla.edu/click/ The lib/glue.cc provides custom operator new. Uh, let's not make the world worse :) Just call malloc from C++, and carefully select what C++ features you are going to use. The VMware source for example does it right. From the links given, I dig that following C++ features need runtime support: a. Pure virtual functions b. Global objects : Needs compiler dependent changes c. new delete : Can use kmalloc / kfree instead d. Run time type info e. Exceptions I guess features d e need considerable effort. Apart from these, am I free to use other C++ features? Where could I see the VMWare sources? Compiling the kernel module with g++ is not a simple work, you may need big patch for kernel itself. I don't want to compile entire kernel. I only want to compile my module with g++ and insmod it. Any hint on how to write the Makefile. Thanks in advance, Rohit -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ -- -- Why is it that every time I'm with you, makes me believe in magic? -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: kmalloc() with size zero
On Fri, 2007-03-23 at 07:08 +0530, Jan Engelhardt wrote: > > On Mar 22 2007 16:18, Stephane Eranian wrote: > > > I'd say "feature", glibc's malloc also returns an address on > malloc(0). > This is implementation defined-the standard allows for return of either null or an address. > > Jan > -- > - > To unsubscribe from this list: send the line "unsubscribe > linux-kernel" in > the body of a message to [EMAIL PROTECTED] > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > > -- Regards, Vignesh Babu BM _ "Why is it that every time I'm with you, makes me believe in magic?" - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: kmalloc() with size zero
On Fri, 2007-03-23 at 07:08 +0530, Jan Engelhardt wrote: On Mar 22 2007 16:18, Stephane Eranian wrote: I'd say feature, glibc's malloc also returns an address on malloc(0). This is implementation defined-the standard allows for return of either null or an address. Jan -- - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ -- Regards, Vignesh Babu BM _ Why is it that every time I'm with you, makes me believe in magic? - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[KJ][PATCH] is_power_of_2 in fs/block_dev.c
Replacing (n & (n-1)) in the context of power of 2 checks with is_power_of_2 Signed-off-by: vignesh babu <[EMAIL PROTECTED]> --- diff --git a/fs/block_dev.c b/fs/block_dev.c index fc7028b..e8f2a2b 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "internal.h" @@ -65,7 +66,7 @@ static void kill_bdev(struct block_device *bdev) int set_blocksize(struct block_device *bdev, int size) { /* Size must be a power of two, and between 512 and PAGE_SIZE */ - if (size > PAGE_SIZE || size < 512 || (size & (size-1))) + if (size > PAGE_SIZE || size < 512 || !is_power_of_2(size)) return -EINVAL; /* Size cannot be smaller than the size supported by the device */ -- Regards, Vignesh Babu BM _ "Why is it that every time I'm with you, makes me believe in magic?" - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[KJ][PATCH] is_power_of_2 in fat
Replacing (n & (n-1)) in the context of power of 2 checks with is_power_of_2 Signed-off-by: vignesh babu <[EMAIL PROTECTED]> --- diff --git a/fs/fat/inode.c b/fs/fat/inode.c index a9e4688..8437190 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #ifndef CONFIG_FAT_DEFAULT_IOCHARSET @@ -1216,8 +1217,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, } logical_sector_size = le16_to_cpu(get_unaligned((__le16 *)>sector_size)); - if (!logical_sector_size - || (logical_sector_size & (logical_sector_size - 1)) + if (!is_power_of_2(logical_sector_size) || (logical_sector_size < 512) || (PAGE_CACHE_SIZE < logical_sector_size)) { if (!silent) @@ -1227,8 +1227,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, goto out_invalid; } sbi->sec_per_clus = b->sec_per_clus; - if (!sbi->sec_per_clus - || (sbi->sec_per_clus & (sbi->sec_per_clus - 1))) { + if (!is_power_of_2(sbi->sec_per_clus)) { if (!silent) printk(KERN_ERR "FAT: bogus sectors per cluster %u\n", sbi->sec_per_clus); -- Regards, Vignesh Babu BM _ "Why is it that every time I'm with you, makes me believe in magic?" - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[KJ][PATCH] is_power_of_2 in fs/hfs
Replacing (n & (n-1)) in the context of power of 2 checks with is_power_of_2 Signed-off-by: vignesh babu <[EMAIL PROTECTED]> --- diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c index 5fd0ed7..8a3a650 100644 --- a/fs/hfs/btree.c +++ b/fs/hfs/btree.c @@ -9,6 +9,7 @@ */ #include +#include #include "btree.h" @@ -76,7 +77,7 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke tree->depth = be16_to_cpu(head->depth); size = tree->node_size; - if (!size || size & (size - 1)) + if (!is_power_of_2(size)) goto fail_page; if (!tree->node_count) goto fail_page; diff --git a/fs/hfsplus/btree.c b/fs/hfsplus/btree.c index a9b9e87..90ebab7 100644 --- a/fs/hfsplus/btree.c +++ b/fs/hfsplus/btree.c @@ -10,6 +10,7 @@ #include #include +#include #include "hfsplus_fs.h" #include "hfsplus_raw.h" @@ -69,7 +70,7 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id) } size = tree->node_size; - if (!size || size & (size - 1)) + if (!is_power_of_2(size)) goto fail_page; if (!tree->node_count) goto fail_page; -- Regards, Vignesh Babu BM _ "Why is it that every time I'm with you, makes me believe in magic?" - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[KJ][PATCH] is_power_of_2 in fat
Replacing (n (n-1)) in the context of power of 2 checks with is_power_of_2 Signed-off-by: vignesh babu [EMAIL PROTECTED] --- diff --git a/fs/fat/inode.c b/fs/fat/inode.c index a9e4688..8437190 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -25,6 +25,7 @@ #include linux/parser.h #include linux/uio.h #include linux/writeback.h +#include linux/log2.h #include asm/unaligned.h #ifndef CONFIG_FAT_DEFAULT_IOCHARSET @@ -1216,8 +1217,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, } logical_sector_size = le16_to_cpu(get_unaligned((__le16 *)b-sector_size)); - if (!logical_sector_size - || (logical_sector_size (logical_sector_size - 1)) + if (!is_power_of_2(logical_sector_size) || (logical_sector_size 512) || (PAGE_CACHE_SIZE logical_sector_size)) { if (!silent) @@ -1227,8 +1227,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, goto out_invalid; } sbi-sec_per_clus = b-sec_per_clus; - if (!sbi-sec_per_clus - || (sbi-sec_per_clus (sbi-sec_per_clus - 1))) { + if (!is_power_of_2(sbi-sec_per_clus)) { if (!silent) printk(KERN_ERR FAT: bogus sectors per cluster %u\n, sbi-sec_per_clus); -- Regards, Vignesh Babu BM _ Why is it that every time I'm with you, makes me believe in magic? - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[KJ][PATCH] is_power_of_2 in fs/hfs
Replacing (n (n-1)) in the context of power of 2 checks with is_power_of_2 Signed-off-by: vignesh babu [EMAIL PROTECTED] --- diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c index 5fd0ed7..8a3a650 100644 --- a/fs/hfs/btree.c +++ b/fs/hfs/btree.c @@ -9,6 +9,7 @@ */ #include linux/pagemap.h +#include linux/log2.h #include btree.h @@ -76,7 +77,7 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke tree-depth = be16_to_cpu(head-depth); size = tree-node_size; - if (!size || size (size - 1)) + if (!is_power_of_2(size)) goto fail_page; if (!tree-node_count) goto fail_page; diff --git a/fs/hfsplus/btree.c b/fs/hfsplus/btree.c index a9b9e87..90ebab7 100644 --- a/fs/hfsplus/btree.c +++ b/fs/hfsplus/btree.c @@ -10,6 +10,7 @@ #include linux/slab.h #include linux/pagemap.h +#include linux/log2.h #include hfsplus_fs.h #include hfsplus_raw.h @@ -69,7 +70,7 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id) } size = tree-node_size; - if (!size || size (size - 1)) + if (!is_power_of_2(size)) goto fail_page; if (!tree-node_count) goto fail_page; -- Regards, Vignesh Babu BM _ Why is it that every time I'm with you, makes me believe in magic? - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[KJ][PATCH] is_power_of_2 in fs/block_dev.c
Replacing (n (n-1)) in the context of power of 2 checks with is_power_of_2 Signed-off-by: vignesh babu [EMAIL PROTECTED] --- diff --git a/fs/block_dev.c b/fs/block_dev.c index fc7028b..e8f2a2b 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -22,6 +22,7 @@ #include linux/mount.h #include linux/uio.h #include linux/namei.h +#include linux/log2.h #include asm/uaccess.h #include internal.h @@ -65,7 +66,7 @@ static void kill_bdev(struct block_device *bdev) int set_blocksize(struct block_device *bdev, int size) { /* Size must be a power of two, and between 512 and PAGE_SIZE */ - if (size PAGE_SIZE || size 512 || (size (size-1))) + if (size PAGE_SIZE || size 512 || !is_power_of_2(size)) return -EINVAL; /* Size cannot be smaller than the size supported by the device */ -- Regards, Vignesh Babu BM _ Why is it that every time I'm with you, makes me believe in magic? - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[KJ][PATCH] is_power_of_2 in ia64mm
Replacing (n & (n-1)) in the context of power of 2 checks with is_power_of_2 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c index 0c7e94e..0ccc70e 100644 --- a/arch/ia64/mm/hugetlbpage.c +++ b/arch/ia64/mm/hugetlbpage.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -175,7 +176,7 @@ static int __init hugetlb_setup_sz(char *str) tr_pages = 0x15557000UL; size = memparse(str, ); - if (*str || (size & (size-1)) || !(tr_pages & size) || + if (*str || !is_power_of_2(size) || !(tr_pages & size) || size <= PAGE_SIZE || size >= (1UL << PAGE_SHIFT << MAX_ORDER)) { printk(KERN_WARNING "Invalid huge page size specified\n"); -- Regards, Vignesh Babu BM _ "Why is it that every time I'm with you, makes me believe in magic?" - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[KJ][PATCH] is_power_of_2 in ia64mm
Replacing (n (n-1)) in the context of power of 2 checks with is_power_of_2 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c index 0c7e94e..0ccc70e 100644 --- a/arch/ia64/mm/hugetlbpage.c +++ b/arch/ia64/mm/hugetlbpage.c @@ -16,6 +16,7 @@ #include linux/smp_lock.h #include linux/slab.h #include linux/sysctl.h +#include linux/log2.h #include asm/mman.h #include asm/pgalloc.h #include asm/tlb.h @@ -175,7 +176,7 @@ static int __init hugetlb_setup_sz(char *str) tr_pages = 0x15557000UL; size = memparse(str, str); - if (*str || (size (size-1)) || !(tr_pages size) || + if (*str || !is_power_of_2(size) || !(tr_pages size) || size = PAGE_SIZE || size = (1UL PAGE_SHIFT MAX_ORDER)) { printk(KERN_WARNING Invalid huge page size specified\n); -- Regards, Vignesh Babu BM _ Why is it that every time I'm with you, makes me believe in magic? - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/