int NaClDescImcShmInternalize(struct NaClDesc **out_desc, struct NaClDescXferState *xfer, struct NaClDescQuotaInterface *quota_interface) { int rv; struct NaClDescImcShm *ndisp; NaClHandle h; nacl_off64_t hsize; UNREFERENCED_PARAMETER(quota_interface); rv = -NACL_ABI_EIO; ndisp = malloc(sizeof *ndisp); if (NULL == ndisp) { rv = -NACL_ABI_ENOMEM; goto cleanup; } if (!NaClDescInternalizeCtor((struct NaClDesc *) ndisp, xfer)) { free(ndisp); ndisp = NULL; rv = -NACL_ABI_ENOMEM; goto cleanup; } if (xfer->next_handle == xfer->handle_buffer_end) { rv = -NACL_ABI_EIO; goto cleanup; } if (xfer->next_byte + sizeof ndisp->size > xfer->byte_buffer_end) { rv = -NACL_ABI_EIO; goto cleanup; } h = *xfer->next_handle; *xfer->next_handle++ = NACL_INVALID_HANDLE; memcpy(&hsize, xfer->next_byte, sizeof hsize); xfer->next_byte += sizeof hsize; if (!NaClDescImcShmSubclassCtor(ndisp, h, hsize)) { rv = -NACL_ABI_EIO; goto cleanup; } *out_desc = (struct NaClDesc *) ndisp; rv = 0; cleanup: if (rv < 0) { NaClDescSafeUnref((struct NaClDesc *) ndisp); } return rv; }
int NaClDescImcShmCtor(struct NaClDescImcShm *self, NaClHandle h, nacl_off64_t size) { struct NaClDesc *basep = (struct NaClDesc *) self; int rv; basep->base.vtbl = (struct NaClRefCountVtbl const *) NULL; if (!NaClDescCtor(basep)) { return 0; } rv = NaClDescImcShmSubclassCtor(self, h, size); if (!rv) { /* NaClDescImcShm construction failed, still a NaClDesc object */ (*NACL_VTBL(NaClRefCount, basep)->Dtor)((struct NaClRefCount *) basep); } (*NACL_VTBL(NaClDesc, basep)->SetFlags)(basep, NACL_ABI_O_RDWR); return 1; }