Linux-Development-Sys Digest #709, Volume #8 Thu, 10 May 01 10:13:12 EDT
Contents:
Writing a SystemCall (Frank)
Re: Multiple processes using the curses library (Bernd Strieder)
Re: why a separate process for each thread on Linux (Jonathan Buzzard)
Re: InterlockedIncrement(), InterlockedDecrement() ? (Vyacheslav Burdjanadze)
Re: How to unblocking a thread blocked on an accept() ( try 2 ) (Vyacheslav
Burdjanadze)
Re: user memory locked down to kernel pages? (Robert Kaiser)
file ops (Vyacheslav Burdjanadze)
Re: user memory locked down to kernel pages? ("Ralf Render")
Re: serial port autodetection (Josef Moellers)
Re: Checking if a pointer is valid (Kasper Dupont)
Re: file ops (Kasper Dupont)
Re: serial port autodetection (Villy Kruse)
double fault (Werner Kuehnert)
Re: Multiple processes using the curses library (Christopher Wong)
Re: serial port autodetection (Greg Copeland)
Re: How to unblocking a thread blocked on an accept() ( try 2 ) (Greg Copeland)
Re: why a separate process for each thread on Linux (Greg Copeland)
Re: why a separate process for each thread on Linux (Greg Copeland)
----------------------------------------------------------------------------
From: Frank <[EMAIL PROTECTED]>
Subject: Writing a SystemCall
Date: Thu, 10 May 2001 00:03:16 -0700
Hi,
I'm having trouble compiling a system call. I was wondering if anyone
could figure out what am I doing wrong. So, here are all the steps:
1) write a function called processinfo.c
#include <linux/kernel.h>
#include <linux/sched.h>
#include <asm/current.h>
#include <asm/uaccess.h>
asmlinkage void sys_getProcessInfo(int *pid, int *uid, int *groupid, int
*start_time)
{
copy_to_user(pid, ¤t->pid, sizeof(current->pid));
copy_to_user(groupid, ¤t->gid, sizeof(current->gid));
copy_to_user(uid, ¤t->uid, sizeof(current->uid));
copy_to_user(pid, ¤t->start_time, sizeof(current->start_time));
return;
}
2) Then, I copied this file to the /usr/src/linux/kernel directory.
3) Then, I go to a terminal window and went into superuser mode and
typed this commandline:
gcc -O0 -g3 -Wall -c processinfo.c
4) At this point, I'm getting a lot of parse and referencing errors.
So, from the steps above, what did I forget to do? Am I supposed to
write to generate the stub(s) first before I write the functions?
Frank
TIA
------------------------------
From: Bernd Strieder <[EMAIL PROTECTED]>
Crossposted-To: comp.os.linux.development.apps
Subject: Re: Multiple processes using the curses library
Date: Thu, 10 May 2001 09:16:42 +0200
"Alex Brown (bee3_00)" wrote:
>
> I am trying to write a program that runs under a vt100 terminal which splits the
> screen into two smaller ones using the curses library. I want the display in
> each window to be from seperate processes - one is the original program the
> other is a child that is created by using fork().
>
> At the moment I am having difficulty in getting the two processes to share the
> terminal screen despite having non-overlapping subwindows. I have used the
> newwin() command from curses to make each window with different sizes and
> co-ordinates from within each process. For some reason the child process stops
> running when it initialises the screen using newwin().
>
> Can anyone suggest a way around this? Many thanks in advance.
You have to write some kind of server that listens to clients what they
want to display. The server forks the two clients and receives via an
protocol you have to design the data to be displayed. I don't know
whether it's possible to put ncurses data into shared memory with
reasonable effort. This might make it easier than really designing a
protocol yourself.
What usually is done in apps of that kind, the curses process does all
the UI stuff and forks child processes to do the actual work.
Wait a moment. There is an app called "screen" doing something similar,
perhaps you could look at it. "man 1 screen"
HTH
Bernd Strieder
------------------------------
From: [EMAIL PROTECTED] (Jonathan Buzzard)
Subject: Re: why a separate process for each thread on Linux
Date: Thu, 10 May 2001 08:54:39 +0100
In article <9dc8nk$[EMAIL PROTECTED]>,
[EMAIL PROTECTED] (Alexander Viro) writes:
[SNIP]
> Let's see. By that logics we would have to implement
> * streams (every Missed'em'V out there)
> * doors (Solaris)
> * environment-dependent symlinks (dual-universe monsters)
> * mpx (remember that v7 misfeature?)
> * /dev/poll (SGI barfball)
> * several mutually incompatible variants of devfs
> * logicals (Vomit Making System)
> * drive letters (DEC-derived systems, including CP/M branch)
> * AST (VMS)
> I can easily continue, but I think you already see what I mean.
>
What's wrong with Logicals? Besides Linux seems to have aquired a LVM.
They are sort of handy with resizeble filesystems.
JAB.
--
Jonathan A. Buzzard Email: [EMAIL PROTECTED]
Northumberland, United Kingdom. Tel: +44(0)1661-832195
------------------------------
Date: Thu, 10 May 2001 13:14:00 +0400
From: Vyacheslav Burdjanadze <[EMAIL PROTECTED]>
Subject: Re: InterlockedIncrement(), InterlockedDecrement() ?
> Are there any equivalents of the Windows functions
> InterlockedIncrement() and InterlockedDecrement, under Linux ?
Yes, you may use atomic_t when in kernel or write your own using
POSIX mutexes
------------------------------
Date: Thu, 10 May 2001 13:16:50 +0400
From: Vyacheslav Burdjanadze <[EMAIL PROTECTED]>
Subject: Re: How to unblocking a thread blocked on an accept() ( try 2 )
> I have a thread blocked on an accept() call. I'd like to wake it up from
> another thread. How do I do that ?
> Under WIN32, I just close the socket, and the accept() returns with an
> error code.
It also SHOULD work inder Linux. Try to shutdown(2). If this doesn't
help, interrupt
system call by raising signal
------------------------------
From: [EMAIL PROTECTED] (Robert Kaiser)
Subject: Re: user memory locked down to kernel pages?
Date: 10 May 2001 08:23:38 GMT
In article <9daplm$bmv$[EMAIL PROTECTED]>,
"Ralf Render" <[EMAIL PROTECTED]> writes:
> Thanks Mike.
>
> Can I call "mlock()" in kernel mode?
>
It is possible, but it requires a kernel modification:
[I guess you are already aware that a contiguous piece
of user memory corresponds to a number of non-contiguous
pages in physical memory. Thus your PCI busmaster must do
scatter/gather DMA.]
* mlock() is a superuser-only call. Therefore the mlock()
code in the kernel checks the user ID of the current
process. If it is not 0, mlock() returns an error.
You have to avoid this check if you call mlock() in
kernel mode.
* mlock() only ensures that the pages you lock with it
_remain_ physically present, but it does not make sure
that they _become_ physically present in the first place.
If an application malloc()s a chunk of user memory,
most of that memory will not be physically present, but
is instead mapped to an invalild page. Once your
application attempts to write to it, the resulting page
fault prompts the system to allocate a physical page and
map it. (This is called "copy on write" or COW). Of course,
this COW mechanism only works if the processor tries to access
the invalid page. If a DMA controller (e.g. a PCI busmaster)
does the access, it won't work.
Therefore, after mlock()ing, you must make sure that you have
the processor write to each of the mlock()ed pages at least once.
I have implemented all this for the 2.0 and 2.2 kernels. The
patch can be found at ftp://ftp.sysgo.de/pub/Linux. Since the
2.4 kernel now has kiobufs, I saw no reason to port my patch
to 2.4 (though I suspect it would be quite easy).
Cheers
Rob
================================================================
Robert Kaiser email: rkaiser AT sysgo DOT de
SYSGO RTS GmbH http://www.elinos.com
Klein-Winternheim / Germany http://www.sysgo.de
------------------------------
Date: Thu, 10 May 2001 13:23:44 +0400
From: Vyacheslav Burdjanadze <[EMAIL PROTECTED]>
Subject: file ops
When I tried to add logging in my kernel module I noticed there is no
just open() call in kernel (or probably i missed something). Then I used
filp_open() and then filp->f_op->write() and such stuff. But these calls
report me -EFAULT. I found I need set_fs(KERNEL_DS) before calling
write(). Why I need to do this when my data already in kernel? Why
set_fs is named set_fs ?
------------------------------
From: "Ralf Render" <[EMAIL PROTECTED]>
Subject: Re: user memory locked down to kernel pages?
Date: Thu, 10 May 2001 11:54:10 +0200
Reply-To: "Ralf Render" <[EMAIL PROTECTED]>
Thank you all for your advice.
It works!
What I do is first lock the memory in user mode (by mlock()) and then run in
kernel mode through the page tables and feed my PCI busmaster
(scatter/gather dma).
That's the solution without modifying the kernel.
To avoid the user-kernel mode switch when locking in user mode in future I
will have a look at kernel 2.4.x (kiobufs). Thanks Rob.
------------------------------
From: Josef Moellers <[EMAIL PROTECTED]>
Subject: Re: serial port autodetection
Date: Thu, 10 May 2001 12:57:25 +0200
Greg Copeland wrote:
> =
> Back in the days of BBSs, we used to assume that the first characters
> received would be a space or cr. So, we set a default baudrate and
> cycled through them until we got a hit. We always assumed N81, otherwi=
se
> it got to complex to do reliably with a standard UART used in PCs.
> =
> I guess if you think you really need to do this and you can ensure the
> first value that is recieved, repeatedly until you can "sync", you coul=
d
> make a table of possible values for each "hit". Once you had a hit, th=
en
> you'd be able to exclude a vast majority of the possible values. From =
the
> hits, you could infer the current setting. You could then repeat until=
> you were able to sync. Not sure how reliable this would be though.
I can't recall where I've seen this, but if you can somehow agree on a
first character, you might want to check what this character might look
like when sent with baud rate A and received with baud rate B.
Under the assumption that at least you have 8 bits/character, the format
of a "frame" is
--------+ +----+----+----+----+----+----+----+----+----+--...
| | | | | | | | | |
+----+----+----+----+----+----+----+----+----+
The vertically separated sections are single bits, the first one is the
"start bit", the next one is bit 8 of the character transmitted, then
comes bit 7 etc. After bit 0 there comes the "stop bit" which is 1, 1.5
or 2 bits long (1 bit with 8n1).
Now, if the transmission speed is higher than the reception speed and
the highest bit of the character is not set (the bits are shown
inverted), the receiver will probably miss that frame, because the start
bit is too short (receivers are very picky about wanting to see a start
bit).
If the transmission speed is lower than the reception speed, the start
bit (and the high bits of the payload) will smear out into the following
bits, e.g. if you transmitted a space character (0x20) at half the speed
of the receiver, the transmitter will send:
--------+ +----+----+ +----+----+----+----+----+----+--...
| | | |
+----+ +----+
Since the receiver expects the bits at double the speed, it samples the
line at twice the rate and sees two bits where one was sent:
--------+ +----+----+----+----+ +----+----+---
| | | |
+----+----+ +----+----+
Which is a 0x86. At four times the speed, it would see a 0xe0 followed
by a 0xfe after 2 bits of idle time on the line.
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
From: Kasper Dupont <[EMAIL PROTECTED]>
Subject: Re: Checking if a pointer is valid
Date: Thu, 10 May 2001 13:00:33 +0200
Andrew Murphy wrote:
>
> Hi,
> Does any one know how to check if a pointer is valid in Linux C. I am
> trying to simulate the windows IsBadReadPtr and IsBadWritePtr functions.
> Any help appreciated.
> Thanks
> Andy
One solution would be to just try the opperation and
have a handler for SIGSEGV to skip the opperation in
case of fault. The skip can be done by using longjmp
or changing the return address.
--
Kasper Dupont
------------------------------
From: Kasper Dupont <[EMAIL PROTECTED]>
Subject: Re: file ops
Date: Thu, 10 May 2001 13:38:21 +0200
Vyacheslav Burdjanadze wrote:
>
> When I tried to add logging in my kernel module I noticed there is no
> just open() call in kernel (or probably i missed something). Then I used
> filp_open() and then filp->f_op->write() and such stuff. But these calls
> report me -EFAULT. I found I need set_fs(KERNEL_DS) before calling
> write(). Why I need to do this when my data already in kernel? Why
> set_fs is named set_fs ?
Using filp_open() and filp->f_op->write(filp,...) is the
way to do this in kernel space.
Usualy the write function expects data to be in user
space, if the pointer given is not a valid userspace
pointer for the current process you get -EFAULT. It
is the same that would happen if a userspace process
tried to write kernel pages into a file.
I think the reason for the name set_fs is that this
function sets the CPUs FS register. This is a segment
selector, it is usually set to a selector that only
allows access to userspace in the start of the
linear address space. When you change it to KERNEL_DS
the selector now allows access to the entire linear
address space including both userspace and kernelspace.
--
Kasper Dupont
------------------------------
From: [EMAIL PROTECTED] (Villy Kruse)
Subject: Re: serial port autodetection
Date: 10 May 2001 12:18:30 GMT
On Thu, 10 May 2001 12:57:25 +0200,
Josef Moellers <[EMAIL PROTECTED]> wrote:
>
>I can't recall where I've seen this, but if you can somehow agree on a
>first character, you might want to check what this character might look
>like when sent with baud rate A and received with baud rate B.
>Under the assumption that at least you have 8 bits/character, the format
>of a "frame" is
>
The new (back then) System V rel4 replacement for getty, perhaps.
Worked for 1200, 2400, and 9600 and possible a few other posibilities.
Villy
------------------------------
From: [EMAIL PROTECTED] (Werner Kuehnert)
Subject: double fault
Date: Thu, 10 May 2001 12:30:43 +0000 (UTC)
Hi all,
can anyone give me a hint how to detect the reason for a double fault ?
TIA
Werner K�hnert
--
E-Mail: [EMAIL PROTECTED]
------------------------------
From: [EMAIL PROTECTED] (Christopher Wong)
Crossposted-To: comp.os.linux.development.apps
Subject: Re: Multiple processes using the curses library
Date: Thu, 10 May 2001 12:31:10 GMT
On Wed, 09 May 2001 16:14:25 +0100, Alex Brown (bee3_00)
<[EMAIL PROTECTED]> wrote:
>I am trying to write a program that runs under a vt100 terminal which
>splits the screen into two smaller ones using the curses library. I
>want the display in each window to be from seperate processes - one is
>the original program the other is a child that is created by using
>fork().
>
>At the moment I am having difficulty in getting the two processes to
>share the terminal screen despite having non-overlapping subwindows. I
>have used the newwin() command from curses to make each window with
>different sizes and co-ordinates from within each process. For some
>reason the child process stops running when it initialises the screen
>using newwin().
>
>Can anyone suggest a way around this? Many thanks in advance.
Search for "twin" on Freshmeat.net. Description: "Twin is a text-mode
window environment. It turns a text terminal into a X11-style display
with window manager, terminal windows, and can also serve as display for
remote applications. Each terminal window provides the functions of a
text-mode Linux console. ..."
Chris
------------------------------
Subject: Re: serial port autodetection
From: Greg Copeland <[EMAIL PROTECTED]>
Date: 10 May 2001 08:47:11 -0500
Josef Moellers <[EMAIL PROTECTED]> writes:
> Greg Copeland wrote:
> >
[snip]
> >
> > I guess if you think you really need to do this and you can ensure the
> > first value that is recieved, repeatedly until you can "sync", you could
> > make a table of possible values for each "hit". Once you had a hit, then
> > you'd be able to exclude a vast majority of the possible values. From the
> > hits, you could infer the current setting. You could then repeat until
> > you were able to sync. Not sure how reliable this would be though.
>
> I can't recall where I've seen this, but if you can somehow agree on a
> first character, you might want to check what this character might look
> like when sent with baud rate A and received with baud rate B.
> Under the assumption that at least you have 8 bits/character, the format
> of a "frame" is
That's exactly what I was talking about. The idea is that you can make a table
of these possible baud rate/bit deltas. Assuming that you can have a collision
on a "hit" you'll need to be able to excluding some of the possible entries,
which in turn might exclude some possible baud rate settings. The idea, is that
it will allow you to sync faster by being able to exclude some of the others.
At any rate, you clearly understand the concept.
--
Greg Copeland, Principal Consultant
Copeland Computer Consulting
==================================================
PGP/GPG Key at http://www.keyserver.net
DE5E 6F1D 0B51 6758 A5D7 7DFE D785 A386 BD11 4FCD
==================================================
------------------------------
Subject: Re: How to unblocking a thread blocked on an accept() ( try 2 )
From: Greg Copeland <[EMAIL PROTECTED]>
Date: 10 May 2001 08:54:11 -0500
Since you are using threads, pthreads I'll assume, using signals is
somewhat iffy. The other thing you can do is to select on the socket
that you want to accept which should indicate when it's ready for you
to actually accept on it. In other words, create the socket, bind to
it, then select on it. When select returns with the correct status,
you now know you need to accept the connection.
I think you can also put it into non-blocking mode and poll using
accept.
You may also try using the shutdown() function to shutdown the
socket, but I honestly don't know if this will work for you.
Greg
Vyacheslav Burdjanadze <[EMAIL PROTECTED]> writes:
> > I have a thread blocked on an accept() call. I'd like to wake it up from
> > another thread. How do I do that ?
> > Under WIN32, I just close the socket, and the accept() returns with an
> > error code.
> It also SHOULD work inder Linux. Try to shutdown(2). If this doesn't
> help, interrupt
> system call by raising signal
--
Greg Copeland, Principal Consultant
Copeland Computer Consulting
==================================================
PGP/GPG Key at http://www.keyserver.net
DE5E 6F1D 0B51 6758 A5D7 7DFE D785 A386 BD11 4FCD
==================================================
------------------------------
Subject: Re: why a separate process for each thread on Linux
From: Greg Copeland <[EMAIL PROTECTED]>
Date: 10 May 2001 09:02:17 -0500
Doesn't using clone() has a list of issues by it self. Like some
of the libraries may not work as expected and a list of other items.
Last I heard, and I believe it was from Xavier, clone() should not
be used unless you are absolutly sure you need to use and have the
time to implement all of the things that threads already do for
you. Sure wish I could remember what all was on this list, but
for some reason I simply filed it in my head as don't use this
call.
I know that's not very helpful, but maybe someone can pick up
where I left off.
--
Greg Copeland, Principal Consultant
Copeland Computer Consulting
==================================================
PGP/GPG Key at http://www.keyserver.net
DE5E 6F1D 0B51 6758 A5D7 7DFE D785 A386 BD11 4FCD
==================================================
------------------------------
Subject: Re: why a separate process for each thread on Linux
From: Greg Copeland <[EMAIL PROTECTED]>
Date: 10 May 2001 09:07:29 -0500
[EMAIL PROTECTED] writes:
> That would mean each thread would have to have a stack allocation
> within the address space to grow in, and this would all have to
> come from a subset of the one address space all threads run in.
> If you are allocating arrays within the stack space (e.g. alloca()),
> then your stack space needs will be quite high, potentially. The
> allocation of stack space itself will have to accomodate that,
> perhaps with no advance knowledge of the space needs.
Many thread implementations use the concept of page guarding on the
stack to detect when it needs to grow. That is, when a read-only
page is attempted to be written to, that is the highest point on
the stack, you know it needs to grow. Now, the next step is to
grow the stack logarithmically which means you shouldn't have to
grow it many more times.
--
Greg Copeland, Principal Consultant
Copeland Computer Consulting
==================================================
PGP/GPG Key at http://www.keyserver.net
DE5E 6F1D 0B51 6758 A5D7 7DFE D785 A386 BD11 4FCD
==================================================
------------------------------
** FOR YOUR REFERENCE **
The service address, to which questions about the list itself and requests
to be added to or deleted from it should be directed, is:
Internet: [EMAIL PROTECTED]
You can send mail to the entire list by posting to the
comp.os.linux.development.system newsgroup.
Linux may be obtained via one of these FTP sites:
ftp.funet.fi pub/Linux
tsx-11.mit.edu pub/linux
sunsite.unc.edu pub/Linux
End of Linux-Development-System Digest
******************************