Good PyObjc Tutorial
I've been looking for a good PyObjC Tutorial. The official Apple one is ages old and not comprehensive enough.
Fortunately the "An Epic Introduction to PyObjC and Cocoa" tutorial, is indeed an epic introduction to PyObjC and highly recommended for anyone planning to get started with Cocoa development in Python.
Diving into Python
Recently due to a project(I am part of a group building a next generation operating system, which would allow seamless resource sharing on a global scale) complication I decided to ditch a particular component and implement it in another alternative language. I explored various possibilities. The component is a SOAP web service based thing. It was previously implemented in C, using the Axis2/C framework. The initial impetus to use the Axis2/C framework was to make a web service based component which was as fast as possible. But the problem is that Axis2/C is not mature, it hasn't even crossed the 1.0 milestone! The component was riddled with segmentation faults. It only worked in Slackware 10.2! When we upgraded to Slackware 11.0 in our lab, the component stopped working! I spent some 8 hours trying to debug it but to no avail! I finally decided to ditch the component and implement it another language which was more productive than C and didnt have manual memory management. I had numerous alternatives, Java, which I found to be too resource demanding; PERL, the problem with perl was that I am the only one in the team who knows PERL, and I would have to implement everything myself, I finally settled on a combination of Php and Python. I read somewhere that Python had bad performance as compared to php in hosted applications. So I decided that the server side portion of the component is to be php based and the client side portion is python based, and we have ample expertise in the group in both php and python.
With this effort I hope to dive into python and contrast it to Perl, I will write a subjective comparison of the two languages soon.
Adding a System call (linux 2.4.x)
1. About This Document
This document explains a way to add a system call to linux kernel catered to the linux 2.4.x series. It is based on the guide by Worcester Polytechnic Institute available at here. The guide is for linux 2.2.x, some changes where to the cotents to make it a guide for linux 2.4.x. The reference kernel in this guide is linux 2.4.31
A system call is the standard way an OS service is exported to a user program. For example, to provide users a new semaphore like synchronization method, some system calls need to be provided to access it. Likewise, a system call may be used to give users access to internal information of a file system such as superblock or inodes. The following description is based on linux kernel version 2.2.14 on i386 machine architecture. Also, it is assumed that readers are familiar with Building Linux Kernel.
2. Preparing for A New System Call
A system call cannot be called directly from a user process. Instead, they are called indirectly via an interrupt and looked up in an interrupt table. Thus, when you define a new system call you insert a new entry in this table. You do this by editing the file linux/arch/i386/kernel/entry.S. Inside, you should see lines like:
.data
ENTRY(sys_call_table)
.long SYMBOL_NAME(sys_ni_syscall) /* 0 - old "setup()" system call*/
.long SYMBOL_NAME(sys_exit)
.long SYMBOL_NAME(sys_fork)
.long SYMBOL_NAME(sys_read)
.long SYMBOL_NAME(sys_write)
..
..
.long SYMBOL_NAME(sys_ni_syscall) /* sys_set_tid_address* /
After the "sys_ni_syscall" line, add your entries for your new system calls, with the words "sys_" prepended. For example, you might add the following line for your new system call "myservice":
.long SYMBOL_NAME(sys_myservice) /*259 */
You also need to generate a system call "stub" so that an ordinary user program can invoke your system call. You do this by editing the file linux/include/asm/unistd.h (In linux sources) where you will find lines like:
#define __NR_exit 1
#define __NR_fork 2
...
#define __NR_exit_group 252
You should add #defines for your new system calls at the end, with the prefix "__NR_" in front of it. For example, you might add the line:
#define __NR_myservice 259
3. Places for Your System Call Source Files
After inserting your new system call entry in the interrupt table and preparing a stub for it, you will need to define (or implement) the system call. It will be easiest to have the system call definitions in your own source code files, say myservice.h and myservice.c.
In general, header files for machine architecture independent system calls and functions are kept under linux/include/linux/ and machine architecture dependent ones are kept in linux/include/asm/. Therefore, it would be a good idea to follow this convention. For example, the header file for the system calls for your new synchronization method, of which the implementation is machine architecture specific, would be placed in linux/include/asm/, while the header file for your machine architecture independent system call that access the superblock of one or more of your file systems would be placed under linux/include/linux.
The place for actual implementation file (myservice.c in this example) could vary. For example, if you are implementing a new process synchronization method, linux/ipc/ would be the best place for it. If you are implementing a file system related one, linux/fs/ would be the best place.
Remember that you will need to modify the Makefile in the directory you placed your .c file so that your code gets compiled and linked in properly. Modify the Makefile line to have a .o of your source code. For example, adding myservice.o in linux-2.4.31/mm/
obj-y := memory.o mmap.o filemap.o mprotect.o mlock.o mremap.o vmalloc.o slab.o bootmem.o swap.o vmscan.o page_io.o page_alloc.o swap_state.o swapfile.o numa.o oom_kill.o shmem.o myservice.o
The rest of the Makefiles can remain untouched (Makefile changes will be similar if you choose to add your code elsewhere).
4. System Call Source File Basics
In order to be linked properly, your system calls need the word "asmlinkage" prepended to their function header and "sys_" prepended to the name. For example, you would have:
asmlinkage int sys_myservice(int arg1, char* arg2) {
/* implementation of myservice */
}
Also, you will have to have #include so the compiler will recognize the word "asmlinkage".
Lastly, the user "stub" can be automatically generated so that a user program can use your system call. There are some macros defined for this in . The format is "_syscallN(return type, function name, arg1 type, arg1 name ...)" where "N" is the number of parameters. For example, you might have the line:
_syscall2(int, myservice, int, arg1, char*, arg2);
to generate the stub (in this case, the 2 is for 2 arguments). Note, that your call to generate the stub (as above) should be put it in your header file for users(myservice-user.h). Also, you need to #include in myservice-user.h to make this work. A user program could then just call myservice() as they do other system calls.
Here is an example myservice.h, myservice.c, myservice-user.h and user-app.c assuming myservice.h is under linux/include/linux/ and myservice-user.h is under /usr/include/sys/
myservice.h (used within kernel only)#define __LINUX_MYSERVICE_H#include
#endif |
myservice.c (system call implementation)asmlinkage int sys_myservice (int arg1, char* arg2) {printk("My Service Called"); |
myservice-user.h (for user application)#include_syscall2(int, myservice, int, arg1, char*, arg2); |
user-app.c (user application)main() {myservice(1, "hi"); |
Feed
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jan | ||||||
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 | |
Archives
- January 2010
- December 2009
- November 2009
- October 2009
- July 2009
- May 2009
- March 2009
- February 2009
- January 2009
- December 2008
- October 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
Categories
- adobe
- apple
- backup
- cluster computing
- clusters
- commercial apps
- Distributed Computing
- economics
- firefox
- FOSS
- grid computing
- industry news
- internet
- iPhone app
- ipod
- kde
- kernel development
- linux
- mac
- macosx
- microsoft
- misc
- mozilla
- n95
- networking
- networks
- open source
- opensuse
- operating systems
- pakistan
- perl
- personal
- podcast
- programming
- python
- safari
- security
- software
- startups
- supercomputing
- ubuntu
- Uncategorized
- virtualization
- web
- Web2
- web2.0
- webservices
- wimax
- windows
- wine