Re: Broadcom BCM4310 / bwi(4) and interface bwi0 is not showing up

2010-11-08 Thread Dmitry Krivenok
I tried your patch, but my laptop hung at startup.
The last line I saw on console was "Timecounters tick every 1.000 msec".

I didn't dig into the problem and don't have any information useful
for debugging, but I'm going
to play with it later today.

Dmitry

On Mon, Oct 25, 2010 at 1:29 PM, Bernhard Schmidt  wrote:
> On Sunday, October 24, 2010 07:25:59 Matthias Apitz wrote:
>> Hello,
>>
>> I have a new laptop Acer Aspire One D250 and I want to install a
>> 8-CURRENT as of CVS from May 2009 (as I use this on all my laptops).
>> The laptop comes with as Wifi chip:
>>
>> no...@pci0:1:0:0:       class=0x028000 card=0xe01b105b chip=0x431514e4
>> rev=0x01 hdr=0x00
>>     vendor     = 'Broadcom Corporation'
>>     device     = 'BCM4310 USB Controller'
>>     class      = network
>>
>> I learned after searching around that it should be supported by bwi(4)
>> and one should install the firmware kmod from the ports. I have in
>> loader.conf:
>> [..]
>
> Please try attached patch, I'm not sure if it is that simple.. worth a try
> though.
>
> --
> Bernhard
>
> ___
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
>



-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


printf doesn't work from kernel modules

2010-11-22 Thread Dmitry Krivenok
Hello Hackers,
Recently I installed 8.1 on my laptop and recompiled the kernel.
The system works fine, but I have a strange problem with my own
trivial kernel module.
I noticed that printf function doesn't produce any output (according to
dmesg) if I call it from a module. Note, that the same module works
perfectly on another 8.1 and CURRENT systems. Moreover, I added
debug message (printf ("Bla bla bla\n");)  in my kernel and found that
it works fine (i.e. works if compiled directly in kernel, but doesn't work
from module). Same effect with stock 8.1 kernel.

I see the same problem with examples in /usr/share/examples/kld.

I don't believe this is a real problem in FreeBSD. I'm sure this is some
kind of configuration issue, but I cannot understand what exactly is wrong.

What could cause such behaviour?
Any ideas?

Thanks!

-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: printf doesn't work from kernel modules

2010-11-22 Thread Dmitry Krivenok
Just tried dys_sysctl. It doesn't work as well.
Below are the results I got:

r...@olimpico-freebsd 22:04:17 /usr/share/examples/kld/dyn_sysctl # [0] uname -a
FreeBSD olimpico-freebsd 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Mon Nov
22 21:35:15 MSK 2010
r...@olimpico-freebsd:/usr/obj/usr/src/sys/GENERIC  i386
r...@olimpico-freebsd 22:04:20 /usr/share/examples/kld/dyn_sysctl # [0] kldstat
Id Refs AddressSize Name
 11 0xc040 bb5504   kernel
r...@olimpico-freebsd 22:04:24 /usr/share/examples/kld/dyn_sysctl #
[0] dmesg | tail -n 3
ums0: 3 buttons and [XYZ] coordinates ID=0
ugen2.2:  at usbus2
em0: link state changed to UP
r...@olimpico-freebsd 22:04:39 /usr/share/examples/kld/dyn_sysctl # [0
0] make load
/sbin/kldload -v /usr/share/examples/kld/dyn_sysctl/dyn_sysctl.ko
Loaded /usr/share/examples/kld/dyn_sysctl/dyn_sysctl.ko, id=2
r...@olimpico-freebsd 22:04:49 /usr/share/examples/kld/dyn_sysctl # [0] kldstat
Id Refs AddressSize Name
 12 0xc040 bb5504   kernel
 21 0xc855d000 3000 dyn_sysctl.ko
r...@olimpico-freebsd 22:04:53 /usr/share/examples/kld/dyn_sysctl #
[0] dmesg | tail -n 3
ums0: 3 buttons and [XYZ] coordinates ID=0
ugen2.2:  at usbus2
em0: link state changed to UP
r...@olimpico-freebsd 22:04:57 /usr/share/examples/kld/dyn_sysctl # [0
0] make unload
/sbin/kldunload -v dyn_sysctl.ko
Unloading dyn_sysctl.ko, id=2
r...@olimpico-freebsd 22:05:04 /usr/share/examples/kld/dyn_sysctl # [0] kldstat
Id Refs AddressSize Name
 11 0xc040 bb5504   kernel
r...@olimpico-freebsd 22:05:07 /usr/share/examples/kld/dyn_sysctl #
[0] dmesg | tail -n 3
ums0: 3 buttons and [XYZ] coordinates ID=0
ugen2.2:  at usbus2
em0: link state changed to UP
r...@olimpico-freebsd 22:05:09 /usr/share/examples/kld/dyn_sysctl # [0 0]

Please note that I run standard example on default 8.1 kernel (GENERIC).

Dmitry

>
> Which example did you try and run (it looks like the dyn_sysctl test
> would be a good one to try)?
> -Garrett
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: Simple kernel attack using socketpair.

2010-11-26 Thread Dmitry Krivenok
I run it on 8.0 and CURRENT and got fatal double fault on both systems:


Unread portion of the kernel message buffer:
kern.maxfiles limit exceeded by uid 1001, please see tuning(7).

Fatal double fault
rip = 0x80615f54
rsp = 0xff803c1fa000
rbp = 0xff803c1fa000
cpuid = 0; apic id = 00
panic: double fault
cpuid = 0
KDB: enter: panic
Uptime: 8d21h9m48s
Physical memory: 983 MB
Dumping 244 MB: 229 213 197 181 165 149 133 117 101 85 69 53 37 21 5

