Rev 2475 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2475 | Rev 2478 | ||
---|---|---|---|
Line 53... | Line 53... | ||
53 | #include <futex.h> |
53 | #include <futex.h> |
54 | #include "rd.h" |
54 | #include "rd.h" |
55 | 55 | ||
56 | /** Pointer to the ramdisk's image. */ |
56 | /** Pointer to the ramdisk's image. */ |
57 | static void *rd_addr; |
57 | static void *rd_addr; |
- | 58 | /** Size of the ramdisk. */ |
|
- | 59 | static size_t rd_size; |
|
58 | 60 | ||
59 | /** |
61 | /** |
60 | * This futex protects the ramdisk's data. |
62 | * This futex protects the ramdisk's data. |
61 | * If we were to serve multiple requests (read + write or several writes) |
63 | * If we were to serve multiple requests (read + write or several writes) |
62 | * concurrently (i.e. from two or more threads), each read and write needs to be |
64 | * concurrently (i.e. from two or more threads), each read and write needs to be |
Line 72... | Line 74... | ||
72 | static void rd_connection(ipc_callid_t iid, ipc_call_t *icall) |
74 | static void rd_connection(ipc_callid_t iid, ipc_call_t *icall) |
73 | { |
75 | { |
74 | ipc_callid_t callid; |
76 | ipc_callid_t callid; |
75 | ipc_call_t call; |
77 | ipc_call_t call; |
76 | int retval; |
78 | int retval; |
77 | uintptr_t fs_va = NULL; |
79 | void *fs_va = NULL; |
78 | ipcarg_t offset; |
80 | ipcarg_t offset; |
79 | 81 | ||
80 | /* |
82 | /* |
81 | * We allocate VA for communication per connection. |
83 | * We allocate VA for communication per connection. |
82 | * This allows us to potentionally have more clients and work |
84 | * This allows us to potentionally have more clients and work |
Line 137... | Line 139... | ||
137 | */ |
139 | */ |
138 | ipc_answer_fast(callid, EOK, 0, 0); |
140 | ipc_answer_fast(callid, EOK, 0, 0); |
139 | return; |
141 | return; |
140 | case RD_READ_BLOCK: |
142 | case RD_READ_BLOCK: |
141 | offset = IPC_GET_ARG1(call); |
143 | offset = IPC_GET_ARG1(call); |
- | 144 | if (offset * BLOCK_SIZE > rd_size - BLOCK_SIZE) { |
|
- | 145 | /* |
|
- | 146 | * Reading past the end of the device. |
|
- | 147 | */ |
|
- | 148 | retval = ELIMIT; |
|
- | 149 | break; |
|
- | 150 | } |
|
142 | futex_down(&rd_futex); |
151 | futex_down(&rd_futex); |
143 | memcpy((void *) fs_va, rd_addr + offset, BLOCK_SIZE); |
152 | memcpy(fs_va, rd_addr + offset, BLOCK_SIZE); |
144 | futex_up(&rd_futex); |
153 | futex_up(&rd_futex); |
145 | retval = EOK; |
154 | retval = EOK; |
146 | break; |
155 | break; |
147 | case RD_WRITE_BLOCK: |
156 | case RD_WRITE_BLOCK: |
148 | offset = IPC_GET_ARG1(call); |
157 | offset = IPC_GET_ARG1(call); |
- | 158 | if (offset * BLOCK_SIZE > rd_size - BLOCK_SIZE) { |
|
- | 159 | /* |
|
- | 160 | * Writing past the end of the device. |
|
- | 161 | */ |
|
- | 162 | retval = ELIMIT; |
|
- | 163 | break; |
|
- | 164 | } |
|
149 | futex_up(&rd_futex); |
165 | futex_up(&rd_futex); |
150 | memcpy(rd_addr + offset, (void *) fs_va, BLOCK_SIZE); |
166 | memcpy(rd_addr + offset, fs_va, BLOCK_SIZE); |
151 | futex_down(&rd_futex); |
167 | futex_down(&rd_futex); |
152 | retval = EOK; |
168 | retval = EOK; |
153 | break; |
169 | break; |
154 | default: |
170 | default: |
155 | /* |
171 | /* |
Line 168... | Line 184... | ||
168 | /** Prepare the ramdisk image for operation. */ |
184 | /** Prepare the ramdisk image for operation. */ |
169 | static bool rd_init(void) |
185 | static bool rd_init(void) |
170 | { |
186 | { |
171 | int retval, flags; |
187 | int retval, flags; |
172 | 188 | ||
173 | size_t rd_size = sysinfo_value("rd.size"); |
189 | rd_size = sysinfo_value("rd.size"); |
174 | void *rd_ph_addr = (void *) sysinfo_value("rd.address.physical"); |
190 | void *rd_ph_addr = (void *) sysinfo_value("rd.address.physical"); |
175 | 191 | ||
176 | if (rd_size == 0) |
192 | if (rd_size == 0) |
177 | return false; |
193 | return false; |
178 | 194 |