⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 select.txt

📁 一个通讯程序源码
💻 TXT
📖 第 1 页 / 共 2 页
字号:
NOTE from ...!gatech!emory!tridom!wht:the following is the mail message I originally received; witha little tinkering, i got the select call to behave as advertisedin the BSD manual (my xenix is 386 2.3).  Added it to /lib/386/Slibx.aand all is well for me.  Good luck.From emory!gatech!hubcap!ncrcae!ncr-sd!crash!elgar!ag Thu Feb  2 13:04:07 EST 1989Article 4851 of comp.unix.xenix:Path: tridom!emory!gatech!hubcap!ncrcae!ncr-sd!crash!elgar!ag>From: ag@elgar.UUCP (Keith Gabryelski)Newsgroups: comp.unix.xenixSubject: select() on SCO XENIX 2.3.Message-ID: <38@elgar.UUCP>Date: 24 Jan 89 04:54:17 GMTReply-To: ag@elgar.UUCP (Keith Gabryelski)Organization: Elgar Corporation, San Diego, CALines: 474A few days ago I was paging through my SCO XENIX 2.3.1 Release Notesand found, on page 44 (section 16), a section describing 4BSDenhancements to the current release of SCO XENIX.select(S) was mentioned specifically.I checked the rest of the 2.3 manuals to see if there was a clue onhow to access select(); no dice.  I tried my 2.2 dev sys libraries tosee if it had been supported in previous releases and just notmentioned; negative.I decided to see if I could get select() to work on my system.  Andthat is what this article is about.I checked /xenix and found:	% nm xenix | grep select	nm: xenix: too many symbols to sort		# chuckle	0020:00015bec  T _selectBingo!  I also found <sys/select.h> (which has a comment aboutthe select(2) system call. :-) ).When a system call is made in a C program on a Unix system (egopen(2)), it actually links in a file from libc.a (/lib/libc.a) (inthis case `open.o') written in assembly that loads a register with asystem call number and causes an exception to occur.  The `trap'instruction is used on the 68000, on a vax it's `chmk', and on a 370it's `svc'.  Control is transfered to the kernel which (in the case ofthis particular exception) will index the register into a table(called the sysent table) to get the address of the actual routine inkernel memory to call (_open).At least under SCO XENIX this algorithm is modified somewhat.When a system call is made in a C program on a SCO XENIX system (egopen(S)), it links in a file from libc.a (/lib/386/Slibc.a) (in thiscase `open.o') written in assembly that loads the register `eax' witha system call number and jumps to 7:0 which (a guess) is mapped to aninstruction that switches into supervisory mode and jumps to theroutine ioint (??) in the kernel address space.  The interrupt routinehands the system call number (along with the user given arguments) to_trap with figures out what to sysent table to use (there are a fewunder SCO XENIX) and does the right thing.The _open routine (in libc.a's open.o) would probably look somethinglike:;; open - open a file for reading or writing;	title	open	.386SYSNUM	equ 	5			; open's system call number is `5'.extrn	_errno:dwordpublic  _open_TEXT	segment  dword use32 public 'CODE'	assume   cs: _TEXT_open	proc near	mov	eax, SYSNUM		; Get system call number.	;	; I don't even pretend to understand masm syntax.  I tried	; the following line (and variations) without any success.	;;	call    far 7:0			; Switch to kernel and call SYSNUM.	;	; Don't laugh, it works.	;	db 9ah	dw 0,0	dw 7	jb	short _cerror		; below == error.	xor	eax, eax		; zero return value (no error).	ret				; done._cerror:	mov	_errno, eax		; Save error code in _errno.	mov	eax, -1			; Return -1 (as error).	ret				; done._open	endp_TEXT	ends	endUnder SCO XENIX the sysent table (struct sysent in <sys/systm.h>) lookssomething like:struct sysent{    unsigned char  sy_ret;	 /* Type of return value (int, void ...) */    unsigned char  sy_arg386;	 /* Number of 386 words args on stack */    unsigned char  sy_nlarg286;	 /* # of 286 large model word args on stack */    unsigned char  sy_nmarg286;	 /* 286 Small Middle: max # of args */    unsigned	   sy_argmask;	 /* Argument types on stack. */	     int   (*sy_call)(); /* System call address in kernel */}sy_ret is the type return of the value this system call returns.  `0'seems to be INT and `6' is probably void.sy_arg386 is the number of words the arguments for this system calltake on the stack.sy_nlarg286 and sy_nmarg286 are similar to sy_arg386 but used fordoing 286 stuff.  I don't plan on mentioning the 286 stuff in thisarticle that much, it just isn't interesting to me.sy_argmask is the type of args on the stack using the following table:NUM | SYMBOL  | 386 | 286L | EXPLANATION 0  |         |     |      | Arg not used. 1  | DATAP   |	 2  |  1   | Arg is a data pointer; seg + address 2  | TEXTP   |	 2  |  1   | Arg is a text pointer; seg + address 3  | CONST   |	 1  |  1   | Arg is an int-sized constant  4  | UCONST  |	 1  |  1   | Arg is an unsigned int-sized constant 5  | LCONST  |  1  |  1   | Arg is a long-sized constant 6  | FDATAP  |	 1  |  1   | Arg is FAR data pointer. 7  | SODATAP |  2  |      | 386: 32-bit offset.    |         |     |  1   | 286: low word is 16 bit data pointer offset,    |         |	    |      |	  high word is 16 bit selector. 8  | SOTEXTP |  2  |      | 386: 32-bit offset.    |         |     |  1   | 286: low word is 16 bit text pointer offset,    |         |	    |      |	  high word is 16 bit selector.Each nybble in sy_argmask represents one argument passed to the systemcall.  Bits 0-3 represent arg one; 4-7 arg two; 8-12 arg three; etc.A total of eight arguments (4 bits times 8 args = 32 bits in an int)can be passed to a function (although MASK, a macro used to makesysent's sy_argmask field is limited to six arguments).NUM is the number (put in each nybble) represented by the SYMBOL (in<sys/systm.h>) that corresponds to the arg type EXPLANATION and takes[386|286] (depending on the model you are using) words on the userstack.So, for the open() system call: sy_argmask is 0x00000331 and sy_arg386is 0x04.	open(char *path, int oflag, int mode);             ^^^^^^      ^^^        ^^^             DATAP       CONST      CONSTsy_call is the pointer to the function in kernel memory that shouldhandle this system call request.The sysent table on my system looks something like:Syscal Num | ret| 386| L  | SM |    Arg Types    | System Call sysent:    00     | 00 | 00 | 00 | 03 | 0 0 0 0 0 0 0 0 | _nosys    01     | 00 | 02 | 01 | 05 | 0 0 0 0 0 0 0 1 | _rexit    02     | 00 | 00 | 00 | 03 | 0 0 0 0 0 0 0 0 | _fork	    03     | 00 | 04 | 03 | 03 | 0 0 0 0 0 4 1 3 | _read	    04     | 00 | 04 | 03 | 03 | 0 0 0 0 0 4 1 3 | _write    05     | 00 | 04 | 03 | 03 | 0 0 0 0 0 3 3 1 | _open	    06     | 00 | 01 | 01 | 03 | 0 0 0 0 0 0 0 3 | _close    07     | 00 | 00 | 00 | 03 | 0 0 0 0 0 0 0 0 | _wait	    08     | 00 | 03 | 02 | 03 | 0 0 0 0 0 0 3 1 | _creat	    09     | 00 | 04 | 02 | 03 | 0 0 0 0 0 0 1 1 | _link	    0a     | 00 | 02 | 01 | 03 | 0 0 0 0 0 0 0 1 | _unlink	    0b     | 00 | 04 | 02 | 03 | 0 0 0 0 0 0 1 1 | _exec    0c     | 00 | 02 | 01 | 03 | 0 0 0 0 0 0 0 1 | _chdir	    0d     | 00 | 00 | 00 | 05 | 0 0 0 0 0 0 0 0 | _gtime    0e     | 00 | 04 | 03 | 03 | 0 0 0 0 0 3 3 1 | _mknod           0f     | 00 | 03 | 02 | 03 | 0 0 0 0 0 0 3 1 | _chmod           10     | 00 | 04 | 03 | 03 | 0 0 0 0 0 3 3 1 | _chown           11     | 00 | 02 | 01 | 03 | 0 0 0 0 0 0 0 7 | _brk    12     | 00 | 04 | 02 | 03 | 0 0 0 0 0 0 1 1 | _stat    13     | 00 | 04 | 03 | 05 | 0 0 0 0 0 3 5 3 | _seek     14     | 00 | 00 | 00 | 03 | 0 0 0 0 0 0 0 0 | _getpid          15     | 00 | 05 | 03 | 03 | 0 0 0 0 0 3 1 1 | _smount          16     | 00 | 02 | 01 | 03 | 0 0 0 0 0 0 0 1 | _sumount         17     | 00 | 01 | 01 | 03 | 0 0 0 0 0 0 0 4 | _setuid          18     | 00 | 00 | 00 | 03 | 0 0 0 0 0 0 0 0 | _getuid          19     | 00 | 02 | 01 | 03 | 0 0 0 0 0 0 0 5 | _stime           1a     | 00 | 05 | 04 | 03 | 0 0 0 0 3 1 3 3 | _ptrace          1b     | 00 | 01 | 01 | 04 | 0 0 0 0 0 0 0 3 | _alarm           1c     | 00 | 03 | 02 | 03 | 0 0 0 0 0 0 1 3 | _fstat           1d     | 00 | 00 | 00 | 03 | 0 0 0 0 0 0 0 0 | _pause           1e     | 00 | 04 | 02 | 03 | 0 0 0 0 0 0 1 1 | _utime           1f     | 00 | 03 | 02 | 03 | 0 0 0 0 0 0 1 3 | _stty            20     | 00 | 03 | 02 | 03 | 0 0 0 0 0 0 1 3 | _gtty            21     | 00 | 03 | 02 | 03 | 0 0 0 0 0 0 3 1 | _saccess         22     | 00 | 01 | 01 | 03 | 0 0 0 0 0 0 0 3 | _nice            23     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 |    24     | 00 | 00 | 00 | 03 | 0 0 0 0 0 0 0 0 | _sync            25     | 00 | 02 | 02 | 03 | 0 0 0 0 0 0 3 3 | _kill            26     | 00 | 00 | 01 | 00 | 0 0 0 0 0 0 0 0 |                  27     | 00 | 00 | 02 | 00 | 0 0 0 0 0 0 0 0 |                  28     | 00 | 00 | 03 | 00 | 0 0 0 0 0 0 0 0 |                  29     | 00 | 02 | 02 | 03 | 0 0 0 0 0 0 3 3 | _dup             2a     | 00 | 00 | 00 | 03 | 0 0 0 0 0 0 0 0 | _pipe            2b     | 00 | 02 | 01 | 05 | 0 0 0 0 0 0 0 1 | _times           2c     | 06 | 08 | 05 | 03 | 0 0 0 1 4 8 4 1 | _profil          2d     | 00 | 01 | 01 | 03 | 0 0 0 0 0 0 0 3 | _lock            2e     | 00 | 01 | 01 | 03 | 0 0 0 0 0 0 0 4 | _setgid          2f     | 00 | 00 | 00 | 03 | 0 0 0 0 0 0 0 0 | _getgid          30     | 00 | 03 | 02 | 02 | 0 0 0 0 0 0 2 3 | _ssig            31     | 00 | 00 | 01 | 03 | 0 0 0 0 0 0 0 3 | _msgsys          32     | 06 | 07 | 04 | 03 | 0 0 0 0 5 5 1 3 | _sysi86          33     | 00 | 02 | 01 | 03 | 0 0 0 0 0 0 0 1 | _sysacct         34     | 00 | 00 | 01 | 06 | 0 0 0 0 0 0 0 3 | _shmsys          35     | 00 | 00 | 01 | 03 | 0 0 0 0 0 0 0 3 | _semsys          36     | 00 | 04 | 03 | 03 | 0 0 0 0 0 7 3 3 | _ioctl           37     | 00 | 00 | 04 | 00 | 0 0 0 0 0 0 0 0 |                  38     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 | _nosys           39     | 00 | 00 | 05 | 00 | 0 0 0 0 0 0 0 0 |                  3a     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 | _nosys           3b     | 00 | 06 | 03 | 03 | 0 0 0 0 0 1 1 1 | _exece           3c     | 00 | 01 | 01 | 03 | 0 0 0 0 0 0 0 3 | _umask           3d     | 00 | 02 | 01 | 03 | 0 0 0 0 0 0 0 1 | _chroot          3e     | 00 | 00 | 06 | 00 | 0 0 0 0 0 0 0 0 |                  3f     | 00 | 00 | 07 | 00 | 0 0 0 0 0 0 0 0 |                  40     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 | _nosys           41     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 | _nosys           42     | 00 | 00 | 00 | 00 | 0 0 0 0 0 0 0 0 | _nosys       

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -