Re: bash Shell Scripting Question

2012-09-19 Thread Mihai Donțu
On Wed, 19 Sep 2012 21:03:11 -0500 Martin McCormick wrote:
 #!/usr/local/bin/bash 
 ls -LF |grep \/ /tmp/files
 while read dirname; do
 cd $dirname
 #Do whatever commands to be repeated in each directory.
 done  /tmp/files
 

How about:

   ls -LF | grep \/ | while read dirname; do
   cd $dirname
   # do stuff
   done

or:

   find . -maxdepth 1 -type d | while read dirname; do
   cd $dirname
   # do stuff
   done

or even:

   find . -maxdepth 1 -type d ! -name .* | while read dirname; do
   cd $dirname
   # do stuff
   done

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: AES NI

2012-07-21 Thread Mihai Donțu
On Fri, 20 Jul 2012 18:19:37 +0200 (CEST) Wojciech Puchar wrote:
 am i doing something wrong? i have processor with AES-NI support.
 
 I've seen a lot of tests showing AES encryption performance to be in
 order of 1GB/s or more.
 

ignore its GNU/Linux orientation and go for the numbers:
http://www.phoronix.com/scan.php?page=articleitem=ubuntu_aesni_intel

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Processor question

2012-02-14 Thread Mihai Donțu
On Tue, 14 Feb 2012 14:47:08 -0500 Mike Dockery wrote:
 Greetings,
 
 I have been a user of Linux since 1994, but most of the linux distros 
 seem to be getting away from freedom... which is why I chose it in
 the first place.  They seem intent on forcing things that do not work
 well (like pulseaudio and nouveau) on everyone.  Freedom of choice is
 always best.
 

Far be it for me to stop you from adventuring into the FreeBSD world, I
encourage you actually. :-) However, note that you always had and will
have the freedom of choice. One Linux distribution might have chosen to
go the pulseaudio way (binary-only ones usually do), but FreeBSD
inspired ones, with ports-like features, offer you the choice to go
plain ALSA or even OSS (Crux, Gentoo etc.).

In what concerns nouveau, I'm afraid there's no running away from it.
Reverse engineering close source drivers for modern GPU-s is an
incredibly hard task. FreeBSD will likely get nouveau when KMS gets
finished (soon I hear?). Until then, the good old nVidia blob will do.

So instead of seeing FreeBSD as a place of retreat, see it as an
adventure! :-)

 My question is:  Should I try the amd64 version of FreeBSD with my
 Intel Core i7-2600 processor or should I use the i386?
 

Definitely amd64.

 I hope to give FreeBSD a try later this month.
 

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: google browser?

2011-02-16 Thread Mihai Donțu
On Wednesday 16 February 2011 09:09:44 Gary Kline wrote:
 Anybody know how to use this Chrome?  I don't see any places to
 plug in players ... like vlc, etc.  Can't find and back/Forward
 icons, nothing like firefoxI give it all three thumbs
 down.
 
 Would still like to see GOOG have its own twitter and facebook
 tho.
 
 Anybody else have the browser on FBSD??

I haven't tried it, but maybe it works under the FreeBSD Linux emulation. I 
found some build hints here too: http://wiki.freebsd.org/Chromium , however it 
definitely needs some love from a dedicated FreeBSD developer.

I use Google Chrome (or Chromium - depends on how bleeding edge I want to be) 
on Linux. I'm amazed by the speed with which the project progresses and the 
incredible feel of the browser itself.

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: google browser?

2011-02-16 Thread Mihai Donțu
(e-mails from the past always find me unprepared)

