Changeset 6843a9c in mainline for uspace/lib/c/generic
- Timestamp:
- 2012-06-29T13:02:14Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 722912e
- Parents:
- ba72f2b (diff), 0bbd13e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/lib/c/generic
- Files:
-
- 6 added
- 4 deleted
- 24 edited
-
adt/measured_strings.c (deleted)
-
as.c (modified) (2 diffs)
-
async.c (modified) (30 diffs)
-
ddi.c (modified) (7 diffs)
-
device/nic.c (modified) (5 diffs)
-
device/pci.c (added)
-
devman.c (modified) (11 diffs)
-
elf/elf_load.c (modified) (1 diff)
-
fibril.c (modified) (1 diff)
-
fibril_synch.c (modified) (5 diffs)
-
inet.c (added)
-
inetcfg.c (added)
-
inetping.c (added)
-
io/printf_core.c (modified) (2 diffs)
-
ipc.c (modified) (6 diffs)
-
iplink.c (added)
-
iplink_srv.c (added)
-
loader.c (modified) (5 diffs)
-
loc.c (modified) (18 diffs)
-
malloc.c (modified) (1 diff)
-
mman.c (modified) (1 diff)
-
net/icmp_api.c (deleted)
-
net/modules.c (deleted)
-
net/packet.c (deleted)
-
net/socket_client.c (modified) (4 diffs)
-
ns.c (modified) (5 diffs)
-
private/async.h (modified) (1 diff)
-
stacktrace.c (modified) (1 diff)
-
stats.c (modified) (1 diff)
-
str.c (modified) (8 diffs)
-
sysinfo.c (modified) (4 diffs)
-
thread.c (modified) (3 diffs)
-
time.c (modified) (2 diffs)
-
vfs/vfs.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/as.c
rba72f2b r6843a9c 45 45 /** Create address space area. 46 46 * 47 * @param address Virtual address where to place new address space area. 48 * @param size Size of the area. 49 * @param flags Flags describing type of the area. 47 * @param base Starting virtual address of the area. 48 * If set to AS_AREA_ANY ((void *) -1), 49 * the kernel finds a mappable area. 50 * @param size Size of the area. 51 * @param flags Flags describing type of the area. 50 52 * 51 * @return address on success, (void *) -1 otherwise. 53 * @return Starting virtual address of the created area on success. 54 * @return AS_MAP_FAILED ((void *) -1) otherwise. 52 55 * 53 56 */ 54 void *as_area_create(void * address, size_t size, unsigned int flags)57 void *as_area_create(void *base, size_t size, unsigned int flags) 55 58 { 56 return (void *) __SYSCALL 3(SYS_AS_AREA_CREATE, (sysarg_t) address,57 (sysarg_t) size, (sysarg_t) flags );59 return (void *) __SYSCALL4(SYS_AS_AREA_CREATE, (sysarg_t) base, 60 (sysarg_t) size, (sysarg_t) flags, (sysarg_t) __entry); 58 61 } 59 62 … … 102 105 } 103 106 104 /** Return pointer to unmapped address space area107 /** Find mapping to physical address. 105 108 * 106 * @param size Requested size of the allocation. 109 * @param virt Virtual address to find mapping for. 110 * @param[out] phys Physical adress. 107 111 * 108 * @return Pointer to the beginning of unmapped address space area. 112 * @return EOK on no error. 113 * @retval ENOENT if no mapping was found. 109 114 * 110 115 */ 111 void *as_get_mappable_page(size_t size)116 int as_get_physical_mapping(const void *virt, uintptr_t *phys) 112 117 { 113 return (void *) __SYSCALL2(SYS_AS_GET_UNMAPPED_AREA, 114 (sysarg_t) __entry, (sysarg_t) size); 115 } 116 117 /** Find mapping to physical address. 118 * 119 * @param address Virtual address in question (virtual). 120 * @param[out] frame Frame address (physical). 121 * @return Error code. 122 * @retval EOK No error, @p frame holds the translation. 123 * @retval ENOENT Mapping not found. 124 */ 125 int as_get_physical_mapping(const void *address, uintptr_t *frame) 126 { 127 uintptr_t tmp_frame; 128 uintptr_t virt = (uintptr_t) address; 129 130 int rc = (int) __SYSCALL2(SYS_PAGE_FIND_MAPPING, 131 (sysarg_t) virt, (sysarg_t) &tmp_frame); 132 if (rc != EOK) { 133 return rc; 134 } 135 136 if (frame != NULL) { 137 *frame = tmp_frame; 138 } 139 140 return EOK; 118 return (int) __SYSCALL2(SYS_PAGE_FIND_MAPPING, (sysarg_t) virt, 119 (sysarg_t) phys); 141 120 } 142 121 -
uspace/lib/c/generic/async.c
rba72f2b r6843a9c 189 189 /** If reply was received. */ 190 190 bool done; 191 192 /** If the message / reply should be discarded on arrival. */ 193 bool forget; 194 195 /** If already destroyed. */ 196 bool destroyed; 191 197 192 198 /** Pointer to where the answer data is stored. */ … … 241 247 static fibril_local connection_t *fibril_connection; 242 248 249 static void to_event_initialize(to_event_t *to) 250 { 251 struct timeval tv = { 0, 0 }; 252 253 to->inlist = false; 254 to->occurred = false; 255 link_initialize(&to->link); 256 to->expires = tv; 257 } 258 259 static void wu_event_initialize(wu_event_t *wu) 260 { 261 wu->inlist = false; 262 link_initialize(&wu->link); 263 } 264 265 void awaiter_initialize(awaiter_t *aw) 266 { 267 aw->fid = 0; 268 aw->active = false; 269 to_event_initialize(&aw->to_event); 270 wu_event_initialize(&aw->wu_event); 271 } 272 273 static amsg_t *amsg_create(void) 274 { 275 amsg_t *msg; 276 277 msg = malloc(sizeof(amsg_t)); 278 if (msg) { 279 msg->done = false; 280 msg->forget = false; 281 msg->destroyed = false; 282 msg->dataptr = NULL; 283 msg->retval = (sysarg_t) EINVAL; 284 awaiter_initialize(&msg->wdata); 285 } 286 287 return msg; 288 } 289 290 static void amsg_destroy(amsg_t *msg) 291 { 292 assert(!msg->destroyed); 293 msg->destroyed = true; 294 free(msg); 295 } 296 243 297 static void *default_client_data_constructor(void) 244 298 { … … 257 311 void async_set_client_data_constructor(async_client_data_ctor_t ctor) 258 312 { 313 assert(async_client_data_create == default_client_data_constructor); 259 314 async_client_data_create = ctor; 260 315 } … … 262 317 void async_set_client_data_destructor(async_client_data_dtor_t dtor) 263 318 { 319 assert(async_client_data_destroy == default_client_data_destructor); 264 320 async_client_data_destroy = dtor; 265 321 } … … 303 359 void async_set_client_connection(async_client_conn_t conn) 304 360 { 361 assert(client_connection == default_client_connection); 305 362 client_connection = conn; 306 363 } … … 889 946 890 947 switch (IPC_GET_IMETHOD(*call)) { 891 case IPC_M_C ONNECT_ME:948 case IPC_M_CLONE_ESTABLISH: 892 949 case IPC_M_CONNECT_ME_TO: 893 950 /* Open new connection with fibril, etc. */ … … 960 1017 961 1018 suseconds_t timeout; 1019 unsigned int flags = SYNCH_FLAGS_NONE; 962 1020 if (!list_empty(&timeout_list)) { 963 1021 awaiter_t *waiter = list_get_instance( … … 970 1028 futex_up(&async_futex); 971 1029 handle_expired_timeouts(); 972 continue; 973 } else 1030 /* 1031 * Notice that even if the event(s) already 1032 * expired (and thus the other fibril was 1033 * supposed to be running already), 1034 * we check for incoming IPC. 1035 * 1036 * Otherwise, a fibril that continuously 1037 * creates (almost) expired events could 1038 * prevent IPC retrieval from the kernel. 1039 */ 1040 timeout = 0; 1041 flags = SYNCH_FLAGS_NON_BLOCKING; 1042 1043 } else { 974 1044 timeout = tv_sub(&waiter->to_event.expires, &tv); 975 } else 1045 futex_up(&async_futex); 1046 } 1047 } else { 1048 futex_up(&async_futex); 976 1049 timeout = SYNCH_NO_TIMEOUT; 977 978 futex_up(&async_futex); 1050 } 979 1051 980 1052 atomic_inc(&threads_in_ipc_wait); 981 1053 982 1054 ipc_call_t call; 983 ipc_callid_t callid = ipc_wait_cycle(&call, timeout, 984 SYNCH_FLAGS_NONE); 1055 ipc_callid_t callid = ipc_wait_cycle(&call, timeout, flags); 985 1056 986 1057 atomic_dec(&threads_in_ipc_wait); … … 1097 1168 1098 1169 msg->done = true; 1099 if (!msg->wdata.active) { 1170 1171 if (msg->forget) { 1172 assert(msg->wdata.active); 1173 amsg_destroy(msg); 1174 } else if (!msg->wdata.active) { 1100 1175 msg->wdata.active = true; 1101 1176 fibril_add_ready(msg->wdata.fid); 1102 1177 } 1103 1178 1104 1179 futex_up(&async_futex); 1105 1180 } … … 1128 1203 return 0; 1129 1204 1130 amsg_t *msg = malloc(sizeof(amsg_t));1205 amsg_t *msg = amsg_create(); 1131 1206 if (msg == NULL) 1132 1207 return 0; 1133 1208 1134 msg->done = false;1135 1209 msg->dataptr = dataptr; 1136 1137 msg->wdata.to_event.inlist = false;1138 1139 /*1140 * We may sleep in the next method,1141 * but it will use its own means1142 */1143 1210 msg->wdata.active = true; 1144 1211 … … 1174 1241 return 0; 1175 1242 1176 amsg_t *msg = malloc(sizeof(amsg_t)); 1177 1243 amsg_t *msg = amsg_create(); 1178 1244 if (msg == NULL) 1179 1245 return 0; 1180 1246 1181 msg->done = false;1182 1247 msg->dataptr = dataptr; 1183 1184 msg->wdata.to_event.inlist = false;1185 1186 /*1187 * We may sleep in the next method,1188 * but it will use its own means1189 */1190 1248 msg->wdata.active = true; 1191 1249 … … 1210 1268 1211 1269 futex_down(&async_futex); 1270 1271 assert(!msg->forget); 1272 assert(!msg->destroyed); 1273 1212 1274 if (msg->done) { 1213 1275 futex_up(&async_futex); … … 1228 1290 *retval = msg->retval; 1229 1291 1230 free(msg);1292 amsg_destroy(msg); 1231 1293 } 1232 1294 1233 1295 /** Wait for a message sent by the async framework, timeout variant. 1296 * 1297 * If the wait times out, the caller may choose to either wait again by calling 1298 * async_wait_for() or async_wait_timeout(), or forget the message via 1299 * async_forget(). 1234 1300 * 1235 1301 * @param amsgid Hash of the message to wait for. … … 1246 1312 1247 1313 amsg_t *msg = (amsg_t *) amsgid; 1248 1249 /* TODO: Let it go through the event read at least once */ 1250 if (timeout < 0) 1251 return ETIMEOUT; 1252 1314 1253 1315 futex_down(&async_futex); 1316 1317 assert(!msg->forget); 1318 assert(!msg->destroyed); 1319 1254 1320 if (msg->done) { 1255 1321 futex_up(&async_futex); … … 1257 1323 } 1258 1324 1325 /* 1326 * Negative timeout is converted to zero timeout to avoid 1327 * using tv_add with negative augmenter. 1328 */ 1329 if (timeout < 0) 1330 timeout = 0; 1331 1259 1332 gettimeofday(&msg->wdata.to_event.expires, NULL); 1260 1333 tv_add(&msg->wdata.to_event.expires, timeout); 1261 1334 1335 /* 1336 * Current fibril is inserted as waiting regardless of the 1337 * "size" of the timeout. 1338 * 1339 * Checking for msg->done and immediately bailing out when 1340 * timeout == 0 would mean that the manager fibril would never 1341 * run (consider single threaded program). 1342 * Thus the IPC answer would be never retrieved from the kernel. 1343 * 1344 * Notice that the actual delay would be very small because we 1345 * - switch to manager fibril 1346 * - the manager sees expired timeout 1347 * - and thus adds us back to ready queue 1348 * - manager switches back to some ready fibril 1349 * (prior it, it checks for incoming IPC). 1350 * 1351 */ 1262 1352 msg->wdata.fid = fibril_get_id(); 1263 1353 msg->wdata.active = false; … … 1276 1366 *retval = msg->retval; 1277 1367 1278 free(msg);1368 amsg_destroy(msg); 1279 1369 1280 1370 return 0; 1281 1371 } 1372 1373 /** Discard the message / reply on arrival. 1374 * 1375 * The message will be marked to be discarded once the reply arrives in 1376 * reply_received(). It is not allowed to call async_wait_for() or 1377 * async_wait_timeout() on this message after a call to this function. 1378 * 1379 * @param amsgid Hash of the message to forget. 1380 */ 1381 void async_forget(aid_t amsgid) 1382 { 1383 amsg_t *msg = (amsg_t *) amsgid; 1384 1385 assert(msg); 1386 assert(!msg->forget); 1387 assert(!msg->destroyed); 1388 1389 futex_down(&async_futex); 1390 if (msg->done) { 1391 amsg_destroy(msg); 1392 } else { 1393 msg->dataptr = NULL; 1394 msg->forget = true; 1395 } 1396 futex_up(&async_futex); 1397 } 1282 1398 1283 1399 /** Wait for specified time. … … 1290 1406 void async_usleep(suseconds_t timeout) 1291 1407 { 1292 amsg_t *msg = malloc(sizeof(amsg_t)); 1293 1408 amsg_t *msg = amsg_create(); 1294 1409 if (!msg) 1295 1410 return; 1296 1411 1297 1412 msg->wdata.fid = fibril_get_id(); 1298 msg->wdata.active = false;1299 1413 1300 1414 gettimeofday(&msg->wdata.to_event.expires, NULL); … … 1310 1424 /* Futex is up automatically after fibril_switch() */ 1311 1425 1312 free(msg);1426 amsg_destroy(msg); 1313 1427 } 1314 1428 … … 1556 1670 } 1557 1671 1558 /** Wrapper for making IPC_M_C ONNECT_MEcalls using the async framework.1559 * 1560 * Ask throughfor a cloned connection to some service.1672 /** Wrapper for making IPC_M_CLONE_ESTABLISH calls using the async framework. 1673 * 1674 * Ask for a cloned connection to some service. 1561 1675 * 1562 1676 * @param mgmt Exchange management style. … … 1566 1680 * 1567 1681 */ 1568 async_sess_t *async_c onnect_me(exch_mgmt_t mgmt, async_exch_t *exch)1682 async_sess_t *async_clone_establish(exch_mgmt_t mgmt, async_exch_t *exch) 1569 1683 { 1570 1684 if (exch == NULL) { … … 1581 1695 ipc_call_t result; 1582 1696 1583 amsg_t *msg = malloc(sizeof(amsg_t));1584 if ( msg == NULL) {1697 amsg_t *msg = amsg_create(); 1698 if (!msg) { 1585 1699 free(sess); 1586 1700 errno = ENOMEM; … … 1588 1702 } 1589 1703 1590 msg->done = false;1591 1704 msg->dataptr = &result; 1592 1593 msg->wdata.to_event.inlist = false;1594 1595 /*1596 * We may sleep in the next method,1597 * but it will use its own means1598 */1599 1705 msg->wdata.active = true; 1600 1706 1601 ipc_call_async_0(exch->phone, IPC_M_C ONNECT_ME, msg,1707 ipc_call_async_0(exch->phone, IPC_M_CLONE_ESTABLISH, msg, 1602 1708 reply_received, true); 1603 1709 … … 1640 1746 ipc_call_t result; 1641 1747 1642 amsg_t *msg = malloc(sizeof(amsg_t));1643 if ( msg == NULL)1748 amsg_t *msg = amsg_create(); 1749 if (!msg) 1644 1750 return ENOENT; 1645 1751 1646 msg->done = false;1647 1752 msg->dataptr = &result; 1648 1649 msg->wdata.to_event.inlist = false;1650 1651 /*1652 * We may sleep in the next method,1653 * but it will use its own means1654 */1655 1753 msg->wdata.active = true; 1656 1754 … … 1846 1944 1847 1945 fibril_mutex_lock(&async_sess_mutex); 1848 1946 1849 1947 int rc = async_hangup_internal(sess->phone); 1850 1948 … … 1998 2096 * 1999 2097 * @param exch Exchange for sending the message. 2000 * @param dst Destination address space area base.2001 2098 * @param size Size of the destination address space area. 2002 2099 * @param arg User defined argument. 2003 2100 * @param flags Storage for the received flags. Can be NULL. 2101 * @param dst Destination address space area base. Cannot be NULL. 2004 2102 * 2005 2103 * @return Zero on success or a negative error code from errno.h. 2006 2104 * 2007 2105 */ 2008 int async_share_in_start(async_exch_t *exch, void *dst, size_t size,2009 sysarg_t arg, unsigned int *flags)2106 int async_share_in_start(async_exch_t *exch, size_t size, sysarg_t arg, 2107 unsigned int *flags, void **dst) 2010 2108 { 2011 2109 if (exch == NULL) 2012 2110 return ENOENT; 2013 2111 2014 sysarg_t tmp_flags; 2015 int res = async_req_3_2(exch, IPC_M_SHARE_IN, (sysarg_t) dst, 2016 (sysarg_t) size, arg, NULL, &tmp_flags); 2112 sysarg_t _flags = 0; 2113 sysarg_t _dst = (sysarg_t) -1; 2114 int res = async_req_2_4(exch, IPC_M_SHARE_IN, (sysarg_t) size, 2115 arg, NULL, &_flags, NULL, &_dst); 2017 2116 2018 2117 if (flags) 2019 *flags = (unsigned int) tmp_flags; 2020 2118 *flags = (unsigned int) _flags; 2119 2120 *dst = (void *) _dst; 2021 2121 return res; 2022 2122 } … … 2047 2147 return false; 2048 2148 2049 *size = (size_t) IPC_GET_ARG 2(data);2149 *size = (size_t) IPC_GET_ARG1(data); 2050 2150 return true; 2051 2151 } … … 2053 2153 /** Wrapper for answering the IPC_M_SHARE_IN calls using the async framework. 2054 2154 * 2055 * This wrapper only makes it more comfortable to answer IPC_M_ DATA_READ2155 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_IN 2056 2156 * calls so that the user doesn't have to remember the meaning of each IPC 2057 2157 * argument. … … 2131 2231 * 2132 2232 */ 2133 int async_share_out_finalize(ipc_callid_t callid, void * dst)2233 int async_share_out_finalize(ipc_callid_t callid, void **dst) 2134 2234 { 2135 2235 return ipc_share_out_finalize(callid, dst); … … 2246 2346 IPC_FF_ROUTE_FROM_ME); 2247 2347 if (retval != EOK) { 2248 async_ wait_for(msg, NULL);2348 async_forget(msg); 2249 2349 ipc_answer_0(callid, retval); 2250 2350 return retval; … … 2440 2540 IPC_FF_ROUTE_FROM_ME); 2441 2541 if (retval != EOK) { 2442 async_ wait_for(msg, NULL);2542 async_forget(msg); 2443 2543 ipc_answer_0(callid, retval); 2444 2544 return retval; -
uspace/lib/c/generic/ddi.c
rba72f2b r6843a9c 33 33 */ 34 34 35 #include <assert.h> 36 #include <unistd.h> 37 #include <errno.h> 35 38 #include <sys/types.h> 36 39 #include <abi/ddi/arg.h> … … 42 45 #include <align.h> 43 46 #include <libarch/config.h> 47 #include "private/libc.h" 44 48 45 49 /** Return unique device number. … … 53 57 } 54 58 55 /** Map piece of physical memory to task.59 /** Map a piece of physical memory to task. 56 60 * 57 61 * Caller of this function must have the CAP_MEM_MANAGER capability. 58 62 * 59 * @param p fPhysical address of the starting frame.60 * @param vp Virtual address of the starting page.61 * @param pages Number of pages to map.62 * @param flags Flags for the new address space area.63 * @param phys Physical address of the starting frame. 64 * @param pages Number of pages to map. 65 * @param flags Flags for the new address space area. 66 * @param virt Virtual address of the starting page. 63 67 * 64 * @return 0 on success, EPERM if the caller lacks the 65 * CAP_MEM_MANAGER capability, ENOENT if there is no task 66 * with specified ID and ENOMEM if there was some problem 67 * in creating address space area. 68 * @return EOK on success 69 * @return EPERM if the caller lacks the CAP_MEM_MANAGER capability 70 * @return ENOENT if there is no task with specified ID 71 * @return ENOMEM if there was some problem in creating 72 * the address space area. 73 * 68 74 */ 69 int physmem_map(void *p f, void *vp, unsigned long pages, int flags)75 int physmem_map(void *phys, size_t pages, unsigned int flags, void **virt) 70 76 { 71 return __SYSCALL4(SYS_PHYSMEM_MAP, (sysarg_t) pf, (sysarg_t) vp, pages, 72 flags); 77 return __SYSCALL5(SYS_PHYSMEM_MAP, (sysarg_t) phys, 78 pages, flags, (sysarg_t) virt, (sysarg_t) __entry); 79 } 80 81 int dmamem_map(void *virt, size_t size, unsigned int map_flags, 82 unsigned int flags, void **phys) 83 { 84 return (int) __SYSCALL6(SYS_DMAMEM_MAP, (sysarg_t) size, 85 (sysarg_t) map_flags, (sysarg_t) flags & ~DMAMEM_FLAGS_ANONYMOUS, 86 (sysarg_t) phys, (sysarg_t) virt, 0); 87 } 88 89 int dmamem_map_anonymous(size_t size, unsigned int map_flags, 90 unsigned int flags, void **phys, void **virt) 91 { 92 return (int) __SYSCALL6(SYS_DMAMEM_MAP, (sysarg_t) size, 93 (sysarg_t) map_flags, (sysarg_t) flags | DMAMEM_FLAGS_ANONYMOUS, 94 (sysarg_t) phys, (sysarg_t) virt, (sysarg_t) __entry); 95 } 96 97 int dmamem_unmap(void *virt, size_t size) 98 { 99 return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, (sysarg_t) size, 0); 100 } 101 102 int dmamem_unmap_anonymous(void *virt) 103 { 104 return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, 0, 105 DMAMEM_FLAGS_ANONYMOUS); 73 106 } 74 107 … … 77 110 * Caller of this function must have the IO_MEM_MANAGER capability. 78 111 * 79 * @param id Task ID.80 * @param ioaddr Starting address of the I/O range.81 * @param size Size of the range.112 * @param id Task ID. 113 * @param ioaddr Starting address of the I/O range. 114 * @param size Size of the range. 82 115 * 83 * @return 0 on success, EPERM if the caller lacks the 84 * CAP_IO_MANAGER capability, ENOENT if there is no task 85 * with specified ID and ENOMEM if there was some problem 86 * in allocating memory. 116 * @return EOK on success 117 * @return EPERM if the caller lacks the CAP_IO_MANAGER capability 118 * @return ENOENT if there is no task with specified ID 119 * @return ENOMEM if there was some problem in allocating memory. 120 * 87 121 */ 88 122 int iospace_enable(task_id_t id, void *ioaddr, unsigned long size) 89 123 { 90 124 ddi_ioarg_t arg; 91 125 92 126 arg.task_id = id; 93 127 arg.ioaddr = ioaddr; 94 128 arg.size = size; 95 129 96 130 return __SYSCALL1(SYS_IOSPACE_ENABLE, (sysarg_t) &arg); 97 131 } … … 99 133 /** Enable PIO for specified I/O range. 100 134 * 101 * @param pio_addr I/O start address.102 * @param size Size of the I/O region.103 * @param use_addr Address where the final address for application's PIO104 * will be stored.135 * @param pio_addr I/O start address. 136 * @param size Size of the I/O region. 137 * @param virt Virtual address for application's 138 * PIO operations. 105 139 * 106 * @return Zero on success or negative error code. 140 * @return EOK on success. 141 * @return Negative error code on failure. 142 * 107 143 */ 108 int pio_enable(void *pio_addr, size_t size, void ** use_addr)144 int pio_enable(void *pio_addr, size_t size, void **virt) 109 145 { 110 void *phys;111 void *virt;112 size_t offset;113 unsigned int pages;114 115 146 #ifdef IO_SPACE_BOUNDARY 116 147 if (pio_addr < IO_SPACE_BOUNDARY) { 117 * use_addr= pio_addr;148 *virt = pio_addr; 118 149 return iospace_enable(task_get_id(), pio_addr, size); 119 150 } 120 151 #endif 121 122 phys = (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE); 123 offset = pio_addr - phys; 124 pages = ALIGN_UP(offset + size, PAGE_SIZE) >> PAGE_WIDTH; 125 virt = as_get_mappable_page(pages << PAGE_WIDTH); 126 *use_addr = virt + offset; 127 return physmem_map(phys, virt, pages, AS_AREA_READ | AS_AREA_WRITE); 152 153 void *phys_frame = 154 (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE); 155 size_t offset = pio_addr - phys_frame; 156 size_t pages = SIZE2PAGES(offset + size); 157 158 void *virt_page; 159 int rc = physmem_map(phys_frame, pages, 160 AS_AREA_READ | AS_AREA_WRITE, &virt_page); 161 if (rc != EOK) 162 return rc; 163 164 *virt = virt_page + offset; 165 return EOK; 128 166 } 129 167 … … 138 176 * 139 177 */ 140 int register_irq(int inr, int devno, int method, irq_code_t *ucode)178 int irq_register(int inr, int devno, int method, irq_code_t *ucode) 141 179 { 142 return __SYSCALL4(SYS_ REGISTER_IRQ, inr, devno, method,180 return __SYSCALL4(SYS_IRQ_REGISTER, inr, devno, method, 143 181 (sysarg_t) ucode); 144 182 } … … 152 190 * 153 191 */ 154 int unregister_irq(int inr, int devno)192 int irq_unregister(int inr, int devno) 155 193 { 156 return __SYSCALL2(SYS_ UNREGISTER_IRQ, inr, devno);194 return __SYSCALL2(SYS_IRQ_UNREGISTER, inr, devno); 157 195 } 158 196 -
uspace/lib/c/generic/device/nic.c
rba72f2b r6843a9c 44 44 #include <ipc/services.h> 45 45 46 /** Send a packet through the device 47 * 48 * @param[in] dev_sess 49 * @param[in] packet_id Id of the sent packet 50 * 51 * @return EOK If the operation was successfully completed 52 * 53 */ 54 int nic_send_message(async_sess_t *dev_sess, packet_id_t packet_id) 55 { 56 async_exch_t *exch = async_exchange_begin(dev_sess); 57 int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 58 NIC_SEND_MESSAGE, packet_id); 59 async_exchange_end(exch); 60 61 return rc; 62 } 63 64 /** Connect the driver to the NET and NIL services 65 * 66 * @param[in] dev_sess 67 * @param[in] nil_service Service identifier for the NIL service 46 /** Send frame from NIC 47 * 48 * @param[in] dev_sess 49 * @param[in] data Frame data 50 * @param[in] size Frame size in bytes 51 * 52 * @return EOK If the operation was successfully completed 53 * 54 */ 55 int nic_send_frame(async_sess_t *dev_sess, void *data, size_t size) 56 { 57 async_exch_t *exch = async_exchange_begin(dev_sess); 58 59 ipc_call_t answer; 60 aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 61 NIC_SEND_MESSAGE, &answer); 62 sysarg_t retval = async_data_write_start(exch, data, size); 63 64 async_exchange_end(exch); 65 66 if (retval != EOK) { 67 async_forget(req); 68 return retval; 69 } 70 71 async_wait_for(req, &retval); 72 return retval; 73 } 74 75 /** Create callback connection from NIC service 76 * 77 * @param[in] dev_sess 68 78 * @param[in] device_id 69 79 * … … 71 81 * 72 82 */ 73 int nic_connect_to_nil(async_sess_t *dev_sess, services_t nil_service, 74 nic_device_id_t device_id) 75 { 76 async_exch_t *exch = async_exchange_begin(dev_sess); 77 int rc = async_req_3_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 78 NIC_CONNECT_TO_NIL, nil_service, device_id); 79 async_exchange_end(exch); 80 81 return rc; 83 int nic_callback_create(async_sess_t *dev_sess, async_client_conn_t cfun, 84 void *carg) 85 { 86 ipc_call_t answer; 87 int rc; 88 sysarg_t retval; 89 90 async_exch_t *exch = async_exchange_begin(dev_sess); 91 aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 92 NIC_CALLBACK_CREATE, &answer); 93 94 rc = async_connect_to_me(exch, 0, 0, 0, cfun, carg); 95 if (rc != EOK) { 96 async_forget(req); 97 return rc; 98 } 99 async_exchange_end(exch); 100 101 async_wait_for(req, &retval); 102 return (int) retval; 82 103 } 83 104 … … 324 345 * it can never force the NIC to advertise unsupported modes. 325 346 * 326 * The allowed modes are defined in "n et/eth_phys.h" in the C library.347 * The allowed modes are defined in "nic/eth_phys.h" in the C library. 327 348 * 328 349 * @param[in] dev_sess … … 361 382 /** Probe current state of auto-negotiation. 362 383 * 363 * Modes are defined in the "n et/eth_phys.h" in the C library.384 * Modes are defined in the "nic/eth_phys.h" in the C library. 364 385 * 365 386 * @param[in] dev_sess … … 895 916 * 896 917 */ 897 int nic_vlan_set_tag(async_sess_t *dev_sess, uint16_t tag, int add, intstrip)918 int nic_vlan_set_tag(async_sess_t *dev_sess, uint16_t tag, bool add, bool strip) 898 919 { 899 920 async_exch_t *exch = async_exchange_begin(dev_sess); -
uspace/lib/c/generic/devman.c
rba72f2b r6843a9c 177 177 178 178 /** Register running driver with device manager. */ 179 int devman_driver_register(const char *name , async_client_conn_t conn)179 int devman_driver_register(const char *name) 180 180 { 181 181 async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_DRIVER); … … 188 188 189 189 if (retval != EOK) { 190 async_wait_for(req, NULL); 191 return retval; 192 } 193 194 async_set_client_connection(conn); 190 async_forget(req); 191 return retval; 192 } 195 193 196 194 exch = devman_exchange_begin(DEVMAN_DRIVER); 197 async_connect_to_me(exch, 0, 0, 0, conn, NULL);195 async_connect_to_me(exch, 0, 0, 0, NULL, NULL); 198 196 devman_exchange_end(exch); 199 197 … … 228 226 if (retval != EOK) { 229 227 devman_exchange_end(exch); 230 async_ wait_for(req, NULL);228 async_forget(req); 231 229 return retval; 232 230 } … … 244 242 if (retval != EOK) { 245 243 devman_exchange_end(exch); 246 async_ wait_for(req2, NULL);247 async_ wait_for(req, NULL);244 async_forget(req2); 245 async_forget(req); 248 246 return retval; 249 247 } … … 252 250 if (retval != EOK) { 253 251 devman_exchange_end(exch); 254 async_ wait_for(req, NULL);252 async_forget(req); 255 253 return retval; 256 254 } … … 285 283 286 284 if (retval != EOK) { 287 async_ wait_for(req, NULL);285 async_forget(req); 288 286 return retval; 289 287 } … … 388 386 389 387 if (retval != EOK) { 390 async_ wait_for(req, NULL);388 async_forget(req); 391 389 return retval; 392 390 } … … 425 423 426 424 if (dretval != EOK) { 427 async_ wait_for(req, NULL);425 async_forget(req); 428 426 return dretval; 429 427 } … … 432 430 async_wait_for(req, &retval); 433 431 434 if (retval != EOK) 435 return retval; 432 if (retval != EOK) { 433 return retval; 434 } 436 435 437 436 act_size = IPC_GET_ARG2(dreply); … … 454 453 } 455 454 455 int devman_fun_get_driver_name(devman_handle_t handle, char *buf, size_t buf_size) 456 { 457 return devman_get_str_internal(DEVMAN_FUN_GET_DRIVER_NAME, handle, buf, 458 buf_size); 459 } 460 456 461 int devman_fun_online(devman_handle_t funh) 457 462 { … … 490 495 491 496 if (rc != EOK) { 492 async_ wait_for(req, NULL);497 async_forget(req); 493 498 return rc; 494 499 } -
uspace/lib/c/generic/elf/elf_load.c
rba72f2b r6843a9c 364 364 * and writeable. 365 365 */ 366 a = as_area_create((uint8_t *) base + bias, mem_sz,366 a = as_area_create((uint8_t *) base + bias, mem_sz, 367 367 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); 368 if (a == (void *)(-1)) {368 if (a == AS_MAP_FAILED) { 369 369 DPRINTF("memory mapping failed (0x%x, %d)\n", 370 base+bias, mem_sz);370 base + bias, mem_sz); 371 371 return EE_MEMORY; 372 372 } -
uspace/lib/c/generic/fibril.c
rba72f2b r6843a9c 286 286 } 287 287 288 /** Delete a fibril that has never run. 289 * 290 * Free resources of a fibril that has been created with fibril_create() 291 * but never readied using fibril_add_ready(). 292 * 293 * @param fid Pointer to the fibril structure of the fibril to be 294 * added. 295 */ 296 void fibril_destroy(fid_t fid) 297 { 298 fibril_t *fibril = (fibril_t *) fid; 299 300 free(fibril->stack); 301 fibril_teardown(fibril); 302 } 303 288 304 /** Add a fibril to the ready list. 289 305 * -
uspace/lib/c/generic/fibril_synch.c
rba72f2b r6843a9c 112 112 awaiter_t wdata; 113 113 114 awaiter_initialize(&wdata); 114 115 wdata.fid = fibril_get_id(); 115 wdata.active = false;116 116 wdata.wu_event.inlist = true; 117 link_initialize(&wdata.wu_event.link);118 117 list_append(&wdata.wu_event.link, &fm->waiters); 119 118 check_for_deadlock(&fm->oi); … … 205 204 awaiter_t wdata; 206 205 206 awaiter_initialize(&wdata); 207 207 wdata.fid = (fid_t) f; 208 wdata.active = false;209 208 wdata.wu_event.inlist = true; 210 link_initialize(&wdata.wu_event.link);211 209 f->flags &= ~FIBRIL_WRITER; 212 210 list_append(&wdata.wu_event.link, &frw->waiters); … … 233 231 awaiter_t wdata; 234 232 233 awaiter_initialize(&wdata); 235 234 wdata.fid = (fid_t) f; 236 wdata.active = false;237 235 wdata.wu_event.inlist = true; 238 link_initialize(&wdata.wu_event.link);239 236 f->flags |= FIBRIL_WRITER; 240 237 list_append(&wdata.wu_event.link, &frw->waiters); … … 375 372 return ETIMEOUT; 376 373 374 awaiter_initialize(&wdata); 377 375 wdata.fid = fibril_get_id(); 378 wdata.active = false;379 380 376 wdata.to_event.inlist = timeout > 0; 381 wdata.to_event.occurred = false;382 link_initialize(&wdata.to_event.link);383 384 377 wdata.wu_event.inlist = true; 385 link_initialize(&wdata.wu_event.link);386 378 387 379 futex_down(&async_futex); … … 447 439 } 448 440 441 /** Timer fibril. 442 * 443 * @param arg Timer 444 */ 445 static int fibril_timer_func(void *arg) 446 { 447 fibril_timer_t *timer = (fibril_timer_t *) arg; 448 int rc; 449 450 fibril_mutex_lock(&timer->lock); 451 452 while (true) { 453 while (timer->state != fts_active && 454 timer->state != fts_cleanup) { 455 456 if (timer->state == fts_cleanup) 457 break; 458 459 fibril_condvar_wait(&timer->cv, &timer->lock); 460 } 461 462 if (timer->state == fts_cleanup) 463 break; 464 465 rc = fibril_condvar_wait_timeout(&timer->cv, &timer->lock, 466 timer->delay); 467 if (rc == ETIMEOUT) { 468 timer->state = fts_fired; 469 fibril_mutex_unlock(&timer->lock); 470 timer->fun(timer->arg); 471 fibril_mutex_lock(&timer->lock); 472 } 473 } 474 475 fibril_mutex_unlock(&timer->lock); 476 return 0; 477 } 478 479 /** Create new timer. 480 * 481 * @return New timer on success, @c NULL if out of memory. 482 */ 483 fibril_timer_t *fibril_timer_create(void) 484 { 485 fid_t fid; 486 fibril_timer_t *timer; 487 488 timer = calloc(1, sizeof(fibril_timer_t)); 489 if (timer == NULL) 490 return NULL; 491 492 fid = fibril_create(fibril_timer_func, (void *) timer); 493 if (fid == 0) { 494 free(timer); 495 return NULL; 496 } 497 498 fibril_mutex_initialize(&timer->lock); 499 fibril_condvar_initialize(&timer->cv); 500 501 timer->fibril = fid; 502 timer->state = fts_not_set; 503 504 fibril_add_ready(fid); 505 506 return timer; 507 } 508 509 /** Destroy timer. 510 * 511 * @param timer Timer, must not be active or accessed by other threads. 512 */ 513 void fibril_timer_destroy(fibril_timer_t *timer) 514 { 515 fibril_mutex_lock(&timer->lock); 516 assert(timer->state != fts_active); 517 timer->state = fts_cleanup; 518 fibril_condvar_broadcast(&timer->cv); 519 fibril_mutex_unlock(&timer->lock); 520 } 521 522 /** Set timer. 523 * 524 * Set timer to execute a callback function after the specified 525 * interval. 526 * 527 * @param timer Timer 528 * @param delay Delay in microseconds 529 * @param fun Callback function 530 * @param arg Argument for @a fun 531 */ 532 void fibril_timer_set(fibril_timer_t *timer, suseconds_t delay, 533 fibril_timer_fun_t fun, void *arg) 534 { 535 fibril_mutex_lock(&timer->lock); 536 timer->state = fts_active; 537 timer->delay = delay; 538 timer->fun = fun; 539 timer->arg = arg; 540 fibril_condvar_broadcast(&timer->cv); 541 fibril_mutex_unlock(&timer->lock); 542 } 543 544 /** Clear timer. 545 * 546 * Clears (cancels) timer and returns last state of the timer. 547 * This can be one of: 548 * - fts_not_set If the timer has not been set or has been cleared 549 * - fts_active Timer was set but did not fire 550 * - fts_fired Timer fired 551 * 552 * @param timer Timer 553 * @return Last timer state 554 */ 555 fibril_timer_state_t fibril_timer_clear(fibril_timer_t *timer) 556 { 557 fibril_timer_state_t old_state; 558 559 fibril_mutex_lock(&timer->lock); 560 old_state = timer->state; 561 timer->state = fts_not_set; 562 563 timer->delay = 0; 564 timer->fun = NULL; 565 timer->arg = NULL; 566 fibril_condvar_broadcast(&timer->cv); 567 fibril_mutex_unlock(&timer->lock); 568 569 return old_state; 570 } 571 449 572 /** @} 450 573 */ -
uspace/lib/c/generic/io/printf_core.c
rba72f2b r6843a9c 283 283 /* Print leading spaces. */ 284 284 size_t strw = str_length(str); 285 if ( precision == 0)285 if ((precision == 0) || (precision > strw)) 286 286 precision = strw; 287 287 … … 331 331 /* Print leading spaces. */ 332 332 size_t strw = wstr_length(str); 333 if ( precision == 0)333 if ((precision == 0) || (precision > strw)) 334 334 precision = strw; 335 335 -
uspace/lib/c/generic/ipc.c
rba72f2b r6843a9c 48 48 #include <fibril.h> 49 49 #include <macros.h> 50 #include "private/libc.h" 50 51 51 52 /** … … 646 647 * 647 648 */ 648 int ipc_c onnect_me(int phoneid)649 int ipc_clone_establish(int phoneid) 649 650 { 650 651 sysarg_t newphid; 651 int res = ipc_call_sync_0_5(phoneid, IPC_M_C ONNECT_ME, NULL, NULL,652 NULL, NULL, &newphid);652 int res = ipc_call_sync_0_5(phoneid, IPC_M_CLONE_ESTABLISH, NULL, 653 NULL, NULL, NULL, &newphid); 653 654 if (res) 654 655 return res; … … 760 761 * 761 762 * @param phoneid Phone that will be used to contact the receiving side. 762 * @param dst Destination address space area base.763 763 * @param size Size of the destination address space area. 764 764 * @param arg User defined argument. 765 765 * @param flags Storage for received flags. Can be NULL. 766 * @param dst Destination address space area base. Cannot be NULL. 766 767 * 767 768 * @return Zero on success or a negative error code from errno.h. 768 769 * 769 770 */ 770 int ipc_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg, 771 unsigned int *flags) 772 { 773 sysarg_t tmp_flags = 0; 774 int res = ipc_call_sync_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst, 775 (sysarg_t) size, arg, NULL, &tmp_flags); 771 int ipc_share_in_start(int phoneid, size_t size, sysarg_t arg, 772 unsigned int *flags, void **dst) 773 { 774 sysarg_t _flags = 0; 775 sysarg_t _dst = (sysarg_t) -1; 776 int res = ipc_call_sync_2_4(phoneid, IPC_M_SHARE_IN, (sysarg_t) size, 777 arg, NULL, &_flags, NULL, &_dst); 776 778 777 779 if (flags) 778 *flags = (unsigned int) tmp_flags; 779 780 *flags = (unsigned int) _flags; 781 782 *dst = (void *) _dst; 780 783 return res; 781 784 } … … 783 786 /** Wrapper for answering the IPC_M_SHARE_IN calls. 784 787 * 785 * This wrapper only makes it more comfortable to answer IPC_M_ DATA_READ788 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_IN 786 789 * calls so that the user doesn't have to remember the meaning of each 787 790 * IPC argument. … … 796 799 int ipc_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags) 797 800 { 798 return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) flags); 801 return ipc_answer_3(callid, EOK, (sysarg_t) src, (sysarg_t) flags, 802 (sysarg_t) __entry); 799 803 } 800 804 … … 826 830 * 827 831 */ 828 int ipc_share_out_finalize(ipc_callid_t callid, void * dst)829 { 830 return ipc_answer_ 1(callid, EOK, (sysarg_t) dst);832 int ipc_share_out_finalize(ipc_callid_t callid, void **dst) 833 { 834 return ipc_answer_2(callid, EOK, (sysarg_t) __entry, (sysarg_t) dst); 831 835 } 832 836 -
uspace/lib/c/generic/loader.c
rba72f2b r6843a9c 101 101 102 102 if (rc != EOK) { 103 async_ wait_for(req, NULL);103 async_forget(req); 104 104 return (int) rc; 105 105 } … … 139 139 140 140 if (rc != EOK) { 141 async_ wait_for(req, NULL);141 async_forget(req); 142 142 return (int) rc; 143 143 } … … 177 177 178 178 if (rc != EOK) { 179 async_ wait_for(req, NULL);179 async_forget(req); 180 180 return (int) rc; 181 181 } … … 236 236 237 237 if (rc != EOK) { 238 async_ wait_for(req, NULL);238 async_forget(req); 239 239 return (int) rc; 240 240 } … … 281 281 282 282 if (rc != EOK) { 283 async_ wait_for(req, NULL);283 async_forget(req); 284 284 return (int) rc; 285 285 } -
uspace/lib/c/generic/loc.c
rba72f2b r6843a9c 47 47 static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex); 48 48 static bool loc_callback_created = false; 49 static loc_cat_change_cb_t cat_change_cb = NULL; 49 50 50 51 static async_sess_t *loc_supp_block_sess = NULL; … … 54 55 static async_sess_t *loc_consumer_sess = NULL; 55 56 56 static loc_cat_change_cb_t cat_change_cb = NULL;57 58 57 static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 59 58 { 60 loc_cat_change_cb_t cb_fun;61 62 59 while (true) { 63 60 ipc_call_t call; … … 69 66 } 70 67 71 int retval;72 73 68 switch (IPC_GET_IMETHOD(call)) { 74 69 case LOC_EVENT_CAT_CHANGE: 75 70 fibril_mutex_lock(&loc_callback_mutex); 76 cb_fun = cat_change_cb; 77 if (cb_fun != NULL) { 71 loc_cat_change_cb_t cb_fun = cat_change_cb; 72 fibril_mutex_unlock(&loc_callback_mutex); 73 74 async_answer_0(callid, EOK); 75 76 if (cb_fun != NULL) 78 77 (*cb_fun)(); 79 } 80 fibril_mutex_unlock(&loc_callback_mutex); 81 retval = 0; 78 82 79 break; 83 80 default: 84 retval = ENOTSUP;81 async_answer_0(callid, ENOTSUP); 85 82 } 86 87 async_answer_0(callid, retval);88 83 } 89 84 } … … 101 96 } 102 97 98 /** Create callback 99 * 100 * Must be called with loc_callback_mutex locked. 101 * 102 * @return EOK on success. 103 * 104 */ 103 105 static int loc_callback_create(void) 104 106 { 105 async_exch_t *exch;106 sysarg_t retval;107 int rc = EOK;108 109 fibril_mutex_lock(&loc_callback_mutex);110 111 107 if (!loc_callback_created) { 112 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER); 108 async_exch_t *exch = 109 loc_exchange_begin_blocking(LOC_PORT_CONSUMER); 113 110 114 111 ipc_call_t answer; 115 112 aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer); 116 async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);113 int rc = async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL); 117 114 loc_exchange_end(exch); 118 115 116 if (rc != EOK) 117 return rc; 118 119 sysarg_t retval; 119 120 async_wait_for(req, &retval); 120 if (rc != EOK) 121 goto done; 122 123 if (retval != EOK) { 124 rc = retval; 125 goto done; 126 } 121 if (retval != EOK) 122 return retval; 127 123 128 124 loc_callback_created = true; 129 125 } 130 126 131 rc = EOK; 132 done: 133 fibril_mutex_unlock(&loc_callback_mutex); 134 return rc; 127 return EOK; 135 128 } 136 129 … … 242 235 243 236 /** Register new driver with loc. */ 244 int loc_server_register(const char *name , async_client_conn_t conn)237 int loc_server_register(const char *name) 245 238 { 246 239 async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER); … … 253 246 254 247 if (retval != EOK) { 255 async_wait_for(req, NULL); 256 return retval; 257 } 258 259 async_set_client_connection(conn); 248 async_forget(req); 249 return retval; 250 } 260 251 261 252 exch = loc_exchange_begin(LOC_PORT_SUPPLIER); … … 294 285 295 286 if (retval != EOK) { 296 async_ wait_for(req, NULL);287 async_forget(req); 297 288 return retval; 298 289 } … … 361 352 362 353 if (retval != EOK) { 363 async_ wait_for(req, NULL);354 async_forget(req); 364 355 return retval; 365 356 } … … 410 401 411 402 if (dretval != EOK) { 412 async_ wait_for(req, NULL);403 async_forget(req); 413 404 return dretval; 414 405 } … … 457 448 { 458 449 return loc_get_name_internal(LOC_SERVICE_GET_NAME, svc_id, name); 450 } 451 452 /** Get service server name. 453 * 454 * Provided ID of a service, return the name of its server. 455 * 456 * @param svc_id Service ID 457 * @param name Place to store pointer to new string. Caller should 458 * free it using free(). 459 * @return EOK on success or negative error code 460 */ 461 int loc_service_get_server_name(service_id_t svc_id, char **name) 462 { 463 return loc_get_name_internal(LOC_SERVICE_GET_SERVER_NAME, svc_id, name); 459 464 } 460 465 … … 480 485 481 486 if (retval != EOK) { 482 async_ wait_for(req, NULL);487 async_forget(req); 483 488 return retval; 484 489 } … … 529 534 530 535 if (retval != EOK) { 531 async_ wait_for(req, NULL);536 async_forget(req); 532 537 return retval; 533 538 } … … 692 697 693 698 if (rc != EOK) { 694 async_ wait_for(req, NULL);699 async_forget(req); 695 700 free(devs); 696 701 return 0; … … 741 746 742 747 if (rc != EOK) { 743 async_ wait_for(req, NULL);748 async_forget(req); 744 749 free(devs); 745 750 return 0; … … 769 774 770 775 if (rc != EOK) { 771 async_ wait_for(req, NULL);776 async_forget(req); 772 777 return rc; 773 778 } … … 797 802 sysarg_t **data, size_t *count) 798 803 { 799 service_id_t *ids;800 size_t act_size;801 size_t alloc_size;802 int rc;803 804 804 *data = NULL; 805 act_size = 0; /* silence warning */ 806 807 rc = loc_category_get_ids_once(method, arg1, NULL, 0, 805 *count = 0; 806 807 size_t act_size = 0; 808 int rc = loc_category_get_ids_once(method, arg1, NULL, 0, 808 809 &act_size); 809 810 if (rc != EOK) 810 811 return rc; 811 812 alloc_size = act_size;813 ids = malloc(alloc_size);812 813 size_t alloc_size = act_size; 814 service_id_t *ids = malloc(alloc_size); 814 815 if (ids == NULL) 815 816 return ENOMEM; 816 817 817 818 while (true) { 818 819 rc = loc_category_get_ids_once(method, arg1, ids, alloc_size, … … 820 821 if (rc != EOK) 821 822 return rc; 822 823 823 824 if (act_size <= alloc_size) 824 825 break; 825 826 alloc_size *= 2; 827 free(ids); 828 829 ids = malloc(alloc_size); 826 827 alloc_size = act_size; 828 ids = realloc(ids, alloc_size); 830 829 if (ids == NULL) 831 830 return ENOMEM; 832 831 } 833 832 834 833 *count = act_size / sizeof(category_id_t); 835 834 *data = ids; … … 869 868 int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun) 870 869 { 871 if (loc_callback_create() != EOK) 870 fibril_mutex_lock(&loc_callback_mutex); 871 if (loc_callback_create() != EOK) { 872 fibril_mutex_unlock(&loc_callback_mutex); 872 873 return EIO; 873 874 } 875 874 876 cat_change_cb = cb_fun; 877 fibril_mutex_unlock(&loc_callback_mutex); 878 875 879 return EOK; 876 880 } -
uspace/lib/c/generic/malloc.c
rba72f2b r6843a9c 283 283 static bool area_create(size_t size) 284 284 { 285 void *start = as_get_mappable_page(size); 286 if (start == NULL) 287 return false; 288 289 /* Align the heap area on page boundary */ 290 void *astart = (void *) ALIGN_UP((uintptr_t) start, PAGE_SIZE); 285 /* Align the heap area size on page boundary */ 291 286 size_t asize = ALIGN_UP(size, PAGE_SIZE); 292 293 astart = as_area_create(astart, asize,AS_AREA_WRITE | AS_AREA_READ);294 if (astart == (void *) -1)287 void *astart = as_area_create(AS_AREA_ANY, asize, 288 AS_AREA_WRITE | AS_AREA_READ); 289 if (astart == AS_MAP_FAILED) 295 290 return false; 296 291 -
uspace/lib/c/generic/mman.c
rba72f2b r6843a9c 42 42 { 43 43 if (!start) 44 start = as_get_mappable_page(length);44 start = AS_AREA_ANY; 45 45 46 46 // if (!((flags & MAP_SHARED) ^ (flags & MAP_PRIVATE))) -
uspace/lib/c/generic/net/socket_client.c
rba72f2b r6843a9c 44 44 #include <errno.h> 45 45 #include <task.h> 46 #include <ns.h> 46 47 #include <ipc/services.h> 47 48 #include <ipc/socket.h> 48 #include <net/modules.h>49 49 #include <net/in.h> 50 50 #include <net/socket.h> … … 283 283 static async_sess_t *socket_get_tcp_sess(void) 284 284 { 285 if (socket_globals.tcp_sess == NULL) {286 socket_globals.tcp_sess = bind_service(SERVICE_TCP,285 if (socket_globals.tcp_sess == NULL) 286 socket_globals.tcp_sess = service_bind(SERVICE_TCP, 287 287 0, 0, SERVICE_TCP, socket_connection); 288 } 289 288 290 289 return socket_globals.tcp_sess; 291 290 } … … 300 299 static async_sess_t *socket_get_udp_sess(void) 301 300 { 302 if (socket_globals.udp_sess == NULL) {303 socket_globals.udp_sess = bind_service(SERVICE_UDP,301 if (socket_globals.udp_sess == NULL) 302 socket_globals.udp_sess = service_bind(SERVICE_UDP, 304 303 0, 0, SERVICE_UDP, socket_connection); 305 } 306 304 307 305 return socket_globals.udp_sess; 308 306 } … … 378 376 * @return Other error codes as defined for the NET_SOCKET message. 379 377 * @return Other error codes as defined for the 380 * bind_service() function.378 * service_bind() function. 381 379 */ 382 380 int socket(int domain, int type, int protocol) -
uspace/lib/c/generic/ns.c
rba72f2b r6843a9c 37 37 #include <async.h> 38 38 #include <macros.h> 39 #include <errno.h> 39 40 #include "private/ns.h" 40 41 … … 48 49 } 49 50 50 async_sess_t *service_connect(exch_mgmt_t mgmt, s ysarg_t service, sysarg_t arg2,51 async_sess_t *service_connect(exch_mgmt_t mgmt, services_t service, sysarg_t arg2, 51 52 sysarg_t arg3) 52 53 { … … 72 73 } 73 74 74 async_sess_t *service_connect_blocking(exch_mgmt_t mgmt, s ysarg_t service,75 async_sess_t *service_connect_blocking(exch_mgmt_t mgmt, services_t service, 75 76 sysarg_t arg2, sysarg_t arg3) 76 77 { … … 81 82 async_connect_me_to_blocking(mgmt, exch, service, arg2, arg3); 82 83 async_exchange_end(exch); 83 84 84 85 if (!sess) 85 86 return NULL; … … 91 92 */ 92 93 async_sess_args_set(sess, arg2, arg3, 0); 94 95 return sess; 96 } 97 98 /** Create bidirectional connection with a service 99 * 100 * @param[in] service Service. 101 * @param[in] arg1 First parameter. 102 * @param[in] arg2 Second parameter. 103 * @param[in] arg3 Third parameter. 104 * @param[in] client_receiver Message receiver. 105 * 106 * @return Session to the service. 107 * @return Other error codes as defined by async_connect_to_me(). 108 * 109 */ 110 async_sess_t *service_bind(services_t service, sysarg_t arg1, sysarg_t arg2, 111 sysarg_t arg3, async_client_conn_t client_receiver) 112 { 113 /* Connect to the needed service */ 114 async_sess_t *sess = 115 service_connect_blocking(EXCHANGE_SERIALIZE, service, 0, 0); 116 if (sess != NULL) { 117 /* Request callback connection */ 118 async_exch_t *exch = async_exchange_begin(sess); 119 int rc = async_connect_to_me(exch, arg1, arg2, arg3, 120 client_receiver, NULL); 121 async_exchange_end(exch); 122 123 if (rc != EOK) { 124 async_hangup(sess); 125 errno = rc; 126 return NULL; 127 } 128 } 93 129 94 130 return sess; -
uspace/lib/c/generic/private/async.h
rba72f2b r6843a9c 81 81 } awaiter_t; 82 82 83 extern void awaiter_initialize(awaiter_t *); 84 83 85 extern void __async_init(void); 84 86 extern void async_insert_timeout(awaiter_t *); -
uspace/lib/c/generic/stacktrace.c
rba72f2b r6843a9c 38 38 #include <sys/types.h> 39 39 #include <errno.h> 40 #include <unistd.h> 40 41 41 42 static int stacktrace_read_uintptr(void *arg, uintptr_t addr, uintptr_t *data); -
uspace/lib/c/generic/stats.c
rba72f2b r6843a9c 40 40 #include <inttypes.h> 41 41 #include <malloc.h> 42 #include <unistd.h> 42 43 43 44 #define SYSINFO_STATS_MAX_PATH 64 -
uspace/lib/c/generic/str.c
rba72f2b r6843a9c 46 46 #include <mem.h> 47 47 #include <str.h> 48 49 /** Check the condition if wchar_t is signed */ 50 #ifdef WCHAR_IS_UNSIGNED 51 #define WCHAR_SIGNED_CHECK(cond) (true) 52 #else 53 #define WCHAR_SIGNED_CHECK(cond) (cond) 54 #endif 48 55 49 56 /** Byte mask consisting of lowest @n bits (out of 8) */ … … 261 268 } 262 269 270 /** Get size of string with size limit. 271 * 272 * Get the number of bytes which are used by the string @a str 273 * (excluding the NULL-terminator), but no more than @max_size bytes. 274 * 275 * @param str String to consider. 276 * @param max_size Maximum number of bytes to measure. 277 * 278 * @return Number of bytes used by the string 279 * 280 */ 281 size_t str_nsize(const char *str, size_t max_size) 282 { 283 size_t size = 0; 284 285 while ((*str++ != 0) && (size < max_size)) 286 size++; 287 288 return size; 289 } 290 291 /** Get size of wide string with size limit. 292 * 293 * Get the number of bytes which are used by the wide string @a str 294 * (excluding the NULL-terminator), but no more than @max_size bytes. 295 * 296 * @param str Wide string to consider. 297 * @param max_size Maximum number of bytes to measure. 298 * 299 * @return Number of bytes used by the wide string 300 * 301 */ 302 size_t wstr_nsize(const wchar_t *str, size_t max_size) 303 { 304 return (wstr_nlength(str, max_size) * sizeof(wchar_t)); 305 } 306 263 307 /** Get size of wide string with length limit. 264 308 * … … 362 406 bool ascii_check(wchar_t ch) 363 407 { 364 if ( (ch >= 0) && (ch <= 127))408 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127)) 365 409 return true; 366 410 … … 375 419 bool chr_check(wchar_t ch) 376 420 { 377 if ( (ch >= 0) && (ch <= 1114111))421 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111)) 378 422 return true; 379 423 … … 476 520 * @param count Size of the destination buffer (must be > 0). 477 521 * @param src Source string. 522 * 478 523 */ 479 524 void str_cpy(char *dest, size_t size, const char *src) … … 508 553 * @param src Source string. 509 554 * @param n Maximum number of bytes to read from @a src. 555 * 510 556 */ 511 557 void str_ncpy(char *dest, size_t size, const char *src, size_t n) … … 839 885 840 886 return NULL; 887 } 888 889 /** Removes specified trailing characters from a string. 890 * 891 * @param str String to remove from. 892 * @param ch Character to remove. 893 */ 894 void str_rtrim(char *str, wchar_t ch) 895 { 896 size_t off = 0; 897 size_t pos = 0; 898 wchar_t c; 899 bool update_last_chunk = true; 900 char *last_chunk = NULL; 901 902 while ((c = str_decode(str, &off, STR_NO_LIMIT))) { 903 if (c != ch) { 904 update_last_chunk = true; 905 last_chunk = NULL; 906 } else if (update_last_chunk) { 907 update_last_chunk = false; 908 last_chunk = (str + pos); 909 } 910 pos = off; 911 } 912 913 if (last_chunk) 914 *last_chunk = '\0'; 915 } 916 917 /** Removes specified leading characters from a string. 918 * 919 * @param str String to remove from. 920 * @param ch Character to remove. 921 */ 922 void str_ltrim(char *str, wchar_t ch) 923 { 924 wchar_t acc; 925 size_t off = 0; 926 size_t pos = 0; 927 size_t str_sz = str_size(str); 928 929 while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) { 930 if (acc != ch) 931 break; 932 else 933 pos = off; 934 } 935 936 if (pos > 0) { 937 memmove(str, &str[pos], str_sz - pos); 938 pos = str_sz - pos; 939 str[str_sz - pos] = '\0'; 940 } 841 941 } 842 942 … … 1444 1544 * 1445 1545 */ 1446 int str_uint64 (const char *nptr, char **endptr, unsigned int base,1546 int str_uint64_t(const char *nptr, char **endptr, unsigned int base, 1447 1547 bool strict, uint64_t *result) 1448 1548 { -
uspace/lib/c/generic/sysinfo.c
rba72f2b r6843a9c 39 39 #include <malloc.h> 40 40 #include <bool.h> 41 #include <unistd.h> 42 43 /** Get sysinfo keys size 44 * 45 * @param path Sysinfo path. 46 * @param value Pointer to store the keys size. 47 * 48 * @return EOK if the keys were successfully read. 49 * 50 */ 51 static int sysinfo_get_keys_size(const char *path, size_t *size) 52 { 53 return (int) __SYSCALL3(SYS_SYSINFO_GET_KEYS_SIZE, (sysarg_t) path, 54 (sysarg_t) str_size(path), (sysarg_t) size); 55 } 56 57 /** Get sysinfo keys 58 * 59 * @param path Sysinfo path. 60 * @param value Pointer to store the keys size. 61 * 62 * @return Keys read from sysinfo or NULL if the 63 * sysinfo item has no subkeys. 64 * The returned non-NULL pointer should be 65 * freed by free(). 66 * 67 */ 68 char *sysinfo_get_keys(const char *path, size_t *size) 69 { 70 /* 71 * The size of the keys might change during time. 72 * Unfortunatelly we cannot allocate the buffer 73 * and transfer the keys as a single atomic operation. 74 */ 75 76 /* Get the keys size */ 77 int ret = sysinfo_get_keys_size(path, size); 78 if ((ret != EOK) || (size == 0)) { 79 /* 80 * Item with no subkeys. 81 */ 82 *size = 0; 83 return NULL; 84 } 85 86 char *data = malloc(*size); 87 if (data == NULL) { 88 *size = 0; 89 return NULL; 90 } 91 92 /* Get the data */ 93 size_t sz; 94 ret = __SYSCALL5(SYS_SYSINFO_GET_KEYS, (sysarg_t) path, 95 (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size, 96 (sysarg_t) &sz); 97 if (ret == EOK) { 98 *size = sz; 99 return data; 100 } 101 102 free(data); 103 *size = 0; 104 return NULL; 105 } 41 106 42 107 /** Get sysinfo item type … … 70 135 /** Get sysinfo binary data size 71 136 * 72 * @param path Sysinfo path.73 * @param value Pointer to store the binary data size.137 * @param path Sysinfo path. 138 * @param size Pointer to store the binary data size. 74 139 * 75 140 * @return EOK if the value was successfully read and … … 85 150 /** Get sysinfo binary data 86 151 * 87 * @param path Sysinfo path.88 * @param value Pointer to store the binary data size.152 * @param path Sysinfo path. 153 * @param size Pointer to store the binary data size. 89 154 * 90 155 * @return Binary data read from sysinfo or NULL if the … … 134 199 } 135 200 201 /** Get sysinfo property 202 * 203 * @param path Sysinfo path. 204 * @param name Property name. 205 * @param size Pointer to store the binary data size. 206 * 207 * @return Property value read from sysinfo or NULL if the 208 * sysinfo item value type is not binary data. 209 * The returned non-NULL pointer should be 210 * freed by free(). 211 * 212 */ 213 void *sysinfo_get_property(const char *path, const char *name, size_t *size) 214 { 215 size_t total_size; 216 void *data = sysinfo_get_data(path, &total_size); 217 if ((data == NULL) || (total_size == 0)) { 218 *size = 0; 219 return NULL; 220 } 221 222 size_t pos = 0; 223 while (pos < total_size) { 224 /* Process each property with sanity checks */ 225 size_t cur_size = str_nsize(data + pos, total_size - pos); 226 if (((char *) data)[pos + cur_size] != 0) 227 break; 228 229 bool found = (str_cmp(data + pos, name) == 0); 230 231 pos += cur_size + 1; 232 if (pos >= total_size) 233 break; 234 235 /* Process value size */ 236 size_t value_size; 237 memcpy(&value_size, data + pos, sizeof(value_size)); 238 239 pos += sizeof(value_size); 240 if ((pos >= total_size) || (pos + value_size > total_size)) 241 break; 242 243 if (found) { 244 void *value = malloc(value_size); 245 if (value == NULL) 246 break; 247 248 memcpy(value, data + pos, value_size); 249 free(data); 250 251 *size = value_size; 252 return value; 253 } 254 255 pos += value_size; 256 } 257 258 free(data); 259 260 *size = 0; 261 return NULL; 262 } 263 136 264 /** @} 137 265 */ -
uspace/lib/c/generic/thread.c
rba72f2b r6843a9c 41 41 #include <str.h> 42 42 #include <async.h> 43 #include <errno.h> 44 #include <as.h> 43 45 #include "private/thread.h" 44 46 45 #ifndef THREAD_INITIAL_STACK_PAGES _NO46 #define THREAD_INITIAL_STACK_PAGES_NO 2 47 #ifndef THREAD_INITIAL_STACK_PAGES 48 #define THREAD_INITIAL_STACK_PAGES 2 47 49 #endif 48 50 … … 65 67 66 68 uarg->uspace_thread_function(uarg->uspace_thread_arg); 67 /* XXX: we cannot free the userspace stack while running on it 68 free(uarg->uspace_stack); 69 free(uarg); 70 */ 69 /* 70 * XXX: we cannot free the userspace stack while running on it 71 * 72 * free(uarg->uspace_stack); 73 * free(uarg); 74 */ 71 75 72 76 /* If there is a manager, destroy it */ … … 92 96 thread_id_t *tid) 93 97 { 94 char *stack; 95 uspace_arg_t *uarg; 96 int rc; 97 98 stack = (char *) malloc(getpagesize() * THREAD_INITIAL_STACK_PAGES_NO); 99 if (!stack) 100 return -1; 101 102 uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t)); 103 if (!uarg) { 104 free(stack); 105 return -1; 98 uspace_arg_t *uarg = 99 (uspace_arg_t *) malloc(sizeof(uspace_arg_t)); 100 if (!uarg) 101 return ENOMEM; 102 103 size_t stack_size = getpagesize() * THREAD_INITIAL_STACK_PAGES; 104 void *stack = as_area_create(AS_AREA_ANY, stack_size, 105 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); 106 if (stack == AS_MAP_FAILED) { 107 free(uarg); 108 return ENOMEM; 106 109 } 107 110 108 111 uarg->uspace_entry = (void *) FADDR(__thread_entry); 109 uarg->uspace_stack = (void *) stack; 112 uarg->uspace_stack = stack; 113 uarg->uspace_stack_size = stack_size; 110 114 uarg->uspace_thread_function = function; 111 115 uarg->uspace_thread_arg = arg; 112 116 uarg->uspace_uarg = uarg; 113 117 114 rc = __SYSCALL4(SYS_THREAD_CREATE, (sysarg_t) uarg, (sysarg_t) name,115 (sysarg_t) str_size(name), (sysarg_t) tid);118 int rc = __SYSCALL4(SYS_THREAD_CREATE, (sysarg_t) uarg, 119 (sysarg_t) name, (sysarg_t) str_size(name), (sysarg_t) tid); 116 120 117 if (rc ) {121 if (rc != EOK) { 118 122 /* 119 123 * Failed to create a new thread. 120 * Free up the allocated structures.124 * Free up the allocated data. 121 125 */ 126 as_area_destroy(stack); 122 127 free(uarg); 123 free(stack);124 128 } 125 129 126 130 return rc; 127 131 } -
uspace/lib/c/generic/time.c
rba72f2b r6843a9c 43 43 #include <ddi.h> 44 44 #include <libc.h> 45 #include <unistd.h> 45 46 46 47 /** Pointer to kernel shared variables with time */ … … 147 148 } 148 149 149 void *addr = as_get_mappable_page(PAGE_SIZE); 150 if (addr == NULL) { 151 errno = ENOMEM; 152 return -1; 153 } 154 155 rc = physmem_map((void *) faddr, addr, 1, 156 AS_AREA_READ | AS_AREA_CACHEABLE); 150 void *addr; 151 rc = physmem_map((void *) faddr, 1, 152 AS_AREA_READ | AS_AREA_CACHEABLE, &addr); 157 153 if (rc != EOK) { 158 154 as_area_destroy(addr); -
uspace/lib/c/generic/vfs/vfs.c
rba72f2b r6843a9c 831 831 } 832 832 833 int get_mtab_list(list_t *mtab_list) 834 { 835 sysarg_t rc; 836 aid_t req; 837 size_t i; 838 sysarg_t num_mounted_fs; 839 840 async_exch_t *exch = vfs_exchange_begin(); 841 842 req = async_send_0(exch, VFS_IN_MTAB_GET, NULL); 843 844 /* Ask VFS how many filesystems are mounted */ 845 rc = async_req_0_1(exch, VFS_IN_PING, &num_mounted_fs); 846 if (rc != EOK) 847 goto exit; 848 849 for (i = 0; i < num_mounted_fs; ++i) { 850 mtab_ent_t *mtab_ent; 851 852 mtab_ent = malloc(sizeof(mtab_ent_t)); 853 if (!mtab_ent) { 854 rc = ENOMEM; 855 goto exit; 856 } 857 858 memset(mtab_ent, 0, sizeof(mtab_ent_t)); 859 860 rc = async_data_read_start(exch, (void *) mtab_ent->mp, 861 MAX_PATH_LEN); 862 if (rc != EOK) 863 goto exit; 864 865 rc = async_data_read_start(exch, (void *) mtab_ent->opts, 866 MAX_MNTOPTS_LEN); 867 if (rc != EOK) 868 goto exit; 869 870 rc = async_data_read_start(exch, (void *) mtab_ent->fs_name, 871 FS_NAME_MAXLEN); 872 if (rc != EOK) 873 goto exit; 874 875 sysarg_t p[2]; 876 877 rc = async_req_0_2(exch, VFS_IN_PING, &p[0], &p[1]); 878 if (rc != EOK) 879 goto exit; 880 881 mtab_ent->instance = p[0]; 882 mtab_ent->service_id = p[1]; 883 884 link_initialize(&mtab_ent->link); 885 list_append(&mtab_ent->link, mtab_list); 886 } 887 888 exit: 889 async_wait_for(req, &rc); 890 vfs_exchange_end(exch); 891 return rc; 892 } 893 833 894 /** @} 834 895 */
Note:
See TracChangeset
for help on using the changeset viewer.
