From ee528c2e9aa7d0a6463a2fea2b58624e67ddce02 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sun, 28 Mar 2010 00:46:48 +0000 Subject: [PATCH] Dynamically detect width/height, allocate black_ from non-cached volatile Mach memory, turn off super verbose RFB logging, and deal with a pool-related memory leak. --- Tweak.mm | 38 +++++++++++++++++++++++++++++--------- control | 2 +- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Tweak.mm b/Tweak.mm index 852ad7e..de862ab 100644 --- a/Tweak.mm +++ b/Tweak.mm @@ -46,6 +46,7 @@ #include #include +#include #import #import @@ -61,8 +62,8 @@ #import #import -static size_t Width = 320; -static size_t Height = 480; +static size_t width_; +static size_t height_; static const size_t BytesPerPixel = 4; static const size_t BitsPerSample = 8; @@ -246,8 +247,11 @@ static void VNCNotifySettings( static rfbBool VNCCheck(rfbClientPtr client, const char *data, int size) { @synchronized (condition_) { if (NSString *password = reinterpret_cast(screen_->authPasswdData)) { + NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); rfbEncryptBytes(client->authChallenge, const_cast([password UTF8String])); - return memcmp(client->authChallenge, data, size) == 0; + bool good(memcmp(client->authChallenge, data, size) == 0); + [pool release]; + return good; } return TRUE; } } @@ -441,14 +445,22 @@ static rfbNewClientAction VNCClient(rfbClientPtr client) { return action; } -static rfbPixel black_[320][480]; +static rfbPixel *black_; + +static void VNCBlack() { + if (_unlikely(black_ == NULL)) + black_ = reinterpret_cast(mmap(NULL, sizeof(rfbPixel) * width_ * height_, PROT_READ, MAP_ANON | MAP_PRIVATE | MAP_NOCACHE, VM_FLAGS_PURGABLE, 0)); + screen_->frameBuffer = reinterpret_cast(black_); +} static void VNCSetup() { + rfbLogEnable(false); + @synchronized (condition_) { int argc(1); char *arg0(strdup("VNCServer")); char *argv[] = {arg0, NULL}; - screen_ = rfbGetScreen(&argc, argv, Width, Height, BitsPerSample, 3, BytesPerPixel); + screen_ = rfbGetScreen(&argc, argv, width_, height_, BitsPerSample, 3, BytesPerPixel); free(arg0); VNCSettings(); @@ -464,7 +476,7 @@ static void VNCSetup() { screen_->serverFormat.greenShift = BitsPerSample * 1; screen_->serverFormat.blueShift = BitsPerSample * 0; - screen_->frameBuffer = reinterpret_cast(black_); + VNCBlack(); screen_->kbdAddEvent = &VNCKeyboard; screen_->ptrAddEvent = &VNCPointer; @@ -518,19 +530,27 @@ MSHook(kern_return_t, IOMobileFramebufferSwapSetLayer, int flags ) { if (_unlikely(screen_ == NULL)) { + CGSize size; + IOMobileFramebufferGetDisplaySize(fb, &size); + + width_ = size.width; + height_ = size.height; + + NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); VNCSetup(); VNCEnabled(); + [pool release]; } else if (_unlikely(clients_ != 0)) { if (buffer == NULL) - screen_->frameBuffer = reinterpret_cast(black_); + VNCBlack(); else { CoreSurfaceBufferLock(buffer, 2); - rfbPixel (*data)[480] = reinterpret_cast(CoreSurfaceBufferGetBaseAddress(buffer)); + rfbPixel *data(reinterpret_cast(CoreSurfaceBufferGetBaseAddress(buffer))); screen_->frameBuffer = const_cast(reinterpret_cast(data)); CoreSurfaceBufferUnlock(buffer); } - rfbMarkRectAsModified(screen_, 0, 0, Width, Height); + rfbMarkRectAsModified(screen_, 0, 0, width_, height_); } return _IOMobileFramebufferSwapSetLayer(fb, layer, buffer, bounds, frame, flags); diff --git a/control b/control index b7f4f57..05fc751 100644 --- a/control +++ b/control @@ -5,7 +5,7 @@ Priority: optional Section: Networking Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 0.9.3144-1 +Version: 0.9.3145-1 Description: a VNC /server/ for the iPhone Name: Veency Depends: mobilesubstrate (>= 0.9.2966-1), libvncserver, com.saurik.iphone.ske, preferenceloader, jp.ashikase.mousesupport | firmware (<< 3.0) -- 2.45.2