On Wednesday 23 July 2008 11:52:58 Devin Teske wrote:
 On Feb 16, 2011, at 12:39 AM, Mihai Donțu wrote:
  On Wednesday 16 February 2011 09:09:44 Gary Kline wrote:
  Anybody know how to use this Chrome?  I don't see any places to
  plug in players ... like vlc, etc.  Can't find and back/Forward
  icons, nothing like firefoxI give it all three thumbs
  down.
  
  Would still like to see GOOG have its own twitter and facebook
  tho.
  
  Anybody else have the browser on FBSD??
  
  I haven't tried it, but maybe it works under the FreeBSD Linux emulation.
  I found some build hints here too: http://wiki.freebsd.org/Chromium ,
  however it definitely needs some love from a dedicated FreeBSD
  developer.
  
  I use Google Chrome (or Chromium - depends on how bleeding edge I want to
  be) on Linux. I'm amazed by the speed with which the project progresses
  and the incredible feel of the browser itself.
 
 I've heard certain noises on this list that the current port-maintainer of
 Chromium has dropped the ball (not my words, just paraphrasing the
 sentiment from the below thread).
 
 http://www.FreeBSD.org/cgi/getmsg.cgi?fetch=890197+893402+/usr/local/www/db
 /text/2010/freebsd-questions/20101231.freebsd-questions
 
 The OP's concerns about security vulnerabilities (though voiced over 30
 days ago) still appear to be of concern (that is to say, nothing appears
 to have changed except some _minor_ work on January 18th this year by
 rene).
 
 However, Freshports still has a less-than-favorable status for this port:
 http://www.freshports.org/www/chromium/
 
 Now... that being said, I have a co-worker that is running Chromium every
 day on FreeBSD-8.1 and he's very happy with it. Though, given the above
 consideration, both him and I have decided to _not_ deploy this browser in
 production (at least until we can get some love on those vulnerabilities).
 
 So, I guess I'd like to throw the query out there...
 
 If you had to pick between Firefox and Chrome for distribution to 1000
 FreeBSD systems running 8.1 in production... which would you choose? We're
 heavily leaning toward Firefox, but would love to hear other's opinions of
 Chrome (if it requires Linux emulation, that may be a death-knell, leaving
 Firefox the only real choice???).

I've been an avid Firefox user until ~1 month ago. I just couldn't put up with 
the sluggishness anymore. Tried to use Firefox 4 beta. No dice. The JS engine 
_is_ faster but that didn't solve the problem. The UI is just not OK. I used 
to think it was because of the multi-threaded design, until Opera rolled out 
version 10 which is just as snappy as Google Chrome. The only downside with 
Opera is that it's just too strict wrt standards. FF and Chrome use all kinds 
of quirks to make old websites render reasonably well. Still, given the 
current situation on FreeBSD, I'd go with Opera. I love Mozilla and its push 
towards a free/open web, but with version 4 they seem to have lost focus on 
what it matters for the majority of the people. Sure, fast web page rendering 
is important, but I for one wouldn't mind a slow[ish] render if I was able to 
quickly open another tab (page) to bash.org (just an example) while I wait for 
the other one to load.

Note that I use FreeBSD only on my servers. I use Linux for desktop, so take 
my suggestion with a grain of salt. :-)

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: File System Performance on FreeBSD

2010-08-08 Thread Mihai Donțu
On Sunday 08 August 2010 20:55:40 Antonio Vieiro wrote:
 I don't mind if a filesystem is very fast: I want it to be reliable
 first. I wonder if that Phoronix test suite checks for reliability first
 or not.

https://ext4.wiki.kernel.org/index.php/Ext4_Howto#Barriers_on_by_default

Since it has been declared stable, the performance of ext4 has dropped due to 
various reliability fixes, culminating with the making of write barriers a 
default.

More info here: http://lwn.net/Articles/283161/

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: FreeBSD's UFS vs Ext4

2010-02-08 Thread Mihai Donțu
On Monday 08 February 2010 12:54:26 Pieter de Goeje wrote:
  Even deleting a large file off that raid array I can
  see a difference, prior to reformatting, i deleted a 190GB file off the
  raid, under UFS the delete took quite some time (well over 10 seconds),
  under ext4 the deletion of the same size file took about 3 seconds.
 
 File deletion speed is relevant how?
 

It can be, depending on the workload. I (as a Linux user) moved from ext3 to 
xfs, ignoring the warnings about file deletion [being slow]. Now I _kind of_ 
regret it. Seems I have more than one program on my laptop that deletes files 
(kmail's email-expiration thing comes to mind). I also work on a project that 
creates large log files an deletes them (periodically). When all these 
programs meet, I go for a coffee. :)

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Problems with FreeBSD assembly

