Showing posts with label solaris. Show all posts
Showing posts with label solaris. Show all posts

2007-09-09

DTrace and C++

Solaris DTrace isn't that C++ friendly. The SDT provider doesn't work with C++ programs. But I have fortunately managed to find a workaround. Not pretty, but it works.

2007-08-06

Concurrent shared memory allocator

I have recently adapted Solaris's libmtmalloc(3) to satisfy allocation requests from shared memory segments; it works both with POSIX and SYSV shared memory. You can get the code here. I knew about a similar project, but I have no idea how well does it scale with increasing number of concurrent processes.

2007-08-04

Prex, DTrace and linux lameness

Adam Leventhal has in his blog exposed the lameness of the SystemTap team (e.g. they claim that they weren't inspired by DTrace at all, but output format of some of their utilities is identical to that of DTrace). He also took an amusing photo showing that users are not very happy with SystemTap.

But I want to point to another very useful tool that got completely shadowed by DTrace: TNF tracing. In short, it is "printf() debugging" on steroids; read the tracing(3TNF) man page for more details. The TNF logging probes must be manually inserted in the source code at places where printf() would be put, and they produce no output by default. When you run the program under the control of prex(1) program, you may choose to log the otuput of all probes, or select just a subset of them (they are named!). The trace is later analyzed with the tnfdump(1) program. The best thing is that prex works also on running programs; it can attach to them, collect data and detach at later point.

TNF has been an enormous help in finding and correcting complex, time-dependent problems that I'd have much harder time to resolve otherwise.

2007-08-03

Solaris signal handling bug, part 2

My initial report has been confirmed to be a genuine bug. Even more interesting, the bug has been introduced in Solaris 8, and hasn't been noticed until few days ago. Wow :)

2007-07-29

A possible signal handling bug in Solaris

I know that combining threads and signals is a bad idea, but I just couldn't resist the temptation. It seemed like a nice solution until I've hit what seems to be a possible signal handling bug: sometimes the signal is not delivered on the alternate signal stack, even though a thread has requested so. You can read the full description here. I wonder whether I'll get a reply. In the mean-time, I'm abandoning threads in favor of multiple processes operating over a large shared memory segment.

2007-04-24

Solaris 11, xemacs and dbx

I have recently installed Solaris Express (Solaris 11), first in one virtual machine and then on "bare metal". I have to say that I'm very pleasantly surprised. The installation went very smooth, the only "configuration" neccessary was to enter time, location, select additional locales, type in the root password and to create a new non-root user upon first login. The default desktop is GNOME and looks very polished up. Security-wise, the installation seems very sane. There are many services bound on TCP ports, but almost all of them only to the loopback interface (meaning that only local programs can connect to them). The only publicly open ports are 111 (rpcbind) and 22 (ssh), 6011 and 6010 (I guess, X). And sshd is configured to not permit root logins by default.

I tried Sun Studio 11, but.. being used to emacs, it doesn't feel quite right (+ it's not comfortable to use it if you're running it over remote X11 connection). However, Solaris has a very nice toolbox for programmers: dbx, mdb, dtrace and tnf (man tracing), different malloc libraries, etc. It's really very advanced OS, and very developer-friendly. Plus there are zones, fine-grained privilege and role system which works... And everything is excellently documented in man pages. I'm too short on time right now to describe all the goodies, but.. I'm impressed. By the installation, default settings, and overall consistency and look&feel of the system. I can only say excellent work to all the Solaris developers, and a big thanks to Sun for making it all available at no charge.

Now, to the topic: I had a problem with xemacs not displaying source files when I used it with dbx to debug a multi-directory project. The problem turned out to be that dbx does not by default display full path to the source file. xemacs looks for the file in the wrong directory and consequently does not show the source you're supposed to be debugging. You can solve this problem by putting the following line in your .dbxrc:

DBX_output_short_file_name=off

2007-04-10

Linux signal handling is broken

Enter sigaction() in combination with SA_SIGINFO flag. Such signal handler accepts three arguments, the third being the context (full machine state needed to resume it, eg. registers) of the interrupted thread.

First problem: linux ABI is broken. The FP state in the uc_mcontext member of the ucontext_t structure is pointer, instead of value. This makes copying of the context nontrivial.

Second problem: You can't use setcontext() to leave signal handler and jump into another, previously saved, context. (Or, for that matter, you can't use it to return to the very same context passed as argument to the signal handler.) In other words, signal handler like
static void sighandler(
  int signo, siginfo_t *psi, void *pv)
{
  memcpy(puc_old, pv, sizeof(ucontext_t));
  /* choose another context to dispatch */
  setcontext(puc_another);
}
does not work. It does not restore signal mask specified in the puc_other, does not reestablish alternate signal stack, etc. However, this scheme works flawlessly on Solaris.

How am I fixing it on Linux? I walk the stack frames (following the saved stack frame pointer), modify the return address so that the signal handler returns to itself instead to the interrupted context, etc. Very ugly and nonportable.

Not to mention that I'm relying on luck: it seems that, under current linux kernel, it is not possible to atomically restore signal mask and return from signal handler to context other than the immediately interrupted one. (Heck, it's not even possible to do it nonatomically without resorting to "black magic" involving reading hex dumps of stack frames.)

I'm installing Solaris in a virtual machine to try it out, and I'm seriously considering to move my development to Solaris.