1 : /*
2 : * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 : #include "native_client/src/trusted/service_runtime/nacl_reverse_quota_interface.h"
8 : #include "native_client/src/include/portability.h"
9 : #include "native_client/src/include/nacl_macros.h"
10 :
11 : #include "native_client/src/shared/platform/nacl_log.h"
12 : #include "native_client/src/shared/platform/nacl_sync.h"
13 : #include "native_client/src/shared/platform/nacl_sync_checked.h"
14 : #include "native_client/src/shared/srpc/nacl_srpc.h"
15 :
16 : #include "native_client/src/trusted/desc/nacl_desc_base.h"
17 : #include "native_client/src/trusted/desc/nacl_desc_quota.h"
18 : #include "native_client/src/trusted/desc/nacl_desc_quota_interface.h"
19 :
20 : #include "native_client/src/trusted/reverse_service/reverse_control_rpc.h"
21 : #include "native_client/src/trusted/service_runtime/sel_ldr.h"
22 :
23 : /*
24 : * A descriptor quota interface that works over the reverse channel to Chrome.
25 : */
26 :
27 0 : static void ReverseQuotaDtor(struct NaClRefCount *nrcp) {
28 0 : NaClLog(4, "NaClReverseQuotaInterfaceDtor\n");
29 0 : nrcp->vtbl = (struct NaClRefCountVtbl *)(&kNaClDescQuotaInterfaceVtbl);
30 0 : (*nrcp->vtbl->Dtor)(nrcp);
31 0 : }
32 :
33 : static int64_t ReverseQuotaWriteRequest(
34 : struct NaClDescQuotaInterface *vself,
35 : uint8_t const *file_id,
36 : int64_t offset,
37 0 : int64_t length) {
38 : struct NaClReverseQuotaInterface *self =
39 0 : (struct NaClReverseQuotaInterface *) vself;
40 : NaClSrpcError rpc_result;
41 : int64_t allowed;
42 : int64_t rv;
43 :
44 0 : NaClLog(4, "Entered NaClReverseQuotaWriteRequest\n");
45 0 : NaClXMutexLock(&self->nap->mu);
46 0 : if (NACL_REVERSE_CHANNEL_INITIALIZED !=
47 : self->nap->reverse_channel_initialization_state) {
48 0 : NaClLog(LOG_FATAL,
49 : "NaClReverseQuotaWriteRequest: Reverse channel not initialized\n");
50 : }
51 0 : rpc_result = NaClSrpcInvokeBySignature(&self->nap->reverse_channel,
52 : NACL_REVERSE_REQUEST_QUOTA_FOR_WRITE,
53 : 16,
54 : file_id,
55 : offset,
56 : length,
57 : &allowed);
58 0 : if (NACL_SRPC_RESULT_OK != rpc_result) {
59 0 : rv = 0;
60 : } else {
61 0 : rv = allowed;
62 : }
63 0 : NaClXMutexUnlock(&self->nap->mu);
64 0 : NaClLog(4, "Leaving NaClReverseQuotaWriteRequest\n");
65 0 : return rv;
66 : }
67 :
68 : static int64_t ReverseQuotaFtruncateRequest(
69 : struct NaClDescQuotaInterface *self,
70 : uint8_t const *file_id,
71 0 : int64_t length) {
72 : UNREFERENCED_PARAMETER(self);
73 : UNREFERENCED_PARAMETER(file_id);
74 :
75 0 : NaClLog(LOG_FATAL, "FtruncateRequest invoked!?!\n");
76 0 : return length;
77 : }
78 :
79 : struct NaClDescQuotaInterfaceVtbl const kNaClReverseQuotaInterfaceVtbl = {
80 : {
81 : ReverseQuotaDtor
82 : },
83 : ReverseQuotaWriteRequest,
84 : ReverseQuotaFtruncateRequest
85 : };
86 :
87 : int NaClReverseQuotaInterfaceCtor(struct NaClReverseQuotaInterface *self,
88 0 : struct NaClApp *nap) {
89 0 : struct NaClRefCount *nrcp = (struct NaClRefCount *) self;
90 0 : NaClLog(4, "NaClReverseQuotaInterfaceCtor\n");
91 0 : if (!NaClDescQuotaInterfaceCtor(&(self->base))) {
92 0 : return 0;
93 : }
94 0 : nrcp->vtbl = (struct NaClRefCountVtbl *) (&kNaClReverseQuotaInterfaceVtbl);
95 0 : self->nap = nap;
96 0 : return 1;
97 : }
|