2009-11-11 Thread Mihai Donțu
On Wednesday 11 November 2009 21:43:21 David Jackson wrote:
 I am having great difficulty running a very simple assembler program on
 FreeBSD on x86 in my efforts to learn some assembly programming on
 FreeBSD.  I have tried to compile the following with nasm, however i get
 nothing in response when I attempt to run this program:
 
 section .data
 hello   db  'Hello, World!', 0xa
 hbytes  equ $ - hello
 
 section .text
 global  _start
 _start:
 pushdword hbytes
 pushdword hello
 pushdword 1
 mov eax,0x4
 int 0x80
 add esp,12
 
 pushdword 0
 mov eax,0x1
 int 0x80
 
 nasm -f elf -o hello1s.o hello1.s
 ld -s -o hello1s hello1s.o
 
 ./hello1s prints nothing.
 

I don't think the kernel is the one that initializes the 0, 1 and 2 file 
descriptors (stdin, stdout and stderr). I think you have to open them 
yourself. I will know for sure when my nasm port finishes installing. :)

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: accents in file names

2009-02-16 Thread Mihai Donțu
On Friday 13 February 2009, Chuck Swiger wrote:
 On Feb 12, 2009, at 2:50 PM, Wojciech Puchar wrote:
  accented letter to my freebsd box, the accented letter simply
  disappear.
 
  UFS supports 8-bit characters except for / and \0, but you also
  need to run a terminal with UTF8 support and use a correct font to
  view such things.
 
  why? i use ISO-8859-2

 You've answered why when you state that you set up a locale which
 supports ISO Latin-X charset.  If you are running in the default C/
 POSIX locale, using the US-ASCII character set and a font that only
 knows about 7-bit ASCII glyphs, then you won't get accented characters.

  UFS doesn't deal with encoding at all, just store what you give

 That's right, which means you need to use filenames encoded in UTF8
 rather than in arbitrary Unicode.

UTF-8 is what we prefer these days, but the filesystem can handle anything 
that is ASCII compatible (like you said: Shift_JIS, EUC-JP etc.).

Now, I assume Daniel was copying filé.txt from a non-UFS (Windows box, 
FAT32, NTFS etc) filesystem to UFS, because this is the only case I can think 
of and in which such a problem might appear.

 People in Asia tend to want UTF-16 
 or UTF-32 encoding (although historical encodings like Big5, Shift-
 JIS, and now GB18030 for China are still rather popular, and those are
 multibyte encodings), and things like gcc's implementation of
 widechars or Python are standardizing on UTF-32.

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: uptime 2 years!

2008-10-08 Thread Mihai Donțu
On Wednesday 08 October 2008, Jeremy Chadwick wrote:
 On Wed, Oct 08, 2008 at 08:54:47AM -0700, Chad Marshall wrote:
  Would like to share a success story which I'm sure you've had in the
  past but one of my servers running FreeBSD will have an uptime of 2
  years tomorrow. I plan on putting on my blog but as it doesn't have much
  reach but wanted to share with you since your community has made this
  possible. Please indicate where I could post this to have a bit more
  reach or if you'd like to put a link to my blog, I'd be more than happy
  to provide that.

 I don't want to rain on your parade, but uptime ultimately means squat.
 I can install FreeBSD on a box under my desk at home, on a UPS, and
 leave it powered on for the next 30 years -- it tells people absolutely
 nothing about the reliability of the OS, or what kind of stress it's
 undergone during that time.

 Additionally, long uptimes also reflect directly on sysadmins: I take it
 to mean the administrator is very lazy.  There are security holes
 (kernel or userland/library-level) which are exploitable on boxes which
 have been up for that kind of time.  I'm also making the assumption that
 said boxes have Internet connectivity, hence my point.

 Food for thought.  :-)

Or to put it mildly and not alienate Chad :), what was the box used for and, 
if it had Internet connectivity, how were the potential security issues 
handled within the last two years?

A Guy Ritchie kind of story will do just fine. :)

-- 
Mihai Donțu
unices.bitdefender.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: FreeBSD 5.4 chroot

