Forum Settings
       
Reply To Thread

Structs and Kernels can go diaf.Follow

#1 Dec 08 2012 at 7:40 PM Rating: Decent
It's Just a Flesh Wound
******
22,697 posts
They are evil, and they should be ashamed that they exist.
____________________________
Dear people I don't like: 凸(●´―`●)凸
#2 Dec 08 2012 at 9:15 PM Rating: Decent
It's Just a Flesh Wound
******
22,697 posts
Also doing file IO in the kernel is just bad. Imagine if a programming language had almost no documentation, and then imagine that the thing you're trying to do is also considered normally taboo.
____________________________
Dear people I don't like: 凸(●´―`●)凸
#3 Dec 08 2012 at 10:16 PM Rating: Good
Worst. Title. Ever!
*****
14,940 posts
Being in the automation industry, the amount of my program that actually does things is only at most 10%... the other 90% is interfacing and diagnostics. I spend hours upon hours of my day writing diagnostics programs for my machines that I know will never be used by the people operating the machines (they always come and ask me without even bothering to look).
____________________________
Can't sleep, clown will eat me.
#4 Dec 08 2012 at 11:44 PM Rating: Excellent
Avatar
******
29,901 posts
It's always the ******* semi colon! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Argh!!!!!
____________________________
Arch Duke Kaolian Drachensborn, lvl 95 Ranger, Unrest Server
Tech support forum | FAQ (Support) | Mobile Zam: http://m.zam.com (Premium only)
Forum Rules
#5 Dec 08 2012 at 11:55 PM Rating: Good
Sage
Avatar
**
644 posts
Dread Lörd Kaolian wrote:
It's always the @#%^ing semi colon! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Argh!!!!!


So much hate for the semi colon isn't it's life hard enough w/ colon sitting above it laughing at it's seminess Smiley: frown
____________________________
Pikko wrote:
I can't freaking believe I didn't click this thread earlier. YOU LITTLE TWERPS!!


Wint wrote:
You know, I can click the rate down button more than once Smiley: motz


>>>--Justice-->
#6 Dec 09 2012 at 12:26 AM Rating: Decent
It's Just a Flesh Wound
******
22,697 posts
It took me about ~140 lines to copy a single struct (3x char*, 2x int) into this system call. The struct (or rather a pointer to it) was passed as a parameter of the system call. And I still haven't properly error checked it while bringing it in.

Then for doing **** with file IO I need to do **** with functions inside structs inside structs. And now for encryption I need to use structs again. Smiley: mad

Quote:
It's always the @#%^ing semi colon! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Argh!!!!!

Apparently the only time I forget semi colons is when writing vhdl. I don't think I've ever accidentally forgot one this entire time I've been making this system call. I ****** up parenthesis or brackets a couple of times, but at least I know I did that when emacs starts trying to format tabs incorrectly.
____________________________
Dear people I don't like: 凸(●´―`●)凸
#7 Dec 09 2012 at 10:58 AM Rating: Good
I'm assuming that you're using Linux here. copy_from_user is your friend. If you want to send data the other way, copy_to_user is your other friend.

Yes, doing file IO is not a good idea in kernel space unless you're a file system or disk driver. If you're just looking to log stuff for your development and debugging, use printk (KERN_ERR "Your message", ...). You can see the output by running dmesg from any terminal. Or, what I do is run in a real text terminal and you'll see the output as its generated. For most distros you can press Ctrl+Alt+F1 to switch into a text-mode terminal. Ctrl+Alt+F7 will bring you back to your GUI (X) terminal. (Some of the newer distros have made the 'F1' terminal the GUI terminal. If so just do a Ctrl+Alt+F2 for a text terminal.)

I've been doing kernel mode development for over 10 years in Linux and Windows (and now VxWorks). I've also started writing my own operating system from scratch. I'm kind of a nerd for this kind of stuff.
____________________________
Love,
PunkFloyd
#8 Dec 09 2012 at 12:51 PM Rating: Decent
It's Just a Flesh Wound
******
22,697 posts
Thanks for the advice. Thankfully I discovered how to printk early in. I'm running Linux 3.2.2 i386 on a VM and then I'm ssh'ing in. Everything is set up so that I code on my sys_xcrypt.c and xcipher.c file, run my makefile, sh install_module.sh to unload/load the module, and then ./xcipher blahblah to test it.

I've copied all the data I need from user land into kernel land, and my file IO works correctly. Pretty much all that's left is trying to figure out how to encrypt/decrypt with aes.

Oh and figuring out how to remove partial output files. (I was thinking vfs_unlink, but if I filp_close before or after then I oops.)