Reading symbols from /boot/modules/bwn_v4_lp_ucode.ko...done.
Loaded symbols for /boot/modules/bwn_v4_lp_ucode.ko
#0  0x805cc90a in kproc_shutdown (arg=0x0, howto=Variable
"howto" is not available.
) at /usr/src/sys/kern/kern_shutdown.c:639
639 printf("Waiting (max %d seconds) for system process
`%s' to stop...",
(kgdb) bt
#0  0x805cc90a in kproc_shutdown (arg=0x0, howto=Variable
"howto" is not available.
) at /usr/src/sys/kern/kern_shutdown.c:639
#1  0x805cce37 in kern_reboot (howto=260) at
/usr/src/sys/kern/kern_shutdown.c:216
#2  0x805cd2c1 in panic (fmt=0x1 )
at /usr/src/sys/kern/kern_shutdown.c:555
#3  0x808c7586 in user_ldt_free (td=0xff800021a300) at cpufunc.h:524
#4  0x808b24dd in Xtss () at /usr/src/sys/amd64/amd64/exception.S:151
#5  0x80615f54 in db_witness_list_all (addr=-2137114768,
have_addr=1, count=-2137114768, modif=0x1 )
at /usr/src/sys/kern/subr_witness.c:2352
Previous frame inner to this frame (corrupt stack?)



On Fri, Nov 26, 2010 at 1:49 PM, Ivan Klymenko  wrote:
> В Fri, 26 Nov 2010 12:26:39 +0200
> Ivan Klymenko  пишет:
>
>> Hello!
>> Rumor has it that this vulnerability applies to FreeBSD too, with the
>> replacement SOCK_SEQPACKET on SOCK_DGRAM...
> and add:
>
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
>
>>
>> http://lkml.org/lkml/2010/11/25/8
>>
>> What do you think about this?
>>
>> Thank you!
> ___
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
>



-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


mtx_init/lock_init and uninitialized struct mtx

2011-02-24 Thread Dmitry Krivenok
Hello Hackers,

Is it allowed to call mtx_init on a mutex defined as an auto variable
and not initialized explicitly, i.e.:

static int foo()
{
   struct mtx m;  // Uninitialized auto variable, so it's value is undefined.
   mtx_init(&m, "my_mutex", NULL, MTX_DEF);
   …
   // Do something
   ...
   mtx_destroy(&m);
   return 0;
}

I encountered a problem with such code on a kernel compiled with
INVARIANTS option.
The problem is that mtx_init calls lock_init(&m->lock_object) and
lock_init, in turn, calls:

 79 /* Check for double-init and zero object. */
 80 KASSERT(!lock_initalized(lock), ("lock \"%s\" %p already
initialized",
 81 name, lock));

lock_initialized() just checks that a bit is set in lo_flags field of
struct lock_object:

178 #define lock_initalized(lo) ((lo)->lo_flags & LO_INITIALIZED)

However, the structure containing this field is never initialized
(neither in mtx_init nor in lock_init).
So, assuming that the mutex was defined as auto variable, the content
of lock_object field of struct mtx
is also undefined:

 37 struct mtx {
 38 struct lock_object  lock_object;/* Common lock
properties. */
 39 volatile uintptr_t  mtx_lock;   /* Owner and flags. */
 40 };

In some cases, the initial value of lo_flags _may_ have the
"initialized" bit set and KASSERT will call panic.

Is it user's responsibility to properly (how exactly?) initialize
struct mtx, e.g.
memset(&m, '\0', sizeof(struct mtx));

Or should mtx_init() explicitly initialize all fields of struct mtx?

Thanks in advance!

-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: mtx_init/lock_init and uninitialized struct mtx

2011-02-24 Thread Dmitry Krivenok
Thanks a lot for your answers!

I'll always explicitly zero stack variables before calling actual
*_init() functions.
Also, it would be great to document this "zeroing" requirement in a
man page for mtx_init()
or simply add a comment in the source.

Dmitry


On Thu, Feb 24, 2011 at 10:02 PM, John Baldwin  wrote:
> On Thursday, February 24, 2011 10:47:27 am Dmitry Krivenok wrote:
>> Hello Hackers,
>>
>> Is it allowed to call mtx_init on a mutex defined as an auto variable
>> and not initialized explicitly, i.e.:
>
> It does expect you to zero it first.  I've considered adding a MTX_NEW flag to
> disable this check for places where the developer knows it is safe.  Most
> mutexes are allocated in an already-zero'd structure or BSS as Patrick noted,
> so they are already correct.  It is a trade off between catching double
> initializations and requiring extra M_ZERO flags or bzero() calls in various
> places.
>
>> static int foo()
>> {
>>    struct mtx m;  // Uninitialized auto variable, so it's value is
> undefined.
>>    mtx_init(&m, "my_mutex", NULL, MTX_DEF);
>>    …
>>    // Do something
>>    ...
>>    mtx_destroy(&m);
>>    return 0;
>> }
>>
>> I encountered a problem with such code on a kernel compiled with
>> INVARIANTS option.
>> The problem is that mtx_init calls lock_init(&m->lock_object) and
>> lock_init, in turn, calls:
>>
>>  79         /* Check for double-init and zero object. */
>>  80         KASSERT(!lock_initalized(lock), ("lock \"%s\" %p already
>> initialized",
>>  81             name, lock));
>>
>> lock_initialized() just checks that a bit is set in lo_flags field of
>> struct lock_object:
>>
>> 178 #define lock_initalized(lo)     ((lo)->lo_flags & LO_INITIALIZED)
>>
>> However, the structure containing this field is never initialized
>> (neither in mtx_init nor in lock_init).
>> So, assuming that the mutex was defined as auto variable, the content
>> of lock_object field of struct mtx
>> is also undefined:
>>
>>  37 struct mtx {
>>  38         struct lock_object      lock_object;    /* Common lock
>> properties. */
>>  39         volatile uintptr_t      mtx_lock;       /* Owner and flags. */
>>  40 };
>>
>> In some cases, the initial value of lo_flags _may_ have the
>> "initialized" bit set and KASSERT will call panic.
>>
>> Is it user's responsibility to properly (how exactly?) initialize
>> struct mtx, e.g.
>> memset(&m, '\0', sizeof(struct mtx));
>>
>> Or should mtx_init() explicitly initialize all fields of struct mtx?
>>
>> Thanks in advance!
>>
>> --
>> Sincerely yours, Dmitry V. Krivenok
>> e-mail: krivenok.dmi...@gmail.com
>> skype: krivenok_dmitry
>> jabber: krivenok_dmi...@jabber.ru
>> icq: 242-526-443
>> ___
>> freebsd-hackers@freebsd.org mailing list
>> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
>> To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"
>>
>
> --
> John Baldwin
>



-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


hw.physmem (loader.conf and sysctl)

2011-03-04 Thread Dmitry Krivenok
Hello Hackers,
I've limited the amount of physical memory visible for my FreeBSD-8.2 by adding
the following in loader.conf:

$ cat /boot/loader.conf | grep hw.physmem
hw.physmem="500M"
$

However, according to sysctl, the system sees

$ sysctl hw.physmem
hw.physmem: 507445248
$

The difference is (500 * 2**20 - 507445248) / 2**20 == 16.0625 Mb.
How does the system use this "hidden" memory?

Thanks!

-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Possible bug in gdb-6.1.1 (it leaves zombie processes)

2011-05-25 Thread Dmitry Krivenok
Hello hackers,
I think I found a bug in base gdb-6.1.1 on FreeBSD-8.2.
Below is how you can reproduce it.

I run "sleep 10" command under control of gdb-6.1.1 as follows

$ gdb --args sleep 10
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...(no debugging
symbols found)...
(gdb) r
Starting program: /bin/sleep 10
(no debugging symbols found)...(no debugging symbols found)...
Program exited normally.
(gdb) q
$

During execution of sleep I saw:
$ ps auxw | grep sleep
krived  2951  0.0  1.1 15836  5520   0  S 4:14PM   0:00.04 gdb
--args sleep 10
krived  2952  0.0  0.2  2764   840   0  SX+   4:14PM   0:00.01 /bin/sleep 10
$

As expected, once sleep exited and got
$ ps auxw | grep sleep
krived  2951  0.0  1.1 15836  5520   0  S+4:14PM   0:00.04 gdb
--args sleep 10
$

However, I found that sleep process became a zombie:
$ ps auxw | grep 2952
krived  2952  0.0  0.0 0 0   0  Z 4:14PM   0:00.01 
$

Then I closed gdb and zombie process went away:
$  ps auxw | grep 2952
$

I did a quick search through the Google and found that other people
also encountered this problem before:
https://bugzilla.redhat.com/show_bug.cgi?id=243845

I tried the same test with gdb-7.2 installed from ports and there was
no zombie process.

I didn't find any reports on this problem in PR database.
Can this problem be classified as a bug in base gdb-6.1.1?

Thanks!
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Problem with running simple pthreads program under gdb-7.2 (Invalid selected thread)

2011-05-25 Thread Dmitry Krivenok
Hello,
I wrote very simple Pthreads program to demonstrate the problem with
gdb-7.2 installed from
ports on my FreeBSD-8.2 (amd64).

///
#include 
#include 
#include 

void* run(void* arg)
{
 return 0;
}

int main(int argc, char** argv)
{
 pthread_t tid;
 int r;
 r = pthread_create(&tid, NULL, &run, NULL);
 assert(!r);
 r = pthread_join(tid, NULL);
 assert(!r);
 return 0;
}
///

I compiled it as follows
$ gcc -Wall -g -O0 -pthread -o t t.c
$

and then run under base gdb-6.1.1

$ gdb --args t
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...
(gdb) r
Starting program: /big/work/coverage/csxroot/src/t/t
[New LWP 100071]
[New Thread 800a041c0 (LWP 100071)]
[New Thread 800a0ae40 (LWP 100170)]
[Thread 800a0ae40 (LWP 100170) exited]

Program exited normally.
(gdb) q
$

As you can see program exited normally w/o any errors.
Then I run the same program under gdb-7.2

$ /usr/local/bin/gdb72 --args t
GNU gdb (GDB) 7.2 [GDB v7.2 for FreeBSD]
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-portbld-freebsd8.2".
For bug reporting instructions, please see:
...
Reading symbols from /big/work/coverage/csxroot/src/t/t...done.
(gdb) r
Starting program: /big/work/coverage/csxroot/src/t/t
[New LWP 100162]
[New Thread 800a041c0 (LWP 100162)]
[New Thread 800a0ae40 (LWP 100171)]
[Thread 800a0ae40 (LWP 100171) exited]
Invalid selected thread.
(gdb) q
A debugging session is active.

   Inferior 1 [process 7756] will be killed.

Quit anyway? (y or n) y
$

In this case I got "Invalid selected thread." right after the thread has exited.
Looks like gdb is unable to switch to another thread.
What's wrong here?

Thanks!

-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Bug in ksched_setscheduler?

2011-06-01 Thread Dmitry Krivenok
Hello Hackers,
I think I found a bug in ksched_setscheduler() function.

178 int
179 ksched_setscheduler(struct ksched *ksched,
180 struct thread *td, int policy, const struct sched_param *param)
181 {
182 int e = 0;
183 struct rtprio rtp;
184
185 switch(policy)
186 {
187 case SCHED_RR:
188 case SCHED_FIFO:
189
190 if (param->sched_priority >= P1B_PRIO_MIN &&
191 param->sched_priority <= P1B_PRIO_MAX)
192 {
193 rtp.prio = p4prio_to_rtpprio(param->sched_priority);
194 rtp.type = (policy == SCHED_FIFO)
195 ? RTP_PRIO_FIFO : RTP_PRIO_REALTIME;
196
197 rtp_to_pri(&rtp, td);
198 }
199 else
200 e = EPERM;
201
202
203 break;
204
205 case SCHED_OTHER:
206 if (param->sched_priority >= 0 &&
207 param->sched_priority <=
(PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE)) {
208 rtp.type = RTP_PRIO_NORMAL;
209 rtp.prio = p4prio_to_rtpprio(param->sched_priority);
210 rtp_to_pri(&rtp, td);
211 } else
212 e = EINVAL;
213
214 break;
215
216 default:
217 e = EINVAL;
218 break;
219 }
220
221 return e;
222 }

Shouldn't we use p4prio_to_tsprio instead of p4prio_to_rtpprio at the line 209?
This macro is defined but never used in kernel code:

$ grep -r 'p4prio_to_tsprio' /usr/src/sys/
/usr/src/sys/kern/ksched.c:#define p4prio_to_tsprio(P)
((PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE) - (P))
$

Is it a real bug or just my misunderstanding of something?

Thanks!

-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: Bug in ksched_setscheduler?

2011-06-06 Thread Dmitry Krivenok
I've submitted PR http://www.freebsd.org/cgi/query-pr.cgi?pr=157657.

Dmitry

On Thu, Jun 2, 2011 at 6:34 PM, John Baldwin  wrote:
> On Wednesday, June 01, 2011 12:42:42 pm Dmitry Krivenok wrote:
>> Hello Hackers,
>> I think I found a bug in ksched_setscheduler() function.
>>
>> 209                         rtp.prio = 
>> p4prio_to_rtpprio(param->sched_priority);
>>
>> Shouldn't we use p4prio_to_tsprio instead of p4prio_to_rtpprio at the line 
>> 209?
>> This macro is defined but never used in kernel code:
>>
>> $ grep -r 'p4prio_to_tsprio' /usr/src/sys/
>> /usr/src/sys/kern/ksched.c:#define p4prio_to_tsprio(P)
>> ((PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE) - (P))
>> $
>>
>> Is it a real bug or just my misunderstanding of something?
>
> I think it is a real bug.  Can you come up with a test case to show it?
>
> --
> John Baldwin
>



-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


pri_to_rtp returns invalid initial priority

2011-07-07 Thread Dmitry Krivenok
Hi Hackers,
I've developed a simple kld which demonstrates a problem I found on my
FreeBSD-8.2.

/
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

static struct sema sem;

/* ###*/

static void
set_prio(
struct thread *td,
u_short type,
u_short prio)
{
struct rtprio rtp;
int r;
rtp.type = type;
rtp.prio = prio;
r = rtp_to_pri(&rtp, td);
if (r != 0)
printf("Unable to set priority of type %u to %u (error code:
%d).\n", type, prio, r);
}

/* ###*/

static void
print_prio(
struct thread *td,
const char *prefix)
{
struct rtprio rtp;
pri_to_rtp(td, &rtp);
printf("%s priority: %u, type: %u.\n", prefix, rtp.prio, rtp.type);
}

/* ###*/

static void
set_and_print(
struct thread *td,
u_short type,
u_short prio,
const char *prefix)
{
set_prio(td, type, prio);
print_prio(td, prefix);
}

/* ###*/

static void
kthread_run(
void)
{
struct thread *td = curthread;

sema_wait(&sem);

print_prio(td, "[NEW] Initial TS");
set_and_print(td, RTP_PRIO_NORMAL, PRI_MIN_TIMESHARE -
PRI_MIN_TIMESHARE, "[NEW] Min TS");
set_and_print(td, RTP_PRIO_NORMAL, (PRI_MAX_TIMESHARE -
PRI_MIN_TIMESHARE) / 2, "[NEW] Mid TS");
set_and_print(td, RTP_PRIO_NORMAL, PRI_MAX_TIMESHARE -
PRI_MIN_TIMESHARE, "[NEW] Max TS");
set_and_print(td, RTP_PRIO_REALTIME, RTP_PRIO_MIN - RTP_PRIO_MIN,
"[NEW] Min RT");
set_and_print(td, RTP_PRIO_REALTIME, (RTP_PRIO_MAX - RTP_PRIO_MIN)
/ 2, "[NEW] Mid RT");
set_and_print(td, RTP_PRIO_REALTIME, RTP_PRIO_MAX - RTP_PRIO_MIN,
"[NEW] Max RT");

sema_destroy(&sem);
kthread_exit();
}

/* ###*/

static int
event_handler(
struct module *module,
int event,
void *arg)
{
if (event == MOD_LOAD) {
struct kthread_desc desc;
struct thread *td = curthread;
desc.arg0 = "my_thr";
desc.func = kthread_run;
desc.global_threadpp = NULL;

sema_init(&sem, 0, "my_sem");
kthread_start(&desc);

print_prio(td, "[MAIN] Initial TS");
set_and_print(td, RTP_PRIO_NORMAL, PRI_MIN_TIMESHARE -
PRI_MIN_TIMESHARE, "[MAIN] Min TS");
set_and_print(td, RTP_PRIO_NORMAL, (PRI_MAX_TIMESHARE -
PRI_MIN_TIMESHARE) / 2, "[MAIN] Mid TS");
set_and_print(td, RTP_PRIO_NORMAL, PRI_MAX_TIMESHARE -
PRI_MIN_TIMESHARE, "[MAIN] Max TS");
set_and_print(td, RTP_PRIO_REALTIME, RTP_PRIO_MIN -
RTP_PRIO_MIN, "[MAIN] Min RT");
set_and_print(td, RTP_PRIO_REALTIME, (RTP_PRIO_MAX -
RTP_PRIO_MIN) / 2, "[MAIN] Mid RT");
set_and_print(td, RTP_PRIO_REALTIME, RTP_PRIO_MAX -
RTP_PRIO_MIN, "[MAIN] Max RT");

sema_post(&sem);
}
if (event == MOD_UNLOAD) {

}
return 0;
};

/* ###*/

static moduledata_t thr_conf = {
"thr", /* module name */
event_handler, /* event handler */
NULL   /* extra data */
};

/* ###*/

DECLARE_MODULE(thr, thr_conf, SI_SUB_KLD, SI_ORDER_ANY);
/

On FreeBSD-8.2 I get the following results:

[MAIN] Initial TS priority: 65508, type: 3.
[MAIN] Min TS priority: 0, type: 3.
[MAIN] Mid TS priority: 31, type: 3.
[MAIN] Max TS priority: 63, type: 3.
[MAIN] Min RT priority: 0, type: 2.
[MAIN] Mid RT priority: 15, type: 2.
[MAIN] Max RT priority: 31, type: 2.
[NEW] Initial TS priority: 65504, type: 3.
[NEW] Min TS priority: 0, type: 3.
[NEW] Mid TS priority: 31, type: 3.
[NEW] Max TS priority: 63, type: 3.
[NEW] Min RT priority: 0, type: 2.
[NEW] Mid RT priority: 15, type: 2.
[NEW] Max RT priority: 31, type: 2.

[MAIN] Initial TS priority: 20, type: 3.
[MAIN] Min TS priority: 0, type: 3.
[MAIN] Mid TS priority: 31, type: 3.
[MAIN] Max TS priority: 63, type: 3.
[MAIN] Min RT priority: 0, type: 2.
[MAIN] Mid RT priority: 15, type: 2.
[MAIN] Max RT priority: 31, type: 2.
[NEW] Initial TS priority: 65504, type: 3.
[NEW] Min TS priority: 0, type: 3.
[NEW] Mid TS priority: 31, type: 3.
[NEW] Max TS priority: 63, type: 3.
[NEW] Min RT priority: 0, type: 2.
[NEW] Mid RT priority: 15, type: 2.
[NEW] Max RT priority: 31, type: 2.

[MAIN] Initial TS priority: 65531, type: 3.
[MAIN] Min TS priority: 0, type: 3.
[MAIN] Mid TS priority: 31, 

Re: pri_to_rtp returns invalid initial priority

2011-07-12 Thread Dmitry Krivenok
No it cannot be r222802.
Actually, I found a bug fixed in r222802 about a month ago
(kern/157657) and I've patched source code
of my FreeBSD-8.2 (this is the only difference between my tree and
stock FreeBSD-8.2).
I thought that build with KERNFAST=1 could be a problem, but I've done
clean build and still
see the same.

On Thu, Jul 7, 2011 at 10:46 PM, John Baldwin  wrote:
> On Thursday, July 07, 2011 6:37:02 am Dmitry Krivenok wrote:
>> Hi Hackers,
>> I've developed a simple kld which demonstrates a problem I found on my
>> FreeBSD-8.2.
>
> Maybe revision 222802?
>
> --
> John Baldwin
>



-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Moving from FreeBSD7 to FreeBSD8 (cdev, minor, dev2unit)

2010-05-07 Thread Dmitry Krivenok
Hello Hackers,

I'm working on porting some kernel modules written for FreeBSD7 to FreeBSD8.
Some of these modules contain the following code:

struct cdev *dev;
...
int dev_num = minor(dev);

This code doesn't compile on FreeBSD8.
I found that in FreeBSD7 minor() was defined as follows:

  515 int
  516 minor(struct cdev *x)
  517 {
  518 if (x == NULL)
  519 return NODEV;
  520 return(x->si_drv0 & MAXMINOR);
  521 }

where MAXMINOR was defined as

  236 #define MAXMINOR0x00ffU

But in FreeBSD8 minor() is defined as macro that takes integer as a parameter:

  323 #define minor(x)((int)((x)&0x00ff)) /* minor number */

I also found that FreeBSD8 provides dev2unit macro:

  276 #define dev2unit(d) ((d)->si_drv0)

It looks like dev2unit is exactly what I need to fix compilation issue.
I changed the code of all modules as follows:

- int dev_num = minor(dev);
+ int dev_num = minor(dev2unit(dev));

and now it compiles and works well.

Is this the proper way of solving the problem?

Thanks in advance!

--
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Need advice about selsocket analogue for a set of sockets

2010-05-13 Thread Dmitry Krivenok
Hi Hackers,

I know that FreeBSD-8 kernel provides selsocket function declared as follows:

int selsocket(struct socket *so, int events, struct timeval *tvp,
struct thread *td);

It's very useful if you have just one socket and don't care about
which events fired.
In my case, however, I have an array of the following structures

typedef struct {
struct socket *fd;
int events;
int revents;
} sock_poll_t;

and need to poll all sockets saving results in revents field.
That is I need to implement a function with the following prototype:

int sockets_poll( sock_poll_t * ufds,  unsigned int nfds,  int timeout_msecs);

Obviously, selsocket is useless is such scenario (it returns 0 on
success and therefore
doesn't tell which events fired).

I looked into sys/kern/sys_generic.c but didn't find any functions
which may be useful
for working with array of structures above.

I could try to implement a function similar to selsocket, but I cannot
use the same helper
functions (selfdalloc, seltdwait, etc) because they are considered as
implementation details
and defined as static.

I need your advice.
What's the best way of solving my problem?

Thanks in advance!

--
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


select/poll for sockets in kernel space

2010-05-25 Thread Dmitry Krivenok
Hello Hackers!

I'm developing a module for FreeBSD-8 and encountered the problem with
polling sockets.
I know that FreeBSD-8 kernel provides 3 interfaces for polling
(kern/sys_generic.c):
1) kern_select
2) poll
3) selsocket

I cannot use first two interfaces because I have an array of sockets
(struct socket) created using socreate, i.e. I don't have file
descriptors.
I also cannot use selsocket because it doesn't tell me which events
fired and takes only one socket (but I have an array of sockets).

The problem is that the module I'm developing should work on
unmodified FreeBSD-8 kernel.
So I cannot just add new functionality suitable for my task in
kern/sys_generic.c.
I also cannot implement such functionality in the module itself
because select/poll implementation is hidden and only limited number
of interfaces is available to the rest
of the kernel (which is generally good, but not in my case :)).

Is it possible to solve my problem using existing kernel functionality?
Any suggestions are welcome!

Thanks in advance!

P.S.
I know about kqueue, but I have to use select/poll is this task.

-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Do we still need libc_r and libkse in /usr/src/lib?

2010-07-05 Thread Dmitry Krivenok
Hi Hackers,

I've just started learning implementation of threads in FreeBSD-CURRENT.
exctags found three different implementations of pthread_create
function - libc_r, libkse and libthr:

  # pri kind tag   file
  1 F   f_pthread_create   lib/libc_r/uthread/uthread_create.c
   _pthread_create(pthread_t *thread, const pthread_attr_t *attr,
  2 F   f_pthread_create   lib/libkse/thread/thr_create.c
   _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
  3 F   f_pthread_create   lib/libthr/thread/thr_create.c
   _pthread_create(pthread_t * thread, const pthread_attr_t * attr,

I did a quick search in the google and found that libc_r (N:1 model)
and libkse (N:M model) are no longer
used in FreeBSD. So the only supported implementation of POSIX threads
API is libthr (1:1 model), right?

However, I found that both libc_r and libkse are still in /usr/src/lib.
That looks like a bug because you even cannot build these libraries (I
encountered compilation errors).

I don't see obvious reason to keep such a dead code.
Isn't it better to remove these libraries (of course you can still
access the source code since SVN doesn't really delete anything)?
If not, could you please explain why?

Thanks!

-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Kernel linker and undefined references in KLD

2010-07-15 Thread Dmitry Krivenok
Hello Hackers,

I have a question about kernel linker.
Please take a look at an example of simple module:


#include 
#include 
#include 
#include 
#include 
#include 
#include 

/* DECLARING A FUNCTION JUST TO AVOID WARNING WHICH IS TREAT AS ERROR
BY DEFAULT */
void seltdinit(struct thread* t);

static int event_handler(struct module *module, int event, void *arg)
{
  int e = 0;
  switch (event)
{
  case MOD_LOAD:
/* CALLING A FUNCTION DECLARED AS STATIC IN kern/sys_generic.c */
seltdinit(curthread);
break;
  case MOD_QUIESCE:
break;
  case MOD_UNLOAD:
break;
  case MOD_SHUTDOWN:
break;
  default:
e = EOPNOTSUPP;
break;
}

  return(e);
};


As you can see, this module calls seltdinit function declared as
_static_ in kern/sys_generic.c file.
I added a declaration of seltdinit function w/o static just to avoid
compilation error since -Werror is used
by default in FreeBSD.

Then I successfully built the module:

$ make
Warning: Object directory not changed from original
/usr/home/krived/work/freebsd/trouble
cc -O2 -pipe -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE
-nostdinc   -I. -I@ -I@/contrib/altq -finline-limit=8000 --param
inline-unit-growth=100 --param large-function-growth=1000 -fno-common
-fno-omit-frame-pointer  -mcmodel=kernel -mno-red-zone  -mfpmath=387
-mno-sse -mno-sse2 -mno-sse3 -mno-mmx -mno-3dnow  -msoft-float
-fno-asynchronous-unwind-tables -ffreestanding -fstack-protector
-std=iso9899:1999 -fstack-protector -Wall -Wredundant-decls
-Wnested-externs -Wstrict-prototypes  -Wmissing-prototypes
-Wpointer-arith -Winline -Wcast-qual  -Wundef -Wno-pointer-sign
-fformat-extensions -c trouble.c
ld  -d -warn-common -r -d -o trouble.ko trouble.o
:> export_syms
awk -f /sys/conf/kmod_syms.awk trouble.ko  export_syms | xargs -J%
objcopy % trouble.ko
objcopy --strip-debug trouble.ko
$

As expected, seltdinit symbol is undefined in trouble.ko file:
$ nm trouble.ko | grep seltdinit
 U seltdinit
$
and is local in kernel binary file:
$ nm /boot/kernel/kernel | grep seltdinit
805fda50 t seltdinit
$

I expected to get something like "undefined reference to seltdinit"
error, but the module was loaded w/o any errors:

$ sudo make load
/sbin/kldload -v /usr/home/krived/work/freebsd/trouble/trouble.ko
Loaded /usr/home/krived/work/freebsd/trouble/trouble.ko, id=2
$ kldstat | grep trouble
 21 0x81212000 126  trouble.ko
$ sudo make unload
/sbin/kldunload -v trouble.ko
Unloading trouble.ko, id=2
$

Could you please explain why the linker (or whatever is loading
modules in FreeBSD) doesn't complain?

For example, ld tool complains for the similar user-space example:


$ cat seltdinit.c
static void seltdinit(void* td)
{
  return;
}
$ cat main.c
void seltdinit(void* td);

int main()
{
  seltdinit(0);
  return 0;
}
$ gcc -Wall -c seltdinit.c
seltdinit.c:2: warning: 'seltdinit' defined but not used
$ gcc -Wall -c main.c
$ gcc seltdinit.o main.o -o sel
main.o: In function `main':
main.c:(.text+0xa): undefined reference to `seltdinit'
collect2: ld returned 1 exit status
$


Thanks in advance!

-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: Kernel linker and undefined references in KLD

2010-07-15 Thread Dmitry Krivenok
Unfortunately, one can easily miss such problems during build of the module.
I'm working on a system which consists of lots of user-space programs
and kernel modules and
uses it's own complicated build system.
gcc option -Werror is not used by the build system (I believe it
should), that's why we just missed
a compiler warning when called undeclared function (actually declared
as static deep in kernel source).

Then we got kernel panic and started investigating it.
I disassembled seltdinit function and found that it takes pointer to
thread from %eax register and global kernel
functions (e.g. kern_select) calling seltdinit copy the pointer to
%eax just before "call" instruction.

Then I disassembled my own function calling seltdinit and found that
it passes the pointer via stack and
doesn't do anything with %eax register.

I'm not OS/compilers/ASM expert, but I guess that gcc is free to
optimize passing of parameters to static functions
because it has all the information about callers of these static
functions (all stuff is inside one translation unit).
So kernel functions call static functions in a right way, but modules
compiled separately may use wrong calling
convention.

On Thu, Jul 15, 2010 at 6:32 PM, Kostik Belousov  wrote:
> On Thu, Jul 15, 2010 at 06:07:36PM +0400, Dmitry Krivenok wrote:
>> Hello Hackers,
>>
>> I have a question about kernel linker.
>> Please take a look at an example of simple module:
>>
>> 
>> #include 
>> #include 
>> #include 
>> #include 
>> #include 
>> #include 
>> #include 
>>
>> /* DECLARING A FUNCTION JUST TO AVOID WARNING WHICH IS TREAT AS ERROR
>> BY DEFAULT */
>> void seltdinit(struct thread* t);
>>
>> static int event_handler(struct module *module, int event, void *arg)
>> {
>>   int e = 0;
>>   switch (event)
>>     {
>>       case MOD_LOAD:
>>         /* CALLING A FUNCTION DECLARED AS STATIC IN kern/sys_generic.c */
>>         seltdinit(curthread);
>>         break;
>>       case MOD_QUIESCE:
>>         break;
>>       case MOD_UNLOAD:
>>         break;
>>       case MOD_SHUTDOWN:
>>         break;
>>       default:
>>         e = EOPNOTSUPP;
>>         break;
>>     }
>>
>>   return(e);
>> };
>> 
>>
>> As you can see, this module calls seltdinit function declared as
>> _static_ in kern/sys_generic.c file.
>> I added a declaration of seltdinit function w/o static just to avoid
>> compilation error since -Werror is used
>> by default in FreeBSD.
>>
>> Then I successfully built the module:
>>
>> $ make
>> Warning: Object directory not changed from original
>> /usr/home/krived/work/freebsd/trouble
>> cc -O2 -pipe -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE
>> -nostdinc   -I. -I@ -I@/contrib/altq -finline-limit=8000 --param
>> inline-unit-growth=100 --param large-function-growth=1000 -fno-common
>> -fno-omit-frame-pointer  -mcmodel=kernel -mno-red-zone  -mfpmath=387
>> -mno-sse -mno-sse2 -mno-sse3 -mno-mmx -mno-3dnow  -msoft-float
>> -fno-asynchronous-unwind-tables -ffreestanding -fstack-protector
>> -std=iso9899:1999 -fstack-protector -Wall -Wredundant-decls
>> -Wnested-externs -Wstrict-prototypes  -Wmissing-prototypes
>> -Wpointer-arith -Winline -Wcast-qual  -Wundef -Wno-pointer-sign
>> -fformat-extensions -c trouble.c
>> ld  -d -warn-common -r -d -o trouble.ko trouble.o
>> :> export_syms
>> awk -f /sys/conf/kmod_syms.awk trouble.ko  export_syms | xargs -J%
>> objcopy % trouble.ko
>> objcopy --strip-debug trouble.ko
>> $
>>
>> As expected, seltdinit symbol is undefined in trouble.ko file:
>> $ nm trouble.ko | grep seltdinit
>>                  U seltdinit
>> $
>> and is local in kernel binary file:
>> $ nm /boot/kernel/kernel | grep seltdinit
>> 805fda50 t seltdinit
>> $
>>
>> I expected to get something like "undefined reference to seltdinit"
>> error, but the module was loaded w/o any errors:
>>
>> $ sudo make load
>> /sbin/kldload -v /usr/home/krived/work/freebsd/trouble/trouble.ko
>> Loaded /usr/home/krived/work/freebsd/trouble/trouble.ko, id=2
>> $ kldstat | grep trouble
>>  2    1 0x81212000 126      trouble.ko
>> $ sudo make unload
>> /sbin/kldunload -v trouble.ko
>> Unloading trouble.ko, id=2
>> $
>>
>> Could you please explain why the linker (or whatever is loading
>> m

Strange behavior of kernel module (output terminated)

2010-03-23 Thread Dmitry Krivenok
Hello Hackers,

I'm new to FreeBSD kernel development and have a very basic question about
kernel modules.
I compiled and slightly modified an example from
http://www.freesoftwaremagazine.com/articles/writing_a_kernel_module_for_freebsd
.
Below is the source code of my first module called "hello":

///
#include 
#include 
#include 
#include 
#include 
#include 
#include 

/* The function called at load/unload. */
static int event_handler(struct module *module, int event, void *arg)
{
  int e = 0; /* Error, 0 for normal return status */
  switch (event)
{
  case MOD_LOAD:
uprintf("Hello FreeBSD kernel!\n");
int i = 0;
for(i = 0; i < 1000; i++)
  {
uprintf("%3d ", i);
if(! (i % 10) ) uprintf("\n");
  }
break;
  case MOD_UNLOAD:
uprintf("Bye Bye FreeBSD Kernel!\n");
break;
  default:
e = EOPNOTSUPP; /* Error, Operation Not Supported */
break;
}

  return(e);
};

/* The second argument of DECLARE_MODULE. */
static moduledata_t hello_conf =
{
  "hello",/* module name */
  event_handler,  /* event handler */
  NULL/* extra data */
};

DECLARE_MODULE(hello, hello_conf, SI_SUB_KLD, SI_ORDER_ANY);
///

I compiled the module successfully and run it (via sudo make load unload).
The output confused me a bit:

$ uname -v
FreeBSD 8.0-RELEASE-p2 #0: Tue Jan  5 21:11:58 UTC 2010
r...@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC
$ make
Warning: Object directory not changed from original
/usr/home/krived/work/freebsd/hello
cc -O2 -pipe -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc
-I. -I@ -I@/contrib/altq -finline-limit=8000 --param inline-unit-growth=100
--param large-function-growth=1000 -fno-common  -fno-omit-frame-pointer
-mcmodel=kernel -mno-red-zone  -mfpmath=387 -mno-sse -mno-sse2 -mno-sse3
-mno-mmx -mno-3dnow  -msoft-float -fno-asynchronous-unwind-tables
-ffreestanding -fstack-protector -std=iso9899:1999 -fstack-protector -Wall
-Wredundant-decls -Wnested-externs -Wstrict-prototypes  -Wmissing-prototypes
-Wpointer-arith -Winline -Wcast-qual  -Wundef -Wno-pointer-sign
-fformat-extensions -c hello.c
ld  -d -warn-common -r -d -o hello.ko hello.o
:> export_syms
awk -f /sys/conf/kmod_syms.awk hello.ko  export_syms | xargs -J% objcopy %
hello.ko
objcopy --strip-debug hello.ko
$ sudo make load unload
/sbin/kldload -v /usr/home/krived/work/freebsd/hello/hello.ko
Hello FreeBSD kernel!
  0
  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  32  33  34  35  36  37  38  39  40
 41  42  43  44  45  46  47  48  49  50
 51  52  53  54  55  56  57  58  59  60
 61  62  63  64  65  66  67  68  69  70
 71  72  73  74  75  76  77  78  79  80
 81  82  83  84  85  86  87  88  89  90
 91  92  93  94  95  96  97  98  99 100
101 102 103 104 105 106 107 108 109 110
111 112 113 114 115 116 117 118 119 120
121 122 123 124 125 126 127 128 129 130
131 132 133 134 135 136 137 138 139 140
141 142 143 144 145 146 147 148 149 150
151 152 153 154 155 156 157 158 159 160
161 162 163 164 165 166 167 168 169 170
171 172 173 174 175 176 177 178 179 180
181 182 183 184 185 186 187 188 189 190
191 192 193 194 195 196 197 198 199 200
201 202 203 204 205 206 207 208 209 210
211 212 213 214 215 216 217 218 219 220
221 222 223 224 225 226 227 228 229 230
231 232 233 234 235 236 237 238 239 240
241 242 243 244 245 246 247 248 249 250
251 252 253 254 255 256 257 258 259 260
261 262 263 264 265 266 267 268 269 270
271 272 273 274 275 276 277 278 279 280
281 282 283 284 285 286 287 288 289 290
291 292 293 294 295 296 297 298 299 300
301 302 303 304 305 306 307 308 309 310
311 312 313 314 315 316 317 318 319 320
321 322 323 324 325 326 327 328 329 330
331 332 333 334 335 336 337 338 339 340
341 342 343 344 345 346 347 348 349 350
351 352 353 354 355 356 357 358 359 360
361 362 363 364 365 366 367 368 369 370
371 372 373 374 375 376 377 378 379 380
381 382 383 384 385 386 387 388 389 390
391 392 393 394 395 396 397 398 399 400
401 402 403 404 405 406 407 408 409 410
411 412 413 414 415 416 417 418 419 420
421 422 423 424 425 426 427 428 429 430
431 432 433 434 435 436 437 438 439 440
441 442 443 444 445 446 447 448 449 450
451 452 453 454 455 456 457 458 459 460
461 462 463 464 465 466Loaded /usr/home/krived/work/freebsd/hello/hello.ko,
id=2
/sbin/kldunload -v hello.ko
Unloading hello.ko, id=2
Bye Bye FreeBSD Kernel!
$

As you can see the loop was terminated after i==466.
I tried to load/unload the module many times but the last printed number was
always 466.

Then I compiled the same module on FreeBSD-7.2 (note, the first test was run
on 8.0).
I saw exactly the same be

Build world with DEBUG_FLAGS='-g -O0'

2010-04-12 Thread Dmitry Krivenok
Hello Hackers,

I'm trying to build FreeBSD-CURRENT (r206494) with DEBUG_FLAGS='-g -O0'.

Below are the commands I executed:

export DEBUG_FLAGS='-g -O0'

cd /usr/src/

time make buildworld


I got the following error:

...

...

===> sys/boot/i386/boot2 (all)

objcopy -S -O binary boot1.out boot1

dd if=/dev/zero of=boot2.ldr bs=512 count=1

1+0 records in

1+0 records out

512 bytes transferred in 0.000142 secs (3603160 bytes/sec)

cc -Os  -fno-guess-branch-probability  -fomit-frame-pointer
-fno-unit-at-a-time  -mno-align-long-strings  -mrtd  -mno-mmx -mno-3dnow
-mno-sse -mno-sse2 -mno

-sse3  -DUFS1_AND_UFS2  -DFLAGS=0x80  -DSIOPRT=0x3f8  -DSIOFMT=0x3
-DSIOSPD=9600  -I/usr/src/sys/boot/i386/boot2/../../common
-I/usr/src/sys/boot/i386/boot

2/../btx/lib -I.  -Wall -Waggregate-return -Wbad-function-cast -Wcast-align
-Wmissing-declarations -Wmissing-prototypes -Wnested-externs  -Wpointer-arith
-W

shadow -Wstrict-prototypes -Wwrite-strings  -Winline --param
max-inline-insns-single=100 -ffreestanding
-mpreferred-stack-boundary=2  -mno-mmx
-mno-3dnow -mn

o-sse -mno-sse2 -mno-sse3 -m32 -march=i386 -g -O0 -std=gnu99   -S -o
boot2.s.tmp /usr/src/sys/boot/i386/boot2/boot2.c

sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s

rm -f boot2.s.tmp

as  --32 -o boot2.o boot2.s

cc -Os  -fno-guess-branch-probability  -fomit-frame-pointer
-fno-unit-at-a-time  -mno-align-long-strings  -mrtd  -mno-mmx -mno-3dnow
-mno-sse -mno-sse2 -mno

-sse3  -DUFS1_AND_UFS2  -DFLAGS=0x80  -DSIOPRT=0x3f8  -DSIOFMT=0x3
-DSIOSPD=9600  -I/usr/src/sys/boot/i386/boot2/../../common
-I/usr/src/sys/boot/i386/boot

2/../btx/lib -I.  -Wall -Waggregate-return -Wbad-function-cast -Wcast-align
 -Wmissing-declarations -Wmissing-prototypes -Wnested-externs  -Wpointer-arith
-W

shadow -Wstrict-prototypes -Wwrite-strings  -Winline --param
max-inline-insns-single=100 -ffreestanding
-mpreferred-stack-boundary=2  -mno-mmx
-mno-3dnow -mn

o-sse -mno-sse2 -mno-sse3 -m32 -march=i386 -g -O0 -std=gnu99   -c
/usr/src/sys/boot/i386/boot2/sio.S

ld -static -N --gc-sections -nostdlib -m elf_i386_fbsd -Ttext 0x2000 -o
boot2.out /usr/src/obj/usr/src/sys/boot/i386/boot2/../btx/lib/crt0.o boot2.o
sio.o

objcopy -S -O binary boot2.out boot2.bin

btxld -v -E 0x2000 -f bin -b
/usr/src/obj/usr/src/sys/boot/i386/boot2/../btx/btx/btx -l boot2.ldr  -o
boot2.ld -P 1 boot2.bin

kernel: ver=1.02 size=690 load=9000 entry=9010 map=16M pgctl=1:1

client: fmt=bin size=20ed text=0 data=0 bss=0 entry=0

output: fmt=bin size=297d text=200 data=277d org=0 entry=0

-2941 bytes available

*** Error code 1



Stop in /usr/src/sys/boot/i386/boot2.

*** Error code 1



Stop in /usr/src/sys/boot/i386.

*** Error code 1



Stop in /usr/src/sys/boot.

*** Error code 1



Stop in /usr/src/sys.

*** Error code 1



Stop in /usr/src.

*** Error code 1



Stop in /usr/src.

*** Error code 1



Stop in /usr/src.



real87m23.033s

user53m7.195s

sys 30m10.744s


Error message "-2941 bytes available" is not clear for me :)
What's wrong?

Thank you beforehand!

P.S.
Note that compiling with DEBUG_FLAGS='-g' works fine.

-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: Build world with DEBUG_FLAGS='-g -O0'

2010-04-12 Thread Dmitry Krivenok
Is there a simple way to build size constrained parts of world (e.g.
bootcode) with '-O2' and other
parts with '-O0'?

On Mon, Apr 12, 2010 at 11:54 PM, Bernd Walter wrote:

> On Mon, Apr 12, 2010 at 10:34:30PM +0400, Dmitry Krivenok wrote:
> > Hello Hackers,
> >
> > I'm trying to build FreeBSD-CURRENT (r206494) with DEBUG_FLAGS='-g -O0'.
> >
> > Below are the commands I executed:
> >
> > export DEBUG_FLAGS='-g -O0'
> >
> > cd /usr/src/
> >
> > time make buildworld
> >
> >
> > I got the following error:
> >
> > ...
> >
> > ...
> >
> > objcopy -S -O binary boot2.out boot2.bin
> >
> > btxld -v -E 0x2000 -f bin -b
> > /usr/src/obj/usr/src/sys/boot/i386/boot2/../btx/btx/btx -l boot2.ldr  -o
> > boot2.ld -P 1 boot2.bin
> >
> > kernel: ver=1.02 size=690 load=9000 entry=9010 map=16M pgctl=1:1
> >
> > client: fmt=bin size=20ed text=0 data=0 bss=0 entry=0
> >
> > output: fmt=bin size=297d text=200 data=277d org=0 entry=0
> >
> > -2941 bytes available
> >
> > *** Error code 1
> >
> >
> >
> > Stop in /usr/src/sys/boot/i386/boot2.
> >
> > *** Error code 1
> >
> >
> >
> > Stop in /usr/src/sys/boot/i386.
> >
> > *** Error code 1
> >
> >
> >
> > Stop in /usr/src/sys/boot.
> >
> > *** Error code 1
> >
> >
> >
> > Stop in /usr/src/sys.
> >
> > *** Error code 1
> >
> >
> >
> > Stop in /usr/src.
> >
> > *** Error code 1
> >
> >
> >
> > Stop in /usr/src.
> >
> > *** Error code 1
> >
> >
> >
> > Stop in /usr/src.
> >
> >
> >
> > real87m23.033s
> >
> > user53m7.195s
> >
> > sys 30m10.744s
> >
> >
> > Error message "-2941 bytes available" is not clear for me :)
> > What's wrong?
>
> It is 2941 bytes too big for bootcode.
> Bootcode is size constrained.
>
> >
> > Thank you beforehand!
> >
> > P.S.
> > Note that compiling with DEBUG_FLAGS='-g' works fine.
>
> Yes - because it compiles with -O2 then, which allows the compiler
> to buld smaller code.
>
> --
> B.Walter  http://www.bwct.de
> Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.
>



-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmi...@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmi...@jabber.ru
icq: 242-526-443
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"