SVGALib 2.0

I sent something similar to this message a long time ago, but I don’t think
it ever appeared on the list, and I completely forgot about it.

If you haven’t noticed, SVGALib 2.0 will soon be coming out. The pre-2.0s
are very stable, and they have an outstanding feature–they don’t require
root! They use a kernel module. Anyways, SDL has code to check whether the
user is root or not, which in the new 2.0 series won’t matter. I have a
patch I made a while back (so I don’t know if it works with the latest CVS,
but I don’t think you’ve changed the code)–all it does is disable the
root-checking part.

If you haven’t checked out the latest SVGALib, do yourself a favor and do it
at http://www.svgalib.org/. It’s a nice alternative now to FBCon, which I
personally can’t use because of incompatibilities between my NVidia FBCon and
X11. I’d use the FB driver but it lacks hardware-accelerated features.
Anyways, when I last tested it, all the examples I tried worked (except of
course the OpenGL one), so if someone will look at it (fix it up however you
want), and commit it to CVS I’d be most grateful. :-)–
~StoverTech~
Benjamin Joel Stover
-------------- next part --------------
Index: src//video/svga/SDL_svgavideo.c

RCS file: /cvs/SDL/src/video/svga/SDL_svgavideo.c,v
retrieving revision 1.1.2.12
diff -u -r1.1.2.12 SDL_svgavideo.c
— src//video/svga/SDL_svgavideo.c 2001/04/04 02:47:57 1.1.2.12
+++ src//video/svga/SDL_svgavideo.c 2001/04/21 19:53:49
@@ -88,7 +88,12 @@
console = -1;
}
}

  • return((geteuid() == 0) && (console >= 0));
  • return(
    +/* This code is disabled because SVGALib 2.0 does not need root! */
    +#if 0
  • (geteuid() == 0) &&
    +#endif
  • (console >= 0));
    }

static void SVGA_DeleteDevice(SDL_VideoDevice *device)

I seriously hope I’m not bugging anyone. However, I submitted an extremely
small patch a few days ago about losing the root-checking in SVGALib because
the new pre-2.0 series don’t require root. I really would like to see this
patch in SDL, because I don’t have FBCon as an option. If anyone (I think
Sam is in charge–fairly new to SDL) has or will submit it to CVS, or if not,
I’d like to know. If there’s anything more I can do with the patch (perhaps
detect what version of SVGALib they have to determine whether or not to check
for root), then I’ll do it.

Again, not trying to irritate anyone. It’s just an important, though very
small patch to me. Thanks for your time, and I’ll leave this topic alone if
no one replies.–
~StoverTech~
Benjamin Joel Stover

I seriously hope I’m not bugging anyone. However, I submitted an extremely
small patch a few days ago about losing the root-checking in SVGALib because
the new pre-2.0 series don’t require root.

and here was the patch:

  •   return((geteuid() == 0) && (console >= 0));
    
  •   return(
    

+/* This code is disabled because SVGALib 2.0 does not need root! */
+#if 0

  •    (geteuid() == 0) &&
    

+#endif

  •    (console >= 0));
    

which is not quite good enough — the SVGA_Available() function should
be accurate even if the user has an older svgalib, or doesn’t have the
new svga kernel module installed, and the code should test for this
in a reliable way

(Speaking of which, I find the svgalib kernel module hack quite ugly.
Instead of inventing their own (pc-centric, no doubt) kernel module,
why not fix fbcon which does essentially the same thing? Or come up with a
way to restrict a file descriptor to a certain offset interval, so
that a user-space daemon can pass restricted fds of the video memory
to client processes? I smell Not Invented Here syndrome from far away)

and here was the patch:

  •   return((geteuid() == 0) && (console >= 0));
    
  •   return(
    

+/* This code is disabled because SVGALib 2.0 does not need root! */
+#if 0

  •    (geteuid() == 0) &&
    

+#endif

  •    (console >= 0));
    

which is not quite good enough — the SVGA_Available() function should
be accurate even if the user has an older svgalib, or doesn’t have the
new svga kernel module installed, and the code should test for this
in a reliable way

Benjamin, if you rewrite it so that it works correctly with both older
and newer versions of SVGAlib, I’ll be happy to include it.