And figuring out why "filpout = filp_open(kargz->outfilezname, O_WRONLY | O_CREAT, 00666);" creates a file with user wr, group r, other r permissions. I was copy pasting the infile permissions from its inode struct instead of just hardcoding numbers, but I noticed the permissions weren't actually copying over. edit: Interesting. I can change user r/w/x, group r, others r/x, but it won't let me change group w/x or others w. From the system call that is, if I just chmod everything changes fine.

And then I need to add some extra error checking.. but I think I know what I'm doing there.

Edited, Dec 9th 2012 2:29pm by Deadgye
____________________________
Dear people I don't like: 凸(●´―`●)凸
#9 Dec 09 2012 at 2:15 PM Rating: Decent
It's Just a Flesh Wound
******
22,697 posts
Why does every function call two functions that call two functions that call two functions that call two functions that call two functions. FUSKJCSKS CSYOUFIOSUYFSHKDFKJDHFJKHD SHKAF SFKJFKLDJ. Smiley: motz
____________________________
Dear people I don't like: 凸(●´―`●)凸
#10 Dec 09 2012 at 6:14 PM Rating: Decent
It's Just a Flesh Wound
******
22,697 posts
I nearly finished writing out how I can do my entire encryption/decryption process. I go to figure out what the last unknown variables are, and I find more kernel fun.

static inline struct crypto_blkcipher *crypto_alloc_blkcipher(const char *alg_name, u32 type, u32 mask)

Alright, type and mask are probably flags defined somewhere, let's check the top of the header file.

 27 /* 
 28  * Algorithm masks and types. 
 29  */ 
 30 #define CRYPTO_ALG_TYPE_MASK            0x0000000f 
 31 #define CRYPTO_ALG_TYPE_CIPHER          0x00000001 
 32 #define CRYPTO_ALG_TYPE_COMPRESS        0x00000002 
 33 #define CRYPTO_ALG_TYPE_AEAD            0x00000003 
 34 #define CRYPTO_ALG_TYPE_BLKCIPHER       0x00000004 
 35 #define CRYPTO_ALG_TYPE_ABLKCIPHER      0x00000005 
 36 #define CRYPTO_ALG_TYPE_GIVCIPHER       0x00000006 
 37 #define CRYPTO_ALG_TYPE_DIGEST          0x00000008 
 38 #define CRYPTO_ALG_TYPE_HASH            0x00000008 
 39 #define CRYPTO_ALG_TYPE_SHASH           0x00000009 
 40 #define CRYPTO_ALG_TYPE_AHASH           0x0000000a 
 41 #define CRYPTO_ALG_TYPE_RNG             0x0000000c 
 42 #define CRYPTO_ALG_TYPE_PCOMPRESS       0x0000000f 
 43  
 44 #define CRYPTO_ALG_TYPE_HASH_MASK       0x0000000e 
 45 #define CRYPTO_ALG_TYPE_AHASH_MASK      0x0000000c 
 46 #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK  0x0000000c 
 47  
 48 #define CRYPTO_ALG_LARVAL               0x00000010 
 49 #define CRYPTO_ALG_DEAD                 0x00000020 
 50 #define CRYPTO_ALG_DYING                0x00000040 
 51 #define CRYPTO_ALG_ASYNC                0x00000080


Smiley: motzSmiley: madSmiley: motz

In case you haven't it figured it out yet, this thread is my outlet so I don't punch my monitors.

Edited, Dec 9th 2012 7:15pm by Deadgye
____________________________
Dear people I don't like: 凸(●´―`●)凸
#11 Dec 10 2012 at 11:39 AM Rating: Good
In case you don't know about it, http://lxr.linux.no/+trees is great for finding type definitions, constants, functions, yadda yadda yadda in the kernel. It's usually faster than grepping.

Have fun with the file system stuff. This for an operating system class or something?
____________________________
Love,
PunkFloyd
#12 Dec 10 2012 at 4:43 PM Rating: Decent
Encyclopedia
******
31,711 posts
Deadgye wrote:
Why does every function call two functions that call two functions that call two functions that call two functions that call two functions. FUSKJCSKS CSYOUFIOSUYFSHKDFKJDHFJKHD SHKAF SFKJFKLDJ. Smiley: motz


You know the answer to that, right? I'm assuming that's just venting. There's a reason I try to avoid the kernel level stuff whenever humanly possible (programming that is, kinda can't avoid loading values and modules and whatnot). I've lost enough sanity over my lifetime.
____________________________
King Nobby wrote:
More words please
#13 Dec 10 2012 at 5:33 PM Rating: Decent
It's Just a Flesh Wound
******
22,697 posts
Quote:
In case you don't know about it, http://lxr.linux.no/+trees is great for finding type definitions, constants, functions, yadda yadda yadda in the kernel. It's usually faster than grepping.

