Changes in / [3abfe9a8:eaf4c393] in mainline
- Files:
-
- 2 deleted
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/Makefile
r3abfe9a8 reaf4c393 240 240 generic/src/lib/func.c \ 241 241 generic/src/lib/memstr.c \ 242 generic/src/lib/memfnc.c \243 242 generic/src/lib/sort.c \ 244 243 generic/src/lib/str.c \ -
kernel/generic/include/memstr.h
r3abfe9a8 reaf4c393 38 38 #include <typedefs.h> 39 39 40 #define memset(dst, val, cnt) __builtin_memset((dst), (val), (cnt))41 #define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt))42 43 40 extern void memsetb(void *, size_t, uint8_t); 44 41 extern void memsetw(void *, size_t, uint16_t); 42 extern void *memset(void *, int, size_t); 43 44 extern void *memcpy(void *, const void *, size_t); 45 45 extern void *memmove(void *, const void *, size_t); 46 46 -
kernel/generic/src/lib/memstr.c
r3abfe9a8 reaf4c393 43 43 #include <memstr.h> 44 44 #include <typedefs.h> 45 #include <align.h> 45 46 46 47 /** Fill block of memory. … … 55 56 void memsetb(void *dst, size_t cnt, uint8_t val) 56 57 { 57 memset(dst, val, cnt);58 __builtin_memset(dst, val, cnt); 58 59 } 59 60 … … 75 76 for (i = 0; i < cnt; i++) 76 77 ptr[i] = val; 78 } 79 80 /** Fill block of memory. 81 * 82 * Fill cnt bytes at dst address with the value val. 83 * 84 * @param dst Destination address to fill. 85 * @param val Value to fill. 86 * @param cnt Number of bytes to fill. 87 * 88 * @return Destination address. 89 * 90 */ 91 void *memset(void *dst, int val, size_t cnt) 92 { 93 return __builtin_memset(dst, val, cnt); 94 } 95 96 /** Move memory block without overlapping. 97 * 98 * Copy cnt bytes from src address to dst address. The source 99 * and destination memory areas cannot overlap. 100 * 101 * @param dst Destination address to copy to. 102 * @param src Source address to copy from. 103 * @param cnt Number of bytes to copy. 104 * 105 * @return Destination address. 106 * 107 */ 108 void *memcpy(void *dst, const void *src, size_t cnt) 109 { 110 return __builtin_memcpy(dst, src, cnt); 77 111 } 78 112 … … 99 133 return memcpy(dst, src, cnt); 100 134 135 const uint8_t *sp; 101 136 uint8_t *dp; 102 const uint8_t *sp;103 137 104 138 /* Which direction? */ 105 139 if (src > dst) { 106 140 /* Forwards. */ 141 sp = src; 107 142 dp = dst; 108 sp = src;109 143 110 144 while (cnt-- != 0) … … 112 146 } else { 113 147 /* Backwards. */ 148 sp = src + (cnt - 1); 114 149 dp = dst + (cnt - 1); 115 sp = src + (cnt - 1);116 150 117 151 while (cnt-- != 0) -
uspace/lib/c/generic/net/packet.c
r3abfe9a8 reaf4c393 190 190 } 191 191 } 192 gpm_destroy(&pm_globals.packet_map , free);192 gpm_destroy(&pm_globals.packet_map); 193 193 /* leave locked */ 194 194 } -
uspace/lib/c/generic/net/socket_client.c
r3abfe9a8 reaf4c393 749 749 dyn_fifo_destroy(&socket->received); 750 750 dyn_fifo_destroy(&socket->accepted); 751 sockets_exclude(socket_get_sockets(), socket->socket_id , free);751 sockets_exclude(socket_get_sockets(), socket->socket_id); 752 752 } 753 753 -
uspace/lib/c/include/adt/generic_char_map.h
r3abfe9a8 reaf4c393 47 47 #define GENERIC_CHAR_MAP_MAGIC_VALUE 0x12345622 48 48 49 /** Generic destructor function pointer. */50 #define DTOR_T(identifier) \51 void (*identifier)(const void *)52 53 49 /** Character string to generic type map declaration. 54 50 * @param[in] name Name of the map. … … 68 64 int name##_add(name##_t *, const uint8_t *, const size_t, type *); \ 69 65 int name##_count(name##_t *); \ 70 void name##_destroy(name##_t * , DTOR_T()); \71 void name##_exclude(name##_t *, const uint8_t *, const size_t , DTOR_T()); \66 void name##_destroy(name##_t *); \ 67 void name##_exclude(name##_t *, const uint8_t *, const size_t); \ 72 68 type *name##_find(name##_t *, const uint8_t *, const size_t); \ 73 69 int name##_initialize(name##_t *); \ … … 88 84 type *value) \ 89 85 { \ 86 int rc; \ 90 87 int index; \ 91 88 if (!name##_is_valid(map)) \ … … 94 91 if (index < 0) \ 95 92 return index; \ 96 return char_map_add(&map->names, name, length, index); \ 93 rc = char_map_add(&map->names, name, length, index); \ 94 if (rc != EOK) { \ 95 name##_items_exclude_index(&map->values, index); \ 96 return rc; \ 97 } \ 98 return EOK; \ 97 99 } \ 98 100 \ … … 103 105 } \ 104 106 \ 105 void name##_destroy(name##_t *map , DTOR_T(dtor)) \107 void name##_destroy(name##_t *map) \ 106 108 { \ 107 109 if (name##_is_valid(map)) { \ 108 110 char_map_destroy(&map->names); \ 109 name##_items_destroy(&map->values , dtor); \111 name##_items_destroy(&map->values); \ 110 112 } \ 111 113 } \ 112 114 \ 113 115 void name##_exclude(name##_t *map, const uint8_t *name, \ 114 const size_t length , DTOR_T(dtor)) \116 const size_t length) \ 115 117 { \ 116 118 if (name##_is_valid(map)) { \ … … 119 121 if (index != CHAR_MAP_NULL) \ 120 122 name##_items_exclude_index(&map->values, \ 121 index , dtor); \123 index); \ 122 124 } \ 123 125 } \ -
uspace/lib/c/include/adt/generic_field.h
r3abfe9a8 reaf4c393 46 46 #define GENERIC_FIELD_MAGIC_VALUE 0x55667788 47 47 48 /** Generic destructor function pointer. */49 #define DTOR_T(identifier) \50 void (*identifier)(const void *)51 52 48 /** Generic type field declaration. 53 49 * … … 67 63 int name##_add(name##_t *, type *); \ 68 64 int name##_count(name##_t *); \ 69 void name##_destroy(name##_t * , DTOR_T()); \70 void name##_exclude_index(name##_t *, int , DTOR_T()); \65 void name##_destroy(name##_t *); \ 66 void name##_exclude_index(name##_t *, int); \ 71 67 type **name##_get_field(name##_t *); \ 72 68 type *name##_get_index(name##_t *, int); \ … … 107 103 } \ 108 104 \ 109 void name##_destroy(name##_t *field , DTOR_T(dtor)) \105 void name##_destroy(name##_t *field) \ 110 106 { \ 111 107 if (name##_is_valid(field)) { \ 112 108 int index; \ 113 109 field->magic = 0; \ 114 if (dtor) { \ 115 for (index = 0; index < field->next; index++) { \ 116 if (field->items[index]) \ 117 dtor(field->items[index]); \ 118 } \ 110 for (index = 0; index < field->next; index++) { \ 111 if (field->items[index]) \ 112 free(field->items[index]); \ 119 113 } \ 120 114 free(field->items); \ … … 122 116 } \ 123 117 \ 124 void name##_exclude_index(name##_t *field, int index , DTOR_T(dtor)) \118 void name##_exclude_index(name##_t *field, int index) \ 125 119 { \ 126 120 if (name##_is_valid(field) && (index >= 0) && \ 127 121 (index < field->next) && (field->items[index])) { \ 128 if (dtor) \ 129 dtor(field->items[index]); \ 122 free(field->items[index]); \ 130 123 field->items[index] = NULL; \ 131 124 } \ -
uspace/lib/c/include/adt/int_map.h
r3abfe9a8 reaf4c393 49 49 #define INT_MAP_ITEM_MAGIC_VALUE 0x55667788 50 50 51 /** Generic destructor function pointer. */52 #define DTOR_T(identifier) \53 void (*identifier)(const void *)54 55 51 /** Integer to generic type map declaration. 56 52 * … … 76 72 \ 77 73 int name##_add(name##_t *, int, type *); \ 78 void name##_clear(name##_t * , DTOR_T()); \74 void name##_clear(name##_t *); \ 79 75 int name##_count(name##_t *); \ 80 void name##_destroy(name##_t * , DTOR_T()); \81 void name##_exclude(name##_t *, int , DTOR_T()); \82 void name##_exclude_index(name##_t *, int , DTOR_T()); \76 void name##_destroy(name##_t *); \ 77 void name##_exclude(name##_t *, int); \ 78 void name##_exclude_index(name##_t *, int); \ 83 79 type *name##_find(name##_t *, int); \ 84 80 int name##_update(name##_t *, int, int); \ … … 86 82 int name##_initialize(name##_t *); \ 87 83 int name##_is_valid(name##_t *); \ 88 void name##_item_destroy(name##_item_t * , DTOR_T()); \84 void name##_item_destroy(name##_item_t *); \ 89 85 int name##_item_is_valid(name##_item_t *); 90 86 … … 119 115 } \ 120 116 \ 121 void name##_clear(name##_t *map , DTOR_T(dtor)) \117 void name##_clear(name##_t *map) \ 122 118 { \ 123 119 if (name##_is_valid(map)) { \ … … 126 122 if (name##_item_is_valid(&map->items[index])) { \ 127 123 name##_item_destroy( \ 128 &map->items[index] , dtor); \124 &map->items[index]); \ 129 125 } \ 130 126 } \ … … 139 135 } \ 140 136 \ 141 void name##_destroy(name##_t *map , DTOR_T(dtor)) \137 void name##_destroy(name##_t *map) \ 142 138 { \ 143 139 if (name##_is_valid(map)) { \ … … 147 143 if (name##_item_is_valid(&map->items[index])) { \ 148 144 name##_item_destroy( \ 149 &map->items[index] , dtor); \145 &map->items[index]); \ 150 146 } \ 151 147 } \ … … 154 150 } \ 155 151 \ 156 void name##_exclude(name##_t *map, int key , DTOR_T(dtor)) \152 void name##_exclude(name##_t *map, int key) \ 157 153 { \ 158 154 if (name##_is_valid(map)) { \ … … 162 158 (map->items[index].key == key)) { \ 163 159 name##_item_destroy( \ 164 &map->items[index] , dtor); \165 } \ 166 } \ 167 } \ 168 } \ 169 \ 170 void name##_exclude_index(name##_t *map, int index , DTOR_T(dtor)) \160 &map->items[index]); \ 161 } \ 162 } \ 163 } \ 164 } \ 165 \ 166 void name##_exclude_index(name##_t *map, int index) \ 171 167 { \ 172 168 if (name##_is_valid(map) && (index >= 0) && \ 173 169 (index < map->next) && \ 174 170 name##_item_is_valid(&map->items[index])) { \ 175 name##_item_destroy(&map->items[index] , dtor); \171 name##_item_destroy(&map->items[index]); \ 176 172 } \ 177 173 } \ … … 240 236 } \ 241 237 \ 242 void name##_item_destroy(name##_item_t *item , DTOR_T(dtor)) \238 void name##_item_destroy(name##_item_t *item) \ 243 239 { \ 244 240 if (name##_item_is_valid(item)) { \ 245 241 item->magic = 0; \ 246 242 if (item->value) { \ 247 if (dtor) \ 248 dtor(item->value); \ 243 free(item->value); \ 249 244 item->value = NULL; \ 250 245 } \ -
uspace/lib/net/tl/socket_core.c
r3abfe9a8 reaf4c393 107 107 socket_release(socket); 108 108 109 socket_cores_exclude(local_sockets, socket->socket_id , free);109 socket_cores_exclude(local_sockets, socket->socket_id); 110 110 } 111 111 … … 230 230 231 231 fail: 232 socket_port_map_destroy(&socket_port->map , free);232 socket_port_map_destroy(&socket_port->map); 233 233 free(socket_port); 234 234 return rc; … … 649 649 if (socket_port->count <= 0) { 650 650 // destroy the map 651 socket_port_map_destroy(&socket_port->map , free);651 socket_port_map_destroy(&socket_port->map); 652 652 // release the port 653 653 socket_ports_exclude(global_sockets, 654 socket->port , free);654 socket->port); 655 655 } else { 656 656 // remove 657 657 socket_port_map_exclude(&socket_port->map, 658 socket->key, socket->key_length , free);658 socket->key, socket->key_length); 659 659 } 660 660 } -
uspace/lib/net/tl/tl_common.c
r3abfe9a8 reaf4c393 182 182 else 183 183 packet_dimensions_exclude(packet_dimensions, 184 DEVICE_INVALID_ID , free);184 DEVICE_INVALID_ID); 185 185 } 186 186 } -
uspace/srv/devman/devman.c
r3abfe9a8 reaf4c393 266 266 } 267 267 268 ssize_t read_bytes = safe_read(fd, buf, len); 269 if (read_bytes <= 0) { 268 if (read(fd, buf, len) <= 0) { 270 269 printf(NAME ": unable to read file '%s'.\n", conf_path); 271 270 goto cleanup; 272 271 } 273 buf[ read_bytes] = 0;272 buf[len] = 0; 274 273 275 274 suc = parse_match_ids(buf, ids); … … 1124 1123 fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path) 1125 1124 { 1126 assert(path != NULL);1127 1128 bool is_absolute = path[0] == '/';1129 if (!is_absolute) {1130 return NULL;1131 }1132 1133 1125 fibril_rwlock_read_lock(&tree->rwlock); 1134 1126 … … 1140 1132 char *rel_path = path; 1141 1133 char *next_path_elem = NULL; 1142 bool cont = true;1134 bool cont = (rel_path[0] == '/'); 1143 1135 1144 1136 while (cont && fun != NULL) { -
uspace/srv/devman/main.c
r3abfe9a8 reaf4c393 477 477 dev = fun->dev; 478 478 479 /* 480 * For a valid function to connect to we need a device. The root 481 * function, for example, has no device and cannot be connected to. 482 * This means @c dev needs to be valid regardless whether we are 483 * connecting to a device or to a function. 484 */ 485 if (dev == NULL) { 479 if (fun == NULL && dev == NULL) { 486 480 printf(NAME ": devman_forward error - no device or function with " 487 481 "handle %" PRIun " was found.\n", handle); -
uspace/srv/devman/util.c
r3abfe9a8 reaf4c393 111 111 } 112 112 113 ssize_t safe_read(int fd, void *buffer, size_t size)114 {115 if (size == 0) {116 return 0;117 }118 119 uint8_t *buf_ptr = (uint8_t *) buffer;120 121 size_t total_read = 0;122 while (total_read < size) {123 ssize_t bytes_read = read(fd, buf_ptr, size - total_read);124 if (bytes_read < 0) {125 /* Error. */126 return bytes_read;127 } else if (bytes_read == 0) {128 /* Possibly end of file. */129 break;130 } else {131 /* Read at least something. */132 buf_ptr += bytes_read;133 total_read += bytes_read;134 }135 }136 137 return (ssize_t) total_read;138 }139 140 113 /** @} 141 114 */ -
uspace/srv/devman/util.h
r3abfe9a8 reaf4c393 47 47 extern void replace_char(char *, char, char); 48 48 49 extern ssize_t safe_read(int, void *, size_t);50 51 49 #endif 52 50 -
uspace/srv/hw/netif/ne2000/dp8390.c
r3abfe9a8 reaf4c393 391 391 392 392 if ((size < ETH_MIN_PACK_SIZE) || (size > ETH_MAX_PACK_SIZE_TAGGED)) { 393 fibril_mutex_unlock(&ne2k->sq_mutex);394 393 fprintf(stderr, "%s: Frame dropped (invalid size %zu bytes)\n", 395 394 NAME, size); -
uspace/srv/net/il/arp/arp.c
r3abfe9a8 reaf4c393 157 157 158 158 arp_clear_addr(&proto->addresses); 159 arp_addr_destroy(&proto->addresses , free);160 } 161 } 162 163 arp_protos_clear(&device->protos , free);159 arp_addr_destroy(&proto->addresses); 160 } 161 } 162 163 arp_protos_clear(&device->protos); 164 164 } 165 165 … … 184 184 } 185 185 186 arp_cache_clear(&arp_globals.cache , free);186 arp_cache_clear(&arp_globals.cache); 187 187 fibril_mutex_unlock(&arp_globals.lock); 188 188 … … 212 212 arp_clear_trans(trans); 213 213 214 arp_addr_exclude(&proto->addresses, address->value, address->length , free);214 arp_addr_exclude(&proto->addresses, address->value, address->length); 215 215 216 216 fibril_mutex_unlock(&arp_globals.lock); … … 345 345 header->protocol_length, trans); 346 346 if (rc != EOK) { 347 free(trans);347 /* The generic char map has already freed trans! */ 348 348 return rc; 349 349 } … … 556 556 if (index < 0) { 557 557 fibril_mutex_unlock(&arp_globals.lock); 558 arp_protos_destroy(&device->protos , free);558 arp_protos_destroy(&device->protos); 559 559 free(device); 560 560 return index; … … 569 569 if (device->phone < 0) { 570 570 fibril_mutex_unlock(&arp_globals.lock); 571 arp_protos_destroy(&device->protos , free);571 arp_protos_destroy(&device->protos); 572 572 free(device); 573 573 return EREFUSED; … … 579 579 if (rc != EOK) { 580 580 fibril_mutex_unlock(&arp_globals.lock); 581 arp_protos_destroy(&device->protos , free);581 arp_protos_destroy(&device->protos); 582 582 free(device); 583 583 return rc; … … 589 589 if (rc != EOK) { 590 590 fibril_mutex_unlock(&arp_globals.lock); 591 arp_protos_destroy(&device->protos , free);591 arp_protos_destroy(&device->protos); 592 592 free(device); 593 593 return rc; … … 601 601 free(device->addr); 602 602 free(device->addr_data); 603 arp_protos_destroy(&device->protos , free);603 arp_protos_destroy(&device->protos); 604 604 free(device); 605 605 return rc; … … 614 614 free(device->broadcast_addr); 615 615 free(device->broadcast_data); 616 arp_protos_destroy(&device->protos , free);616 arp_protos_destroy(&device->protos); 617 617 free(device); 618 618 return rc; … … 746 746 arp_clear_trans(trans); 747 747 arp_addr_exclude(&proto->addresses, target->value, 748 target->length , free);748 target->length); 749 749 return EAGAIN; 750 750 } … … 794 794 trans); 795 795 if (rc != EOK) { 796 free(trans);796 /* The generic char map has already freed trans! */ 797 797 return rc; 798 798 } … … 807 807 arp_clear_trans(trans); 808 808 arp_addr_exclude(&proto->addresses, target->value, 809 target->length , free);809 target->length); 810 810 return ENOENT; 811 811 } -
uspace/srv/net/il/ip/ip.c
r3abfe9a8 reaf4c393 505 505 if (rc != EOK) { 506 506 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 507 ip_routes_destroy(&ip_netif->routes , free);507 ip_routes_destroy(&ip_netif->routes); 508 508 free(ip_netif); 509 509 return rc; -
uspace/srv/net/net/net.c
r3abfe9a8 reaf4c393 555 555 rc = read_netif_configuration(conf_files[i], netif); 556 556 if (rc != EOK) { 557 measured_strings_destroy(&netif->configuration , free);557 measured_strings_destroy(&netif->configuration); 558 558 free(netif); 559 559 return rc; … … 565 565 if (!setting) { 566 566 fprintf(stderr, "%s: Network interface name is missing\n", NAME); 567 measured_strings_destroy(&netif->configuration , free);567 measured_strings_destroy(&netif->configuration); 568 568 free(netif); 569 569 return EINVAL; … … 574 574 int index = netifs_add(&net_globals.netifs, netif->id, netif); 575 575 if (index < 0) { 576 measured_strings_destroy(&netif->configuration , free);576 measured_strings_destroy(&netif->configuration); 577 577 free(netif); 578 578 return index; … … 586 586 index); 587 587 if (rc != EOK) { 588 measured_strings_destroy(&netif->configuration , free);589 netifs_exclude_index(&net_globals.netifs, index , free);588 measured_strings_destroy(&netif->configuration); 589 netifs_exclude_index(&net_globals.netifs, index); 590 590 return rc; 591 591 } … … 595 595 printf("%s: Ignoring failed interface %s (%s)\n", NAME, 596 596 netif->name, str_error(rc)); 597 measured_strings_destroy(&netif->configuration , free);598 netifs_exclude_index(&net_globals.netifs, index , free);597 measured_strings_destroy(&netif->configuration); 598 netifs_exclude_index(&net_globals.netifs, index); 599 599 continue; 600 600 } -
uspace/srv/net/nil/eth/eth.c
r3abfe9a8 reaf4c393 214 214 if (rc != EOK) { 215 215 free(eth_globals.broadcast_addr); 216 eth_devices_destroy(ð_globals.devices , free);216 eth_devices_destroy(ð_globals.devices); 217 217 } 218 218 out: -
uspace/srv/net/tl/tcp/tcp.c
r3abfe9a8 reaf4c393 1707 1707 if (socket->port > 0) { 1708 1708 socket_ports_exclude(&tcp_globals.sockets, 1709 socket->port , free);1709 socket->port); 1710 1710 socket->port = 0; 1711 1711 } … … 2492 2492 rc = packet_dimensions_initialize(&tcp_globals.dimensions); 2493 2493 if (rc != EOK) { 2494 socket_ports_destroy(&tcp_globals.sockets , free);2494 socket_ports_destroy(&tcp_globals.sockets); 2495 2495 goto out; 2496 2496 } -
uspace/srv/net/tl/udp/udp.c
r3abfe9a8 reaf4c393 417 417 rc = packet_dimensions_initialize(&udp_globals.dimensions); 418 418 if (rc != EOK) { 419 socket_ports_destroy(&udp_globals.sockets , free);419 socket_ports_destroy(&udp_globals.sockets); 420 420 fibril_rwlock_write_unlock(&udp_globals.lock); 421 421 return rc; … … 434 434 &data); 435 435 if (rc != EOK) { 436 socket_ports_destroy(&udp_globals.sockets , free);436 socket_ports_destroy(&udp_globals.sockets); 437 437 fibril_rwlock_write_unlock(&udp_globals.lock); 438 438 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.