See ya!
-Sam Lantinga, Lead Programmer, Loki Software, Inc.

which is not quite good enough — the SVGA_Available() function should
be accurate even if the user has an older svgalib, or doesn’t have the
new svga kernel module installed, and the code should test for this
in a reliable way

Thanks, I’ll look into it. :slight_smile:

(Speaking of which, I find the svgalib kernel module hack quite ugly.
Instead of inventing their own (pc-centric, no doubt) kernel module,
why not fix fbcon which does essentially the same thing? Or come up with a
way to restrict a file descriptor to a certain offset interval, so
that a user-space daemon can pass restricted fds of the video memory
to client processes? I smell Not Invented Here syndrome from far away)

Well, unfortunately, fbcon doesn’t work right with X. I’m using the NVidia
drivers (TNT2), and currently the fbcon kernel code and the X accelerated
drivers conflict. I’d switch the X driver to fbcon, but I really need the
hardware-accelerated drivers (well not need, but I’d rather have it than
fbcon). If you know of a way to fix the conflicts between them, I’d love to
know. I just figured since SDL supports SVGALib, and seems to support it
quite well, it wouldn’t hurt to suppose the pre-2.0 features. :slight_smile:

I hadn’t looked into the SVGALib code myself, but at least it worked pretty
well. I sure wish they would’ve thought it out though. Some people just
don’t have fbcon is an option, and X is nice (especially for the hardware
accelerated stuff), but you just can’t beat the direct-access speed as user
mode that SVGALib and fbcon give you.

But please, if I could get fbcon working, I’d be most appreciative. :stuck_out_tongue: If
you need to know more specs, I’m using 2.4.2 with the latest X NVidia drivers
and X 4.0.1 I think (either that or 4.0.2).–
~StoverTech~
Benjamin Joel Stover

which is not quite good enough — the SVGA_Available() function should
be accurate even if the user has an older svgalib, or doesn’t have the
new svga kernel module installed, and the code should test for this
in a reliable way

Benjamin, if you rewrite it so that it works correctly with both older
and newer versions of SVGAlib, I’ll be happy to include it.

I’m not sure if you are going to like this patch much better, but after some
searching it was the best thing I could come up with. After some futile
attempts at looking through the SVGALib docs, I couldn’t find anything that
tells you how to know what version of SDL to use. So, I examined my
vga.h–and noticed at the top it defined SVGALIB_VER to 0x010900. Looking at
the earlier versions of SVGALib (including the latest stable one), I found
out that SVGALIB_VER wasn’t defined until the 1.9.x series. That’s all this
patch does, so it isn’t much of an improvement to the old one.

I see a couple of potentially drawbacks of this approach. For all I know,
they might remove SVGALIB_VER sometime in the future. If you compile SDL
with version 1.4.x and then upgrade to 1.9.x, SDL will still think that it is
using 1.4.x (since it is a preprocessor directive). I wish SVGALIB_VER was
documented somewhere…

This is the best solution I’ve come up with so far. If I have missed
anything any of you know about, feel free to notify me so I can make another
patch. It would be ideal to have a function that checks to see if SVGALib is
available (I mean in the library itself). I was thinking about using
vga_init for this, but I couldn’t find any function that would deinitialize
it after we check the value. We could look internally in the library for
what it calls when SVGALib exits, but IMHO that’s worse than this patch.

I was thinking about e-mailing the SVGALib about other methods that they know
of (that just aren’t documented). Basically this patch replaces #ifdef 0 to
#ifndef SVGALIB_VER (and a big comment before that for any future reference
down the road). Sorry it isn’t much of a difference (though I did quite a
bit more work than what appears :)). I’m open to any suggestions. I think
this patch will do the trick though. I didn’t test it on 1.4.x or anything,
so it’d be nice to confirm that it works on their machines.

Hmm… I just thought of another problem. Since it is a preprocessor
directive, any precompiled versions will either think there’s 1.9.x+ or
something below that. Any ideas?–
~StoverTech~
Benjamin Joel Stover

Sorry forgot about the patch. :-)–
~StoverTech~
Benjamin Joel Stover
-------------- next part --------------
Index: SDL_svgavideo.c

