if we're intentionally using power-of-two sizing for chunks, don't add the header...
[mono-project/dkf.git] / mono / io-layer / shared.c
blob9e70e8c5aec0da235fd4fd3bfa61a499e0eeabeb
1 /*
2 * shared.c: Shared memory handling, and daemon launching
4 * Author:
5 * Dick Porter (dick@ximian.com)
7 * (C) 2002-2006 Novell, Inc.
8 */
11 #include <config.h>
12 #include <glib.h>
13 #include <stdio.h>
14 #include <fcntl.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <errno.h>
18 #include <string.h>
19 #include <unistd.h>
21 #ifdef HAVE_SYS_SEM_H
22 # include <sys/sem.h>
23 #else
24 # define DISABLE_SHARED_HANDLES
25 #endif
27 #ifndef DISABLE_SHARED_HANDLES
28 # include <sys/mman.h>
29 # include <sys/ipc.h>
30 # ifdef HAVE_SYS_UTSNAME_H
31 # include <sys/utsname.h>
32 # endif
33 #endif
35 #include <mono/io-layer/wapi.h>
36 #include <mono/io-layer/wapi-private.h>
37 #include <mono/io-layer/shared.h>
38 #include <mono/io-layer/handles-private.h>
40 #define DEBUGLOG(...)
41 //#define DEBUGLOG(...) g_message(__VA_ARGS__);
43 // Semaphores used when no-shared-memory use is in use
45 static mono_mutex_t noshm_sems[_WAPI_SHARED_SEM_COUNT];
47 gboolean _wapi_shm_disabled = TRUE;
49 static gpointer wapi_storage [16];
51 static void
52 noshm_semaphores_init (void)
54 int i;
56 for (i = 0; i < _WAPI_SHARED_SEM_COUNT; i++)
57 mono_mutex_init (&noshm_sems [i], NULL);
60 static int
61 noshm_sem_lock (int sem)
63 int ret;
65 DEBUGLOG ("%s: locking nosem %d", __func__, sem);
67 ret = mono_mutex_lock (&noshm_sems[sem]);
69 return ret;
72 static int
73 noshm_sem_trylock (int sem)
75 int ret;
77 DEBUGLOG ("%s: trying to lock nosem %d", __func__, sem);
79 ret = mono_mutex_trylock (&noshm_sems[sem]);
81 return ret;
84 static int
85 noshm_sem_unlock (int sem)
87 int ret;
89 DEBUGLOG ("%s: unlocking nosem %d", __func__, sem);
91 ret = mono_mutex_unlock (&noshm_sems[sem]);
93 return ret;
96 #ifdef DISABLE_SHARED_HANDLES
97 void
98 _wapi_shm_semaphores_init (void)
100 noshm_semaphores_init ();
103 void
104 _wapi_shm_semaphores_remove (void)
106 /* Nothing */
110 _wapi_shm_sem_lock (int sem)
112 return noshm_sem_lock (sem);
116 _wapi_shm_sem_trylock (int sem)
118 return noshm_sem_trylock (sem);
122 _wapi_shm_sem_unlock (int sem)
124 return noshm_sem_unlock (sem);
127 gpointer
128 _wapi_shm_attach (_wapi_shm_t type)
130 gpointer res;
132 switch(type) {
133 case WAPI_SHM_DATA:
134 res = g_malloc0 (sizeof(struct _WapiHandleSharedLayout));
135 break;
136 case WAPI_SHM_FILESHARE:
137 res = g_malloc0 (sizeof(struct _WapiFileShareLayout));
138 break;
139 default:
140 g_error ("Invalid type in _wapi_shm_attach ()");
141 return NULL;
144 wapi_storage [type] = res;
145 return res;
148 void
149 _wapi_shm_detach (_wapi_shm_t type)
151 g_free (wapi_storage [type]);
154 gboolean
155 _wapi_shm_enabled (void)
157 return FALSE;
160 #else
162 * Use POSIX shared memory if possible, it is simpler, and it has the advantage that
163 * writes to the shared area does not need to be written to disk, avoiding spinning up
164 * the disk every x secs on laptops.
166 #ifdef HAVE_SHM_OPEN
167 #define USE_SHM 1
168 #endif
170 static gchar *
171 _wapi_shm_base_name (_wapi_shm_t type)
173 gchar *name = NULL;
174 gchar machine_name[256];
175 const gchar *fake_name;
176 struct utsname ubuf;
177 int ret;
178 int len;
180 ret = uname (&ubuf);
181 if (ret == -1) {
182 ubuf.machine[0] = '\0';
183 ubuf.sysname[0] = '\0';
184 } else {
185 g_strdelimit (ubuf.sysname, "/", '_');
186 g_strdelimit (ubuf.machine, "/", '_');
189 fake_name = g_getenv ("MONO_SHARED_HOSTNAME");
190 if (fake_name == NULL) {
191 if (gethostname(machine_name, sizeof(machine_name)) != 0)
192 machine_name[0] = '\0';
193 } else {
194 len = MIN (strlen (fake_name), sizeof (machine_name) - 1);
195 strncpy (machine_name, fake_name, len);
196 machine_name [len] = '\0';
199 switch (type) {
200 case WAPI_SHM_DATA:
201 name = g_strdup_printf ("shared_data-%s-%s-%s-%d-%d-%d",
202 machine_name, ubuf.sysname,
203 ubuf.machine,
204 (int) sizeof(struct _WapiHandleShared),
205 _WAPI_HANDLE_VERSION, 0);
206 break;
208 case WAPI_SHM_FILESHARE:
209 name = g_strdup_printf ("shared_fileshare-%s-%s-%s-%d-%d-%d",
210 machine_name, ubuf.sysname,
211 ubuf.machine,
212 (int) sizeof(struct _WapiFileShare),
213 _WAPI_HANDLE_VERSION, 0);
214 break;
217 return name;
220 #ifdef USE_SHM
222 static gchar *_wapi_shm_shm_name (_wapi_shm_t type)
224 char *base_name = _wapi_shm_base_name (type);
226 /* Also add the uid to avoid permission problems */
227 char *res = g_strdup_printf ("/mono-shared-%d-%s", getuid (), base_name);
229 g_free (base_name);
231 return res;
234 static int
235 _wapi_shm_open (const char *filename, int size)
237 int fd;
239 fd = shm_open (filename, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP);
240 if (fd == -1)
241 /* Maybe /dev/shm is not mounted */
242 return -1;
243 if (ftruncate (fd, size) != 0) {
244 perror ("_wapi_shm_open (): ftruncate ()");
245 g_assert_not_reached ();
248 return fd;
251 #endif
253 static gchar *
254 _wapi_shm_file (_wapi_shm_t type)
256 static gchar file[_POSIX_PATH_MAX];
257 gchar *name = NULL, *filename, *wapi_dir;
259 name = _wapi_shm_base_name (type);
261 /* I don't know how nfs affects mmap. If mmap() of files on
262 * nfs mounts breaks, then there should be an option to set
263 * the directory.
265 wapi_dir = getenv ("MONO_SHARED_DIR");
266 if (wapi_dir == NULL) {
267 filename = g_build_filename (g_get_home_dir (), ".wapi", name,
268 NULL);
269 } else {
270 filename = g_build_filename (wapi_dir, ".wapi", name, NULL);
272 g_free (name);
274 g_snprintf (file, _POSIX_PATH_MAX, "%s", filename);
275 g_free (filename);
277 return file;
280 static int
281 _wapi_shm_file_open (const gchar *filename, guint32 wanted_size)
283 int fd;
284 struct stat statbuf;
285 int ret, tries = 0;
286 gboolean created = FALSE;
287 mode_t oldmask;
288 gchar *dir;
290 /* No need to check if the dir already exists or check
291 * mkdir() errors, because on any error the open() call will
292 * report the problem.
294 dir = g_path_get_dirname (filename);
295 mkdir (dir, 0755);
296 g_free (dir);
298 try_again:
299 if (tries++ > 10) {
300 /* Just give up */
301 return (-1);
302 } else if (tries > 5) {
303 /* Break out of a loop */
304 unlink (filename);
307 /* Make sure future processes can open the shared data files */
308 oldmask = umask (066);
310 /* No O_CREAT yet, because we need to initialise the file if
311 * we have to create it.
313 fd = open (filename, O_RDWR, 0600);
314 umask (oldmask);
316 if (fd == -1 && errno == ENOENT) {
317 /* OK, its up to us to create it. O_EXCL to avoid a
318 * race condition where two processes can
319 * simultaneously try and create the file
321 oldmask = umask (066);
322 fd = open (filename, O_CREAT|O_EXCL|O_RDWR, 0600);
323 umask (oldmask);
325 if (fd == -1 && errno == EEXIST) {
326 /* It's possible that the file was created in
327 * between finding it didn't exist, and trying
328 * to create it. Just try opening it again
330 goto try_again;
331 } else if (fd == -1) {
332 g_critical ("%s: shared file [%s] open error: %s",
333 __func__, filename, g_strerror (errno));
334 return -1;
335 } else {
336 /* We created the file, so we need to expand
337 * the file.
339 * (wanted_size-1, because we're about to
340 * write the other byte to actually expand the
341 * file.)
343 if (lseek (fd, wanted_size-1, SEEK_SET) == -1) {
344 g_critical ("%s: shared file [%s] lseek error: %s", __func__, filename, g_strerror (errno));
345 close (fd);
346 unlink (filename);
347 return -1;
350 do {
351 ret = write (fd, "", 1);
352 } while (ret == -1 && errno == EINTR);
354 if (ret == -1) {
355 g_critical ("%s: shared file [%s] write error: %s", __func__, filename, g_strerror (errno));
356 close (fd);
357 unlink (filename);
358 return -1;
361 created = TRUE;
363 /* The contents of the file is set to all
364 * zero, because it is opened up with lseek,
365 * so we don't need to do any more
366 * initialisation here
369 } else if (fd == -1) {
370 g_critical ("%s: shared file [%s] open error: %s", __func__,
371 filename, g_strerror (errno));
372 return -1;
375 /* Use stat to find the file size (instead of hard coding it)
376 * because we can expand the file later if needed (for more
377 * handles or scratch space.)
379 if (fstat (fd, &statbuf) == -1) {
380 g_critical ("%s: fstat error: %s", __func__,
381 g_strerror (errno));
382 if (created == TRUE) {
383 unlink (filename);
385 close (fd);
386 return -1;
389 if (statbuf.st_size < wanted_size) {
390 close (fd);
391 if (created == TRUE) {
392 g_critical ("%s: shared file [%s] is not big enough! (found %ld, need %d bytes)", __func__, filename, (long)statbuf.st_size, wanted_size);
393 unlink (filename);
394 return -1;
395 } else {
396 /* We didn't create it, so just try opening it again */
397 _wapi_handle_spin (100);
398 goto try_again;
402 return fd;
405 gboolean
406 _wapi_shm_enabled (void)
408 static gboolean env_checked;
410 if (!env_checked) {
411 if (g_getenv ("MONO_ENABLE_SHM"))
412 _wapi_shm_disabled = FALSE;
413 env_checked = TRUE;
416 return !_wapi_shm_disabled;
420 * _wapi_shm_attach:
421 * @success: Was it a success
423 * Attach to the shared memory file or create it if it did not exist.
424 * Returns the memory area the file was mmapped to.
426 gpointer
427 _wapi_shm_attach (_wapi_shm_t type)
429 gpointer shm_seg;
430 int fd;
431 struct stat statbuf;
432 gchar *filename = _wapi_shm_file (type), *shm_name;
433 guint32 size;
435 switch(type) {
436 case WAPI_SHM_DATA:
437 size = sizeof(struct _WapiHandleSharedLayout);
438 break;
440 case WAPI_SHM_FILESHARE:
441 size = sizeof(struct _WapiFileShareLayout);
442 break;
443 default:
444 g_error ("Invalid type in _wapi_shm_attach ()");
445 return NULL;
448 if (!_wapi_shm_enabled ()) {
449 wapi_storage [type] = g_malloc0 (size);
450 return wapi_storage [type];
453 #ifdef USE_SHM
454 shm_name = _wapi_shm_shm_name (type);
455 fd = _wapi_shm_open (shm_name, size);
456 g_free (shm_name);
457 #else
458 fd = -1;
459 #endif
461 /* Fall back to files if POSIX shm fails (for example, because /dev/shm is not mounted */
462 if (fd == -1)
463 fd = _wapi_shm_file_open (filename, size);
464 if (fd == -1) {
465 g_critical ("%s: shared file [%s] open error", __func__,
466 filename);
467 return NULL;
470 if (fstat (fd, &statbuf)==-1) {
471 g_critical ("%s: fstat error: %s", __func__,
472 g_strerror (errno));
473 close (fd);
474 return NULL;
477 shm_seg = mmap (NULL, statbuf.st_size, PROT_READ|PROT_WRITE,
478 MAP_SHARED, fd, 0);
479 if (shm_seg == MAP_FAILED) {
480 shm_seg = mmap (NULL, statbuf.st_size, PROT_READ|PROT_WRITE,
481 MAP_PRIVATE, fd, 0);
482 if (shm_seg == MAP_FAILED) {
483 g_critical ("%s: mmap error: %s", __func__, g_strerror (errno));
484 close (fd);
485 return NULL;
489 close (fd);
490 return shm_seg;
493 void
494 _wapi_shm_detach (_wapi_shm_t type)
496 if (!_wapi_shm_enabled ())
497 g_free (wapi_storage [type]);
500 static void
501 shm_semaphores_init (void)
503 key_t key;
504 key_t oldkey;
505 int thr_ret;
506 struct _WapiHandleSharedLayout *tmp_shared;
507 gchar *ftmp;
508 gchar *filename;
511 * Yet more barmy API - this union is a well-defined parameter
512 * in a syscall, yet I still have to define it here as it
513 * doesn't appear in a header
515 union semun {
516 int val;
517 struct semid_ds *buf;
518 ushort *array;
519 } defs;
520 ushort def_vals[_WAPI_SHARED_SEM_COUNT];
521 int i;
522 int retries = 0;
524 for (i = 0; i < _WAPI_SHARED_SEM_COUNT; i++) {
525 def_vals[i] = 1;
529 * Process count must start at '0' - the 1 for all the others
530 * sets the semaphore to "unlocked"
532 def_vals[_WAPI_SHARED_SEM_PROCESS_COUNT] = 0;
534 defs.array = def_vals;
537 *Temporarily attach the shared data so we can read the
538 * semaphore key. We release this mapping and attach again
539 * after getting the semaphores to avoid a race condition
540 * where a terminating process can delete the shared files
541 * between a new process attaching the file and getting access
542 * to the semaphores (which increments the process count,
543 * preventing destruction of the shared data...)
545 tmp_shared = _wapi_shm_attach (WAPI_SHM_DATA);
546 g_assert (tmp_shared != NULL);
548 #ifdef USE_SHM
549 ftmp=_wapi_shm_shm_name (WAPI_SHM_DATA);
550 filename = g_build_filename ("/dev/shm", ftmp, NULL);
551 g_assert (filename!=NULL);
552 key = ftok (filename, 'M');
553 g_free (ftmp);
554 g_free (filename);
555 #else
556 key = ftok ( _wapi_shm_file (WAPI_SHM_DATA), 'M');
557 #endif
559 again:
560 retries++;
561 oldkey = tmp_shared->sem_key;
563 if (oldkey == 0) {
564 DEBUGLOG ("%s: Creating with new key (0x%x)", __func__, key);
567 * The while loop attempts to make some sense of the
568 * bonkers 'think of a random number' method of
569 * picking a key without collision with other
570 * applications
572 while ((_wapi_sem_id = semget (key, _WAPI_SHARED_SEM_COUNT,
573 IPC_CREAT | IPC_EXCL | 0600)) == -1) {
574 if (errno == ENOMEM) {
575 g_error ("%s: semget error: %s", __func__,
576 g_strerror (errno));
577 } else if (errno == ENOSPC) {
578 g_error ("%s: semget error: %s. Try deleting some semaphores with ipcs and ipcrm\nor increase the maximum number of semaphore in the system.", __func__, g_strerror (errno));
579 } else if (errno != EEXIST) {
580 if (retries > 3)
581 g_warning ("%s: semget error: %s key 0x%x - trying again", __func__,
582 g_strerror (errno), key);
585 key++;
586 DEBUGLOG ("%s: Got (%s), trying with new key (0x%x)", __func__, g_strerror (errno), key);
589 * Got a semaphore array, so initialise it and install
590 * the key into the shared memory
593 if (semctl (_wapi_sem_id, 0, SETALL, defs) == -1) {
594 if (retries > 3)
595 g_warning ("%s: semctl init error: %s - trying again", __func__, g_strerror (errno));
598 * Something went horribly wrong, so try
599 * getting a new set from scratch
601 semctl (_wapi_sem_id, 0, IPC_RMID);
602 goto again;
605 if (InterlockedCompareExchange (&tmp_shared->sem_key,
606 key, 0) != 0) {
608 * Someone else created one and installed the
609 * key while we were working, so delete the
610 * array we created and fall through to the
611 * 'key already known' case.
613 semctl (_wapi_sem_id, 0, IPC_RMID);
614 oldkey = tmp_shared->sem_key;
615 } else {
617 * We've installed this semaphore set's key into
618 * the shared memory
620 goto done;
624 DEBUGLOG ("%s: Trying with old key 0x%x", __func__, oldkey);
626 _wapi_sem_id = semget (oldkey, _WAPI_SHARED_SEM_COUNT, 0600);
627 if (_wapi_sem_id == -1) {
628 if (retries > 3)
629 g_warning ("%s: semget error opening old key 0x%x (%s) - trying again",
630 __func__, oldkey,g_strerror (errno));
633 * Someone must have deleted the semaphore set, so
634 * blow away the bad key and try again
636 InterlockedCompareExchange (&tmp_shared->sem_key, 0, oldkey);
638 goto again;
641 done:
642 /* Increment the usage count of this semaphore set */
643 thr_ret = _wapi_shm_sem_lock (_WAPI_SHARED_SEM_PROCESS_COUNT_LOCK);
644 g_assert (thr_ret == 0);
646 DEBUGLOG ("%s: Incrementing the process count (%d)", __func__, _wapi_getpid ());
649 * We only ever _unlock_ this semaphore, letting the kernel
650 * restore (ie decrement) this unlock when this process exits.
651 * We lock another semaphore around it so we can serialise
652 * access when we're testing the value of this semaphore when
653 * we exit cleanly, so we can delete the whole semaphore set.
655 _wapi_shm_sem_unlock (_WAPI_SHARED_SEM_PROCESS_COUNT);
657 DEBUGLOG ("%s: Process count is now %d (%d)", __func__, semctl (_wapi_sem_id, _WAPI_SHARED_SEM_PROCESS_COUNT, GETVAL), _wapi_getpid ());
659 _wapi_shm_sem_unlock (_WAPI_SHARED_SEM_PROCESS_COUNT_LOCK);
661 if (_wapi_shm_disabled)
662 g_free (tmp_shared);
663 else
664 munmap (tmp_shared, sizeof(struct _WapiHandleSharedLayout));
667 static void
668 shm_semaphores_remove (void)
670 int thr_ret;
671 int proc_count;
672 gchar *shm_name;
674 DEBUGLOG ("%s: Checking process count (%d)", __func__, _wapi_getpid ());
676 thr_ret = _wapi_shm_sem_lock (_WAPI_SHARED_SEM_PROCESS_COUNT_LOCK);
677 g_assert (thr_ret == 0);
679 proc_count = semctl (_wapi_sem_id, _WAPI_SHARED_SEM_PROCESS_COUNT,
680 GETVAL);
682 g_assert (proc_count > 0);
683 if (proc_count == 1) {
685 * Just us, so blow away the semaphores and the shared
686 * files
688 DEBUGLOG ("%s: Removing semaphores! (%d)", __func__, _wapi_getpid ());
690 semctl (_wapi_sem_id, 0, IPC_RMID);
691 #ifdef USE_SHM
692 shm_name = _wapi_shm_shm_name (WAPI_SHM_DATA);
693 shm_unlink (shm_name);
694 g_free (shm_name);
696 shm_name = _wapi_shm_shm_name (WAPI_SHM_FILESHARE);
697 shm_unlink (shm_name);
698 g_free (shm_name);
699 #endif
700 unlink (_wapi_shm_file (WAPI_SHM_DATA));
701 unlink (_wapi_shm_file (WAPI_SHM_FILESHARE));
702 } else {
704 * "else" clause, because there's no point unlocking
705 * the semaphore if we've just blown it away...
707 _wapi_shm_sem_unlock (_WAPI_SHARED_SEM_PROCESS_COUNT_LOCK);
711 static int
712 shm_sem_lock (int sem)
714 struct sembuf ops;
715 int ret;
717 DEBUGLOG ("%s: locking sem %d", __func__, sem);
719 ops.sem_num = sem;
720 ops.sem_op = -1;
721 ops.sem_flg = SEM_UNDO;
723 retry:
724 do {
725 ret = semop (_wapi_sem_id, &ops, 1);
726 } while (ret == -1 && errno == EINTR);
728 if (ret == -1) {
730 * EINVAL covers the case when the semaphore was
731 * deleted before we started the semop
733 if (errno == EIDRM || errno == EINVAL) {
735 * Someone blew away this semaphore set, so
736 * get a new one and try again
738 DEBUGLOG ("%s: Reinitialising the semaphores!", __func__);
740 _wapi_shm_semaphores_init ();
741 goto retry;
744 /* Turn this into a pthreads-style return value */
745 ret = errno;
748 DEBUGLOG ("%s: returning %d (%s)", __func__, ret, g_strerror (ret));
750 return ret;
753 static int
754 shm_sem_trylock (int sem)
756 struct sembuf ops;
757 int ret;
759 DEBUGLOG ("%s: trying to lock sem %d", __func__, sem);
761 ops.sem_num = sem;
762 ops.sem_op = -1;
763 ops.sem_flg = IPC_NOWAIT | SEM_UNDO;
765 retry:
766 do {
767 ret = semop (_wapi_sem_id, &ops, 1);
768 } while (ret == -1 && errno == EINTR);
770 if (ret == -1) {
772 * EINVAL covers the case when the semaphore was
773 * deleted before we started the semop
775 if (errno == EIDRM || errno == EINVAL) {
777 * Someone blew away this semaphore set, so
778 * get a new one and try again
780 DEBUGLOG ("%s: Reinitialising the semaphores!", __func__);
782 _wapi_shm_semaphores_init ();
783 goto retry;
786 /* Turn this into a pthreads-style return value */
787 ret = errno;
790 if (ret == EAGAIN) {
791 /* But pthreads uses this code instead */
792 ret = EBUSY;
795 DEBUGLOG ("%s: returning %d (%s)", __func__, ret, g_strerror (ret));
797 return ret;
800 static int
801 shm_sem_unlock (int sem)
803 struct sembuf ops;
804 int ret;
806 DEBUGLOG ("%s: unlocking sem %d", __func__, sem);
808 ops.sem_num = sem;
809 ops.sem_op = 1;
810 ops.sem_flg = SEM_UNDO;
812 retry:
813 do {
814 ret = semop (_wapi_sem_id, &ops, 1);
815 } while (ret == -1 && errno == EINTR);
817 if (ret == -1) {
818 /* EINVAL covers the case when the semaphore was
819 * deleted before we started the semop
821 if (errno == EIDRM || errno == EINVAL) {
822 /* Someone blew away this semaphore set, so
823 * get a new one and try again (we can't just
824 * assume that the semaphore is now unlocked)
826 DEBUGLOG ("%s: Reinitialising the semaphores!", __func__);
828 _wapi_shm_semaphores_init ();
829 goto retry;
832 /* Turn this into a pthreads-style return value */
833 ret = errno;
836 DEBUGLOG ("%s: returning %d (%s)", __func__, ret, g_strerror (ret));
838 return ret;
841 void
842 _wapi_shm_semaphores_init (void)
844 if (!_wapi_shm_enabled ())
845 noshm_semaphores_init ();
846 else
847 shm_semaphores_init ();
850 void
851 _wapi_shm_semaphores_remove (void)
853 if (!_wapi_shm_disabled)
854 shm_semaphores_remove ();
858 _wapi_shm_sem_lock (int sem)
860 if (_wapi_shm_disabled)
861 return noshm_sem_lock (sem);
862 else
863 return shm_sem_lock (sem);
867 _wapi_shm_sem_trylock (int sem)
869 if (_wapi_shm_disabled)
870 return noshm_sem_trylock (sem);
871 else
872 return shm_sem_trylock (sem);
876 _wapi_shm_sem_unlock (int sem)
878 if (_wapi_shm_disabled)
879 return noshm_sem_unlock (sem);
880 else
881 return shm_sem_unlock (sem);
883 #endif /* !DISABLE_SHARED_HANDLES */