2008-08-26 Thread Mihai Donțu
On Monday 25 August 2008, Kris Kennaway wrote:
 Mihai Donțu wrote:
  Hi,
 
  I've just installed a FreeBSD 6.0-RELEASE and I need a FreeBSD
  5.4-RELEASE chroot to build something in it (hw shortage). All nice and
  dandy, until I hit a /dev problem:
 
  # svn up
  svn: PROPFIND request failed on '/svn/project'
  svn: PROPFIND of '/svn/project': SSL negotiation failed: SSL disabled due
  to lack of entropy (https://svn.host.com)
 
  # ls -l /dev/random
  crw-rw-rw-  1 root  wheel  249,   0 Aug 25 16:19 /dev/random
 
  # cat /dev/random
  cat: /dev/random: Socket operation on non-socket
 
  # rm /dev/random
 
  # mknod /dev/mknod random c 0 10 root:wheel
 
  # chmod 0666 /dev/random
 
  # ls -l /dev/random
  crw-rw-rw-  1 root  wheel0,  10 Aug 25 18:28 /dev/random
 
  # cat /dev/random
  cat: /dev/random: Socket operation on non-socket
 
  Clearly, all those years of Linux chroot-ing have affected my brain, but
  Google isn't very helpful either. :) Could someone, please, hint me about
  what I'm doing wrong?

 mount a devfs instance to create the devices (see mount_devfs) instead
 of trying to mknod them by hand.

Works like magic. :) Thanks!

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


FreeBSD 5.4 chroot

2008-08-25 Thread Mihai Donțu
Hi,

I've just installed a FreeBSD 6.0-RELEASE and I need a FreeBSD 5.4-RELEASE 
chroot to build something in it (hw shortage). All nice and dandy, until I 
hit a /dev problem:

# svn up
svn: PROPFIND request failed on '/svn/project'
svn: PROPFIND of '/svn/project': SSL negotiation failed: SSL disabled due to 
lack of entropy (https://svn.host.com)

# ls -l /dev/random
crw-rw-rw-  1 root  wheel  249,   0 Aug 25 16:19 /dev/random

# cat /dev/random
cat: /dev/random: Socket operation on non-socket

# rm /dev/random

# mknod /dev/mknod random c 0 10 root:wheel

# chmod 0666 /dev/random

# ls -l /dev/random
crw-rw-rw-  1 root  wheel0,  10 Aug 25 18:28 /dev/random

# cat /dev/random
cat: /dev/random: Socket operation on non-socket

Clearly, all those years of Linux chroot-ing have affected my brain, but 
Google isn't very helpful either. :) Could someone, please, hint me about 
what I'm doing wrong?

Thank you,

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Using ZFS on FreeBSD 7.0

2008-02-27 Thread Mihai Donțu
On Thursday 28 February 2008, Rick Nekus wrote:
 Huh ? Date: Wed, 27 Feb 2008 14:49:40 -0800 From: [EMAIL PROTECTED] To:
 [EMAIL PROTECTED] CC: freebsd-questions@freebsd.org Subject: Re:
 Using ZFS on FreeBSD 7.0  Thanks Dan.  That answered my question. 
 I'm really happy to replace Solaris with FreeBSD.  All I have to do is
 import my zfs pool and then upgrade it...2 commands!On Wed, Feb
 27, 2008 at 1:19 PM, Dan Nelson [EMAIL PROTECTED] wrote:  
 In the last episode (Feb 27), Joe said:   I'm currently running
 Solaris 10 Update 4 on x86 hardware at home. I'm excited that
 ZFS is coming in FreeBSD 7.0. I've found that I don't really
 like Solaris that much (no ports!). I   find it so different from other
 OS's and I don't want to learn   another OS just to have a decent 
 fileserver. So I'm looking forward to migrating to FreeBSD 7.0
 from Solaris 10   Update 4. Since ZFS was ported from Solaris,
 at version of Solaris 10 or   OpenSolaris Nevada is FreeBSD 7.0 support
 similar to? In other words, will a lose some features, fixes,
 and enhancements in   ZFS on FreeBSD 7.0 or will I gain?   Going
 from S10U4 (zfs pool version 4) to FreeBSD 7 (v6) you will  actually
 gain gzip compression support. Opensolaris is up to v10.   --  Dan
 Nelson  [EMAIL PROTECTED]

[offtopic]

If you use the Hotmail interface, please don't, anymore :) It does horrible
things to your e-mails.

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: clocks and dualboot

2007-11-09 Thread Mihai Donțu
On Friday 09 November 2007, Aryeh M. Friedman wrote:
 I have a dual boot vista and freebsd machine I use ntpdate on the FB
 machine but then when I go into vista it reports for a different time
 zone (sometimes UTC other times PST)... ntpdate always corrects this
 on reboot but how do I keep the date correct on the vista side?

You must configure FreeBSD to keep the hardware clock to Local Time.
However, I lack the knowledge on how to do that. I'm sorry.

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: amd64_set_gsbase()

2007-10-22 Thread Mihai Donțu
On Wednesday 10 October 2007, Tijl Coosemans wrote:
  To get back to what you are trying to do, because %gs isn't preserved,
  I think you should avoid writing to it and instead strictly use
  amd64_set_gsbase(). But from what you've written, I'm guessing you're
  already doing this, so the next thing to try is to create threads with
  PTHREAD_SCOPE_SYSTEM or use libthr instead of libpthread, because if
  I'm not mistaken, PTHREAD_SCOPE_PROCESS in libpthread doesn't preserve
  gsbase either.

 Anyhoo, I'll try to use 'libthr' and see if this helps.

... and success! Indeed: 'amd64_set_gsbase()' + 'libthr.so' = love. 
'libpthread.so'
is a no-no :)