Yeah it's an operating systems class, our professor hosted an even better and more complete thing like than on school webspace and I've been using that; I didn't link it because he didn't want us sharing it. I wouldn't have gotten anywhere without using it lol.

Quote:
You know the answer to that, right? I'm assuming that's just venting. There's a reason I try to avoid the kernel level stuff whenever humanly possible (programming that is, kinda can't avoid loading values and modules and whatnot). I've lost enough sanity over my lifetime.

Yeah, it just ****** me off that the standard for comments is no comments "because you should be able to easily tell whats happening by looking at the code" but there's 6 levels of function abstraction and defines to get through. At least @#%^ing say what the parameters are supposed to be. Sometimes I didn't know if I should be passing variable or &variable because it just said "addr" and we're dealing with defines of structs inside structs and sh*t.

After dealing with all this sh*t I'm probably going to stick with computer architecture, hardware is much less infuriating. Designing a basic 3-stage mock ps3 cell-lite pipeline processor in vhdl was so much easier than making a kernel module.

My assignment is pretty much complete by now (~90/100). He extended the deadline by 24 hours so it's due in a little less than 6. My sh*t successfully takes in a password/key, hashes it, and encrypts/decrypts a file. Only things left are figuring out how to get the file inode and parent direction dentry without filp_open so I can delete a file with vfs_unlink, figuring out why I'm reading and writing to files that I don't have permissions for (I'll probably have to error check against permissions in inode?), and figuring out how to properly set permissions when I create a new file. Oh and figuring out how to md5 hash in the user level. I find it funny that I know how to do it in kernel level but don't know how to do it in the user level yet.

Or I can leave it as is and study for my japanese final that's in 23 hours

Edited, Dec 10th 2012 6:36pm by Deadgye
____________________________
Dear people I don't like: 凸(●´―`●)凸
#14 Dec 10 2012 at 6:40 PM Rating: Decent
******
21,717 posts
Deadgye wrote:
Yeah, it just ****** me off that the standard for comments is no comments "because you should be able to easily tell whats happening by looking at the code" but there's 6 levels of function abstraction and defines to get through. At least @#%^ing say what the parameters are supposed to be. Sometimes I didn't know if I should be passing variable or &variable because it just said "addr" and we're dealing with defines of structs inside structs and sh*t.


And that right there is why I've never enjoyed programming in C. Dont' get me wrong, I greatly admire those that are able to wade through the sea of crap and spaghetti code, but C makes it too easy for the average programmer to confuse the **** out of himself and every maintainer that follows. Even good code in C is barely legible, IMHO. Sloppy code is a horror that even "spaghetti" can't define.
____________________________
R.I.P. Jessica M. 5/3/2010
This post brought to you by Carl's Jr.
gbaji wrote:
You guys keep tossing facts out there like they mean something.


#15 Dec 10 2012 at 7:04 PM Rating: Decent
It's Just a Flesh Wound
******
22,697 posts
Normal c programs aren't really that bad. I took a class with this professor last year called Advanced systems programming in unix/c. Our final homework was taking a cryptography program from the early 90s(?) called skey and fixing it. We had to make it run on 6 machines. (centos56, freebsd82, oindiana148, osx411, solaris8, ubuntu104.) I had to fix endianness bugs, stupid code (I ended up commenting out entire functions), make scripts to perform a test during compile to choose which defines to use and if certain libraries need to be or can be included. It was a headache, but it felt like a very good and awesome learning experience. All in all though, it was at worst only half as annoying as dealing with kernel code.
____________________________
Dear people I don't like: 凸(●´―`●)凸
#16 Dec 10 2012 at 11:36 PM Rating: Decent
@#%^ing DRK
*****
13,137 posts
Someone I work with uses far, far, far too many semicolons. We're going to have a chat. It's embarrassing, really!
#17 Dec 10 2012 at 11:55 PM Rating: Excellent
I love using semicolons; they are a lot of fun. I use them in sentences all the time; I find a good semicolon can really be useful. In fact, more people should use semicolons; I do wish, however, that people used them properly.
____________________________
idiggory, King of Bards wrote:
I have a racist ****.

Steam: TuxedoFish
battle.net: Fishy #1649
GW2: Fishy.4129

Reply To Thread

Colors Smileys Quote OriginalQuote Checked Help

 

Recent Visitors: 64 All times are in CDT
Anonymous Guests (64)