RCS file: /cvs/SDL/src/video/svga/SDL_svgavideo.c,v
retrieving revision 1.1.2.12
diff -u -r1.1.2.12 SDL_svgavideo.c
— SDL_svgavideo.c 2001/04/04 02:47:57 1.1.2.12
+++ SDL_svgavideo.c 2001/06/15 19:36:31
@@ -88,7 +88,21 @@
console = -1;
}
}

  • return((geteuid() == 0) && (console >= 0));
  • return(

+/* The new SVGALib (from 1.9.x and up) do not require root to be used.

    • Therefore, this function must take consideration about what version
    • of SVGALib is being used. As of now, there is no documentation about
    • doing this. After carefully examing some different SVGALib versions,
    • I found out only 1.9.x+ has defined SVGALIB_VER. For now, this is
    • the only way (AFAIK) to tell between the two different versions.
  • */
    +#ifndef SVGALIB_VER
  • (geteuid() == 0) &&
    +#endif
  • (console >= 0));
    }

static void SVGA_DeleteDevice(SDL_VideoDevice *device)

(please don’t send patches base64-encoded - keep them in ascii in the mail
body)

Looking at
the earlier versions of SVGALib (including the latest stable one), I found
out that SVGALIB_VER wasn’t defined until the 1.9.x series. That’s all this
patch does, so it isn’t much of an improvement to the old one.

why not just do (pseudocode)

if(geteuid() == 0 || open(/dev/svga, O_RDWR) == 0) then yes, else no

? Because that’s basically what you want to know

why not just do (pseudocode)
if(geteuid() == 0 || open(/dev/svga, O_RDWR) == 0) then yes, else no
? Because that’s basically what you want to know

I never woulda thought of that. :stuck_out_tongue: Thanks though. OK, I’ve finished the
patch. Sorry about the base64-encoded. Didn’t even notice I was doing that.
:slight_smile: Sometimes I don’t see the simplest things. It’s my curse. Anyways, I
think this patch should work. However, it only checks for /dev/svga – and
not anything like /dev/svga1 etc. I think the SVGALib always produces it
though (mine wasn’t even a link to /dev/svga1 or something similar–it was a
device). My system has /dev/svga and /dev/svga1-4. I thought that was
strange (I guess /dev/svga is like /dev/svga0?). Anyways I guess I could
look for just /dev/svga and /dev/svga#.

I haven’t tested it on earlier SVGALib versions, so it’d be nice for someone
to confirm that it works. However, it’s such a simple patch I don’t think it
will matter. I also got rid of an implicate definition warning for ioctl.

$cd SDL_DIR
$patch -p0 < svgalib.diff

I think that’s it. :slight_smile: Thanks for all the help Sam and Mattias. Sorry for
all the trouble over something so simple.–
~StoverTech~
Benjamin Joel Stover
-------------- next part --------------
A non-text attachment was scrubbed…
Name: svgalib.diff
Type: text/x-c
Size: 1087 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20010615/1c7e9d5c/attachment.bin

Shouldn’t that be:

if(geteuid() == 0 || open(/dev/svga, O_RDWR) >= 0) then yes, else no

and maybe close it if it does succeed, so as not to leak a file handle. :slight_smile:

-RayOn Friday 15 June 2001 17:43, you wrote:

(please don’t send patches base64-encoded - keep them in ascii in the mail
body)

Looking at
the earlier versions of SVGALib (including the latest stable one), I found
out that SVGALIB_VER wasn’t defined until the 1.9.x series. That’s all
this patch does, so it isn’t much of an improvement to the old one.

why not just do (pseudocode)

if(geteuid() == 0 || open(/dev/svga, O_RDWR) == 0) then yes, else no

? Because that’s basically what you want to know

and maybe close it if it does succeed, so as not to leak a file handle. :slight_smile:

I think it was just meant to show how to do it. My patch handles the file
handle thing so it doesn’t leak, and it also checks for the proper return
value (man is your friend…hmm, that doesn’t sound right :)).–
~StoverTech~
Benjamin Joel Stover

Shouldn’t that be:

if(geteuid() == 0 || open(/dev/svga, O_RDWR) >= 0) then yes, else no

uh, yes, of course. Make it

return (geteuid() == 0 || close(open("/dev/svga", O_RDWR)) == 0);

and it should work (since close(-1) is defined and generates EBADF)