I'm not out of the woods yet, I still have some crashes, but I suspect that's 
just
bad programming on my side.

Thanks,

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: amd64_set_gsbase()

2007-10-10 Thread Mihai Donțu
On Wednesday 10 October 2007, Tijl Coosemans wrote:
 On Tuesday 09 October 2007 02:48:51 Mihai Donțu wrote:
  I have *one* more question: maybe I don't fully understand the hole
  BASE thing, but since the FreeBSD kernel does not preserve %gs and
  %fs, what is the purpose of amd64_set_XXbase()?
 
 The %fs, %gs registers and fsbase and gsbase MSRs are separate
 registers. When you write %gs:offset, you actually get (gsbase+offset),
 so the actual value of %gs doesn't matter.
 
 There are two ways to set gsbase. One is by using the privileged
 instruction wrmsr to set gsbase directly (full 64bit base address),
 which is what amd64_set_gsbase() exposes to userland. The other is by
 loading a descriptor selector in %gs in which case gsbase will be set
 to the base address (only 32bit base address) of a descriptor entry in
 either the GDT or LDT.

Invaluable info. Thanks! :)

 To get back to what you are trying to do, because %gs isn't preserved,
 I think you should avoid writing to it and instead strictly use
 amd64_set_gsbase(). But from what you've written, I'm guessing you're
 already doing this, so the next thing to try is to create threads with
 PTHREAD_SCOPE_SYSTEM or use libthr instead of libpthread, because if
 I'm not mistaken, PTHREAD_SCOPE_PROCESS in libpthread doesn't preserve
 gsbase either.

Well, I'm am not setting (loading) %gs, I *only* do amd64_set_gsbase() and
expect that *all* instructions such as:
mov %gs:0x10,%rax
to be valid (not segfault). I don't really care what the value of %gs is
as long as *all* the instructions as the above work and access the memory
specified in amd64_set_gsbase( addr ).

I was under the (wrong) impression that the value of %gs is important,
that's why I wanted it preserved, but if you say:
 [...] When you write %gs:offset, you actually get (gsbase+offset),
 so the actual value of %gs doesn't matter.
then I don't care if %gs' value gets lost over context switches as long as
mov %gs:0x10,%rax
and other such instructions, work.

However, it turns out that amd64_set_gsbase() is not enough :( Either:
a) someone *does* set %gs (and is not me);
b) the 'gsbase' gets lost;

The thing is I've ported my emulator to Linux and there I use modify_ldt()
and then some __asm__ voodoo to load %gs, because (quote from man):
- ARCH_SET_GS is disabled in some kernels.
- Context switches for 64-bit segment bases are rather expensive. It may
   be a faster alternative to set a 32-bit base using a segment selector
   by setting up an LDT with modify_ldt(2) [...]

Anyhoo, I'll try to use 'libthr' and see if this helps.

