Bug 968244 - Make IPDL-generated code not crash on bad shmems - r=bent
authorBenoit Jacob <bjacob@mozilla.com>
Tue, 25 Feb 2014 08:57:10 -0500
changeset 170713 ceac6a4674d23a4816e7d45faac9b27c7748c6e3
parent 170712 675c6efa096fe08402126cf79513439c764353ed
child 170749 465f58380970aca163a54566e9d46cc1c7046bec
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbent
bugs968244
milestone30.0a1
Bug 968244 - Make IPDL-generated code not crash on bad shmems - r=bent
ipc/ipdl/ipdl/lower.py
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -4030,35 +4030,44 @@ class _GenerateProtocolActorCode(ipdl.as
         # bool AllocShmem(size_t size, Type type, Shmem* outmem):
         allocShmem = allocShmemMethod('AllocShmem', False)
 
         # bool AllocUnsafeShmem(size_t size, Type type, Shmem* outmem):
         allocUnsafeShmem = allocShmemMethod('AllocUnsafeShmem', True)
 
         # bool AdoptShmem(const Shmem& mem, Shmem* outmem):
         #   SharedMemory* raw = mem.mSegment;
-        #   if (!raw || IsTrackingSharedMemory(raw))
-        #     RUNTIMEABORT()
+        #   if (!raw || IsTrackingSharedMemory(raw)) {
+        #     NS_WARNING("bad Shmem"); // or NS_RUNTIMEABORT on child side
+        #     return false;
+        #   }
         #   id_t id
         #   if (!AdoptSharedMemory(raw, &id))
         #     return false
         #   *outmem = Shmem(raw, id);
         #   return true;
         adoptShmem = MethodDefn(MethodDecl(
             'AdoptShmem',
             params=[ Decl(_shmemType(const=1, ref=1), memvar.name),
                      Decl(_shmemType(ptr=1), outmemvar.name) ],
             ret=Type.BOOL))
 
         adoptShmem.addstmt(StmtDecl(Decl(_rawShmemType(ptr=1), rawvar.name),
                                     init=_shmemSegment(memvar)))
         ifbad = StmtIf(ExprBinary(
             ExprNot(rawvar), '||',
             ExprCall(ExprVar('IsTrackingSharedMemory'), args=[ rawvar ])))
-        ifbad.addifstmt(_runtimeAbort('bad Shmem'))
+        badShmemActions = []
+        if (self.side == 'child'):
+            badShmemActions.append(_runtimeAbort('bad Shmem'));
+        else:
+            badShmemActions.append(_printWarningMessage('bad Shmem'));
+        badShmemActions.append(StmtReturn.FALSE);
+        ifbad.addifstmts(badShmemActions)
+
         adoptShmem.addstmt(ifbad)
 
         ifadoptfails = StmtIf(ExprNot(ExprCall(
             p.adoptSharedMemory(), args=[ rawvar, ExprAddrOf(idvar) ])))
         ifadoptfails.addifstmt(StmtReturn.FALSE)
 
         adoptShmem.addstmts([
             Whitespace.NL,
@@ -4069,29 +4078,30 @@ class _GenerateProtocolActorCode(ipdl.as
                               _shmemCtor(rawvar, idvar))),
             StmtReturn.TRUE
         ])
 
         # bool DeallocShmem(Shmem& mem):
         #   bool ok = DestroySharedMemory(mem);
         ##ifdef DEBUG
         #   if (!ok) {
-        #     NS_RUNTIMEABORT("bad Shmem");
+        #     NS_WARNING("bad Shmem"); // or NS_RUNTIMEABORT on child side
+        #     return false;
         #   }
         ##endif // DEBUG
         #   mem.forget();
         #   return ok;
         deallocShmem = MethodDefn(MethodDecl(
             'DeallocShmem',
             params=[ Decl(_shmemType(ref=1), memvar.name) ],
             ret=Type.BOOL))
         okvar = ExprVar('ok')
 
         ifbad = StmtIf(ExprNot(okvar))
-        ifbad.addifstmt(_runtimeAbort('bad Shmem'))
+        ifbad.addifstmts(badShmemActions)
 
         deallocShmem.addstmts([
             StmtDecl(Decl(Type.BOOL, okvar.name),
                      init=ExprCall(p.destroySharedMemory(),
                                    args=[ memvar ])),
             CppDirective('ifdef', 'DEBUG'),
             ifbad,
             CppDirective('endif', '// DEBUG'),