Hello,

> diff --git a/gnumach/ipc/ipc_mqueue.c b/gnumach/ipc/ipc_mqueue.c
> index f770afb..834eb16 100644
> --- a/gnumach/ipc/ipc_mqueue.c
> +++ b/gnumach/ipc/ipc_mqueue.c
> @@ -28,11 +27,11 @@
>   * the rights to redistribute these changes.
>   */
>  /*
> - *   File:   ipc/ipc_mqueue.c
> - *   Author: Rich Draves
> - *   Date:   2026 
> + *  File:   ipc/ipc_mqueue.c
> + *  Author: Rich Draves / Alperen ERKAN 
> + *  Date:   2026 
> @@ -156,6 +159,8 @@ ipc_mqueue_changed(
>  
>  /*
>   *   Routine:        ipc_mqueue_send
> + *  Author :    Alperen ERKAN 
> + *                                            2026
>   *   Purpose:
>   *           Send a message to a port.  The message holds a reference
>   *           for the destination port in the msgh_remote_port field.

A couple lines is not copyrightable and does make you sole author of
the function.

> @@ -52,6 +51,10 @@
>  #include <ipc/ipc_space.h>
>  #include <ipc/ipc_marequest.h>
>  
> +/* 
> + * An absolute message queue upper limit to prevent OOM and memory 
> exhaustion.
> + */
> +#define IPC_MQUEUE_HARD_LIMIT 65536

If we start adding absolute constraints on sizes etc. we'd want to put
that into a header dedicated for that, so people know where to tune
them.

> @@ -180,8 +185,16 @@ ipc_mqueue_send(
>  {
>       ipc_port_t port;
>  
> +     /* Defensive C: Checking the incoming message object and destination 
> port */
> +     if (kmsg == IKM_NULL) {
> +     return MACH_SEND_INVALID_DATA;
> +     }

Again, hiding bugs.

>       port = (ipc_port_t) kmsg->ikm_header.msgh_remote_port;
> -     assert(IP_VALID(port));
> +
> +     if (!IP_VALID(port)) {
> +        return MACH_SEND_INVALID_DEST;
> +     }

If userland passed a bogus port it should have been tested way before
this.

> @@ -230,17 +243,17 @@ ipc_mqueue_send(
>               }
>  
>               /*
> -              *  Don't block if:
> -              *      1) We're under the queue limit.
> -              *      2) Caller used the MACH_SEND_ALWAYS internal option.
> -              *      3) Message is sent to a send-once right.
> -              */
> -
> -             if ((port->ip_msgcount < port->ip_qlimit) ||
> -                 (option & MACH_SEND_ALWAYS) ||
> -                 (MACH_MSGH_BITS_REMOTE(kmsg->ikm_header.msgh_bits) ==
> -                                             MACH_MSG_TYPE_PORT_SEND_ONCE))
> -                     break;
> +         *  Don't block if:
> +         *  1) We're under the queue limit.
> +         *  2) Caller used MACH_SEND_ALWAYS but we are under the hard safety 
> limit.
> +         *  3) Message is sent to a send-once right.
> +         */

Avoid mangling the existing content.

> +
> +        if ((port->ip_msgcount < port->ip_qlimit) ||
> +            ((option & MACH_SEND_ALWAYS) && (port->ip_msgcount < 
> IPC_MQUEUE_HARD_LIMIT)) ||

? No, you are making ipc_mqueue_send ignore the port->ip_qlimit.

> +            (MACH_MSGH_BITS_REMOTE(kmsg->ikm_header.msgh_bits) ==
> +                        MACH_MSG_TYPE_PORT_SEND_ONCE))
> +            break;
>  
>               /* must block waiting for queue to clear */
>  
> @@ -263,45 +276,49 @@ ipc_mqueue_send(
>               counter(c_ipc_mqueue_send_block++);
>               thread_block(thread_no_continuation);
>               ip_lock(port);
> -
> +  
>               /* why did we wake up? */
>  
> -             if (self->ith_state == MACH_MSG_SUCCESS)
> -                     continue;
> -             assert(self->ith_state == MACH_SEND_IN_PROGRESS);
> +        if (self->ith_state == MACH_MSG_SUCCESS) {
> +            self->ith_state = MACH_MSG_SUCCESS; // veya temiz durum 
> sıfırlaması

Always English, please. And this does not do anything.

> +            continue;
> +        }
> +        assert(self->ith_state == MACH_SEND_IN_PROGRESS);

Again avoid mangling the indentation.

>  
> -             /* take ourselves off blocked queue */
> +        /* take ourselves off blocked queue under port lock */
> +        ipc_thread_rmqueue(&port->ip_blocked, self);
> +        
> +        /* [DEFENSIVE]: Clear state to prevent stale status reuse */
> +        self->ith_state = MACH_MSG_SUCCESS;
>  
> -             ipc_thread_rmqueue(&port->ip_blocked, self);
> +        /*
> +         *  Thread wakeup-reason field tells us why
> +         *  the wait was interrupted.
> +         */
>  
> -             /*
> -              *      Thread wakeup-reason field tells us why
> -              *      the wait was interrupted.
> -              */
> +        switch (self->ith_wait_result) {
> +            case THREAD_INTERRUPTED:
> +            /* send was interrupted - give up */

This is completely mangled. No idea if there is anything to read here.

Samuel

  • [no subject] Alperen Erkan
    • Re: Bradley Morgan
    • Re: Samuel Thibault
      • Fwd: Alperen Erkan
        • Re: Alperen Erkan
          • Re: Bradley Morgan
          • Re: Samuel Thibault
            • Re: Alperen Erkan
              • Re: Samuel Thibault
        • Re: Fwd: Samuel Thibault
    • Re: Bradley Morgan

Reply via email to