Thanks, again!

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


amd64_set_gsbase()

2007-10-08 Thread Mihai Donțu
Hi,

I have a small amd64 program that makes havy use of LDT (%GS to be more
specific). The trouble is, in a multithreaded environment, the selector
value gets lost (or reset?).

The code *always* segfaults with this stack:
  4 LWP 100126  0x000800dec07c in select () from /lib/libc.so.6
* 3 Thread 0x517000 (runnable)  0x00080055cfbc in ?? ()
  2 Thread 0x517400 (LWP 100125)  0x000800c0d85c in pthread_testcancel () 
from /lib/libpthread.so.2
  1 Thread 0x517800 (runnable)  0x000800d5d000 in makecontext () from 
/lib/libc.so.6

at this instruction:
  0x00080055cfbc: mov%gs:0x10,%r11

  (gdb) p $gs
  $1 = 0

I've been reading on the net something about the kernel not preserving the GS
across syscalls (or stmh). Is this true? and if so, is there a known workaround?

I'm on a FreeBSD 6.2-STABLE-200706 (AMD64) machine.

Thanks,

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: amd64_set_gsbase()

2007-10-08 Thread Mihai Donțu
On Monday 08 October 2007, Jung-uk Kim wrote:
 Yes, you are correct.  A short version is don't do that.  A long 
 version goes like this.  %fs and %gs are not preserved while context 
 switching on amd64.

But this makes emulation software such as Wine a lost hope, doesn't it?
Because Windows apps access the Thread Information Block (TIB) via %gs
(%fs on ia32).

Anyway, my so called small program is actually a Win64 emulator and
I need the segment selector to stay put across syscalls. It works
like a charm on single threaded apps, but as soon as I spawn a thread,
all hell breaks loose :)

I've managed to come up with something that *kind of* works. It goes
like this:

void my_handler( int s )
{
if ( s == SIGSEGV ) {
if ( get_gs() == 0 ) {
amd64_set_gsbase();
} else {
signal( SIGSEGV, SIG_DFL );
}
}
}

int my_init( void )
{
/* alloc TIB memory and initialize */

amd64_set_gsbase( lpTIB );
signal( SIGSEGV, my_handler );

return 0;
}

but after a series of dlopen()-s, my_handler() is called without %gs
being zero and without a valid fault (the handler does not get recalled
after signal( SIGSEGV, SIG_DFL ). I'm still working on this aspect ...

 In fact, you should not use amd64_set_gsbase() 
 directly.  If you *really* have to mess up with base addresses, you 
 have to use sysarch(2) syscall, i.e., sysarch(AMD64_SET_GSBASE, 
 args).

I found this: /usr/src/lib/libc/amd64/sys/amd64_set_gsbase.c:32

int
amd64_set_gsbase(void *addr)
{
return (sysarch(AMD64_SET_GSBASE, addr));
}


and this (man 2 sysarch()): The sysarch() system call should never be
called directly by user programs.  Instead, they should access its
functions using the architecture-dependent library.

Who am I suppose to believe? :)

 However, it only changes the base address via MSR, i.e., %gs  
 itself has no meaning.

Maybe, but the selector loaded in %gs *does* have meaning.

Anyway, the thing is I _have_ to make this work. I'll keep you posted ;)

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: amd64_set_gsbase()

2007-10-08 Thread Mihai Donțu
On Tuesday 09 October 2007, Jung-uk Kim wrote:
 In long mode, we don't really care about segment registers.  While 
 implementing TLS for Linuxulator, I had to do the following hack, for 
 example:
 
 http://docs.freebsd.org/cgi/mid.cgi?20070336.l2U06LA1075891
 
 Under Linux and Windows, they do preserve segment registers vs. base 
 addresses mapping for backward compatibility, AFAIK with some 
 performance penalty.

Ah! But you are doing your magic _in the kernel_. I don't have this luxury :)
I have to do everything in user space (as a normal user) on an out-of-the-box
FreeBSD (-stable).

I have *one* more question: maybe I don't fully understand the hole BASE thing,
but since the FreeBSD kernel does not preserve %gs and %fs, what is the purpose
of amd64_set_XXbase()?

Thanks,

-- 
Mihai Donțu
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]